With Azure, we have a worker role, which assigned two instances. Inside of them, we have a Performance Counter to record the count of some operation:
static Service()
{
Counter = new PerformanceCounter(CustomCounterCategory, CustomCounterName, "instance", false);
}
public static void DoSomething()
{
while (true)
{
Trace.TraceInformation("[{0}]Raw value is {1}", RoleEnvironment.CurrentRoleInstance.Id, Counter.RawValue);
Counter.Increment();
Thread.Sleep(TimeSpan.FromSeconds(5));
}
}
Above demo code just read current raw data of performance counter and log it, then increment by one.
From the logging, I found the raw data for different instances is exactly same: 0, 1, 2, 3 ...
. So any way to share the raw data for two instances, making the performance counter exists across different instances of role?
UPDATE
Here is how I create the performance counter category:
if (!PerformanceCounterCategory.Exists(Service.CustomCounterCategory))
{
var counterCollection = new CounterCreationDataCollection();
var operationTotal1 = new CounterCreationData
{
CounterName = Service.CustomCounterName,
CounterHelp = "help",
CounterType = PerformanceCounterType.NumberOfItems32
};
counterCollection.Add(operationTotal1);
PerformanceCounterCategory.Create(
Service.CustomCounterCategory,
"CategoryDescription",
PerformanceCounterCategoryType.MultiInstance,
counterCollection);
}