0

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);
}
Jerry Bian
  • 3,998
  • 6
  • 29
  • 54

2 Answers2

0

See this link https://msdn.microsoft.com/en-us/library/azure/dn535595.aspx

PerformanceCounterCategory.Create(
     "MyCustomCounterCategory",
     "My Custom Counter Category",
     PerformanceCounterCategoryType.SingleInstance, counterCollection);

   Trace.WriteLine("Custom counter category created.");

try changing the singleInstance to other options. Sure there will be option for multiinstance also

Mahesh Malpani
  • 1,782
  • 16
  • 27
  • @JerryBian according to http://blogs.msdn.com/b/bclteam/archive/2004/10/29/249799.aspx you should use `PerformanceCounterCategoryType.SingleInstance` to achieve one system-wide counter. –  Apr 08 '15 at 08:52
  • @AndreasNiedermair the deployment would fail once I change `MultiInstance` to `SingleInstance` ... something like `PdhExpandWildCardPath(\CustomCounterCategory3(instance)\CustomCounterName3) failed` – Jerry Bian Apr 08 '15 at 09:11
  • @JerryBian did you investigate if Azure is capable of multiInstance counters? –  Apr 08 '15 at 10:05
  • @AndreasNiedermair I did a google search, but not found meaningful resources. And that's why I post a thread in SO. :-) – Jerry Bian Apr 08 '15 at 10:06
  • @JerryBrian there's a [walkthrough](http://blog.isaleem.com/2013/12/azure-custom-performance-counters.html) available - does that help? –  Apr 08 '15 at 10:11
0

Shortly answer: NO.

Just in case you're looking for the answer of same question.

Jerry Bian
  • 3,998
  • 6
  • 29
  • 54