0
votes

The performance counters are working, but their data is not logged inside WADPerformanceCountersTable.

In the webrole.cs I have

 public override bool OnStart()
    {
        var config = DiagnosticMonitor.GetDefaultInitialConfiguration();
        config.PerformanceCounters.DataSources.Add(
                 new PerformanceCounterConfiguration
                 {
                     CounterSpecifier = @"\Processor(_Total)\% Processor Time",
                     SampleRate = TimeSpan.FromSeconds(5)
                 });
        if (!PerformanceCounterCategory.Exists("MyCustomCounterCategory"))
        {
            CounterCreationDataCollection counterCollection = new CounterCreationDataCollection();


            // add a counter tracking user button1 clicks
            CounterCreationData operationTotal1 = new CounterCreationData();
            operationTotal1.CounterName = "MyButton1Counter";
            operationTotal1.CounterHelp = "My Custom Counter for Button1";
            operationTotal1.CounterType = PerformanceCounterType.NumberOfItems32;
            counterCollection.Add(operationTotal1);


            // add a counter tracking user button2 clicks
            CounterCreationData operationTotal2 = new CounterCreationData();
            operationTotal2.CounterName = "MyButton2Counter";
            operationTotal2.CounterHelp = "My Custom Counter for Button2";
            operationTotal2.CounterType = PerformanceCounterType.NumberOfItems32;
            counterCollection.Add(operationTotal2);


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


            Trace.WriteLine("Custom counter category created.");
        }
        else
        {
            Trace.WriteLine("Custom counter category already exists.");
        }

        config.PerformanceCounters.ScheduledTransferPeriod =
          TimeSpan.FromMinutes(2D);
        config.PerformanceCounters.BufferQuotaInMB = 512;
        TimeSpan perfSampleRate = TimeSpan.FromSeconds(30D);


        // Add configuration settings for custom performance counters.
        config.PerformanceCounters.DataSources.Add(
          new PerformanceCounterConfiguration()
          {
              CounterSpecifier = @"\MyCustomCounterCategory\MyButton1Counter",
              SampleRate = perfSampleRate
          });


        config.PerformanceCounters.DataSources.Add(
          new PerformanceCounterConfiguration()
          {
              CounterSpecifier = @"\MyCustomCounterCategory\MyButton2Counter",
              SampleRate = perfSampleRate
          });


        // Apply the updated configuration to the diagnostic monitor.    
        DiagnosticMonitor.Start("Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString", config);

        return base.OnStart();
    }

In one of my pages load method I added

        var button1Counter = new PerformanceCounter(
  "MyCustomCounterCategory",
  "MyButton1Counter",
  string.Empty,
  false);

        System.Diagnostics.Trace.WriteLine("Users accessed");
        button1Counter.Increment();

I can see the "Users accessed" log in WebLogsTable, also button1Counter.Increment works (I can see it's raw value counting up using logs).

The problem is tat the only performance counter I can see in PerformanceCounters Table is \Processor(_Total)\% Processor Time. If I turn on Verbose monitoring mode in Azure Management Panel, I see some more Performance counters being logged (but only once eery five minutes, but not the custom performance counters )

Why aren't the custom performance counters I created being logged?

Here is the WAD Performanc Counters Table: enter image description here

Here are the logs: enter image description here

Here are the Windows Logs (Each log gets repeated 10 times but I removed the duplicates for "The Portable Device Enumerator Service service entered the stopped state." and "The Application Experience service entered the stopped state" and the one regarding time change. " so you can see them. Why create 10 identical logs?)

enter image description here

SO how can I make AZURE put the custom performance routers in the WADPerformanceCoutersTable?

I have been struggling with this for two days. Please help! I use Azure, and not the simulator

Thank you

1

1 Answers

0
votes

I managed to make it work. I don't know what was the thing (I even deleted the deployment and published again - maybe that fixed it), but here are the files that work

Role.cs file

String wadConnectionString =
                       "Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString";

            CloudStorageAccount cloudStorageAccount =
                                    CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue
                                    (wadConnectionString));

            RoleInstanceDiagnosticManager roleInstanceDiagnosticManager =
                                   cloudStorageAccount.CreateRoleInstanceDiagnosticManager(
                                   RoleEnvironment.DeploymentId,
                                   RoleEnvironment.CurrentRoleInstance.Role.Name,
                                   RoleEnvironment.CurrentRoleInstance.Id);



            LocalResource localResource = RoleEnvironment.GetLocalResource("MyCustomLogs");
            DirectoryConfiguration dirConfig = new DirectoryConfiguration();
            dirConfig.Container = "wad-mycustomlogs-container";
            dirConfig.DirectoryQuotaInMB = localResource.MaximumSizeInMegabytes;
            dirConfig.Path = localResource.RootPath;



            if (!PerformanceCounterCategory.Exists("MyCustomCounterCategory"))
            {
                CounterCreationDataCollection counterCollection = new CounterCreationDataCollection();


                // add a counter tracking user button1 clicks
                CounterCreationData operationTotal1 = new CounterCreationData();
                operationTotal1.CounterName = "MyButton1Counter";
                operationTotal1.CounterHelp = "My Custom Counter for Button1";
                operationTotal1.CounterType = PerformanceCounterType.NumberOfItems32;
                counterCollection.Add(operationTotal1);


                // add a counter tracking user button2 clicks
                CounterCreationData operationTotal2 = new CounterCreationData();
                operationTotal2.CounterName = "MyButton2Counter";
                operationTotal2.CounterHelp = "My Custom Counter for Button2";
                operationTotal2.CounterType = PerformanceCounterType.NumberOfItems32;
                counterCollection.Add(operationTotal2);


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


                Trace.WriteLine("Custom counter category created.");
            }
            else
            {
                Trace.WriteLine("Custom counter category already exists.");
            }
            Trace.WriteLine("Creating custom counters.");
            var config = DiagnosticMonitor.GetDefaultInitialConfiguration();
            config.WindowsEventLog.DataSources.Add("Application!*");
            config.WindowsEventLog.DataSources.Add("System!*");

            config.Directories.ScheduledTransferPeriod = TimeSpan.FromMinutes(2d);
            config.Directories.DataSources.Add(dirConfig);

            config.Logs.ScheduledTransferPeriod = TimeSpan.FromMinutes(2d);
            config.PerformanceCounters.ScheduledTransferPeriod =
              TimeSpan.FromMinutes(2D);
            config.PerformanceCounters.BufferQuotaInMB = 512;
            TimeSpan perfSampleRate = TimeSpan.FromSeconds(30D);


            // Add configuration settings for custom performance counters.
            config.PerformanceCounters.DataSources.Add(
              new PerformanceCounterConfiguration()
              {
                  CounterSpecifier = @"\MyCustomCounterCategory\MyButton1Counter",
                  SampleRate = perfSampleRate
              });

            config.PerformanceCounters.DataSources.Add(
                   new PerformanceCounterConfiguration
                   {
                       CounterSpecifier = @"\Processor(_Total)\% Processor Time",
                       SampleRate = perfSampleRate
                   });
            config.PerformanceCounters.DataSources.Add(
              new PerformanceCounterConfiguration()
              {
                  CounterSpecifier = @"\MyCustomCounterCategory\MyButton2Counter",
                  SampleRate = perfSampleRate
              });


            // Apply the updated configuration to the diagnostic monitor.    
            DiagnosticMonitor.Start("Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString", config);
            Trace.WriteLine("Started perf counters");

web config

   <trace enabled="true" requestLimit="40" localOnly="false" />


 <system.diagnostics>
    <trace>
      <listeners>
        <add type="Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, 
            Microsoft.WindowsAzure.Diagnostics, 
            Version=1.8.0.0, 
            Culture=neutral, 
            PublicKeyToken=31bf3856ad364e35"
           name="AzureDiagnostics">
          <filter type="" />
        </add>
      </listeners>
    </trace>
  </system.diagnostics>

In service definition.cs

  <Imports>
      <Import moduleName="Diagnostics" />
    </Imports>
    <LocalResources>
      <LocalStorage name="MyCustomLogs" sizeInMB="10" cleanOnRoleRecycle="false" />
    </LocalResources>

In ServiceConfiguration.Cloud

  <Setting name="Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString" 
           value="DefaultEndpointsProtocol=https;AccountName=acc name;
           AccountKey=r- --- -- - your key=" />
</ConfigurationSettings>
<Certificates>
  <Certificate name="mycretificate" thumbprint="XXXXX" thumbprintAlgorithm="sha1" />
</Certificates>