c# - How to add a new counter to an existing performance counter category without deleting the old counters? -
I have a custom counter category, which I need to add a new counter, without deleting or resetting any existing counter for. how can I do this?
I tried using CounterExists (), but even after I made the counter, how can I associate it to a CounterCreationDataCollection item and associate my current counter class?
I found, especially, because there does not seem to be much information on this subject The best way to do this is to protect the existing raw values and then delete the category and then re-apply it after it has been rebuilt.
/// & lt; Summary & gt; The removal of the /// category requires the need to preserve the existing counter values /// & lt; / Summary & gt; Fixed dictionary & lt; String, long & gt; GetPreservedValues (string category, XmlNodeList nodes) {dictionary & lt; String, long & gt; Protected Price = New Dictionary & lt; String, long & gt; (); Foreach (XmlNode countersource in nodes) {string counterName = counterNode.Attributes ["name"]. Values; If (PerformanceCounterCategory.CounterExists (counterName, category)) {PerformanceCounter performanceCounter = New PerformanceCounter (Category, counterName, False); Protected Price Add (CounterName, Performance Counter. Rowwall); Protecting {0} with a cratele of console (lightning "{1}", counter name, display counter Rowwall);} Else {Console.WriteLine ("Unable to preserve {0} because it does not exist" CounterName);}} Returns protected value;} /// & lt; summary & gt; /// Restore preserved values after the re-created category /// & lt; / summary & gt; static void SetPreservedValues (String category, dictionary & lt; string; long & gt; preservedValues) {foreach (KeyValuePair & lt; string, From time to time> SavedValues stored in Values {PerformanceCounter performanceCounter = New PerformanceCounter (category, preservedValue.Key, false); DisplayConverter.Raval Price = Protected Price; Console.WriteLine ("Restoring {0} With a RawValue of {1} ", preservedValue.Key, performanceCounter.RawValue);}}
Comments
Post a Comment