1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using System.Text;
|
---|
5 | using System.Diagnostics;
|
---|
6 |
|
---|
7 | namespace HeuristicLab.Services.Optimization.Scaler {
|
---|
8 | public static class PerformanceCounterHelper {
|
---|
9 | public const string HiveCounterCategory = "Hive";
|
---|
10 | public const string HiveCounterGlobalUsageName = "% Global Usage";
|
---|
11 | public const string HiveCounterGlobalUsage = @"\" + HiveCounterCategory + @"\" + HiveCounterGlobalUsageName;
|
---|
12 |
|
---|
13 | public class PerformanceCounterEntry {
|
---|
14 | public string Name { get; set; }
|
---|
15 | public string HelpText { get; set; }
|
---|
16 | public PerformanceCounterType Type { get; set; }
|
---|
17 | }
|
---|
18 |
|
---|
19 | private static void InitializePerformanceCounters(string category, string categoryHelpText, params PerformanceCounterEntry[] entries) {
|
---|
20 |
|
---|
21 | if (PerformanceCounterCategory.Exists(category))
|
---|
22 | PerformanceCounterCategory.Delete(category);
|
---|
23 |
|
---|
24 | var counterCollection = new CounterCreationDataCollection();
|
---|
25 | foreach (var entry in entries) {
|
---|
26 | var creationData = new CounterCreationData() {
|
---|
27 | CounterName = entry.Name,
|
---|
28 | CounterHelp = entry.HelpText,
|
---|
29 | CounterType = entry.Type
|
---|
30 | };
|
---|
31 | counterCollection.Add(creationData);
|
---|
32 | }
|
---|
33 | PerformanceCounterCategory.Create(
|
---|
34 | category,
|
---|
35 | categoryHelpText,
|
---|
36 | PerformanceCounterCategoryType.SingleInstance,
|
---|
37 | counterCollection);
|
---|
38 |
|
---|
39 | Trace.WriteLine(string.Format("Category {0} created.", category));
|
---|
40 | }
|
---|
41 |
|
---|
42 | public static void InitializePerformanceCounters() {
|
---|
43 | InitializePerformanceCounters(HiveCounterCategory, "Hive performance counters",
|
---|
44 | new PerformanceCounterEntry() {
|
---|
45 | Name = HiveCounterGlobalUsageName,
|
---|
46 | Type = PerformanceCounterType.NumberOfItems32,
|
---|
47 | HelpText = "The current usage in % over all hive slaves in the system"
|
---|
48 | }
|
---|
49 | );
|
---|
50 | }
|
---|
51 |
|
---|
52 | private static PerformanceCounter hiveGlovalUsage;
|
---|
53 | public static PerformanceCounter HiveGlobalUsage {
|
---|
54 | get {
|
---|
55 | if (hiveGlovalUsage == null) {
|
---|
56 | hiveGlovalUsage = new PerformanceCounter(
|
---|
57 | PerformanceCounterHelper.HiveCounterCategory,
|
---|
58 | PerformanceCounterHelper.HiveCounterGlobalUsageName,
|
---|
59 | string.Empty,
|
---|
60 | false);
|
---|
61 | }
|
---|
62 | return hiveGlovalUsage;
|
---|
63 | }
|
---|
64 | }
|
---|
65 | }
|
---|
66 | }
|
---|