自定义性能计数器未记录 [英] custom performance counters are not logged

查看:88
本文介绍了自定义性能计数器未记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

性能计数器正在工作,但其数据未记录在WADPerformanceCountersTable中.

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

在webrole.cs中,

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();

我可以在WebLogsTable中看到已访问用户"日志,也可以看到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).

问题是我只能在PerformanceCounters表中看到的唯一性能计数器 是\ Processor(_Total)\%Processor Time.如果我在Azure管理面板中打开了详细监视模式,则会看到更多的性能计数器正在记录(但是每5分钟仅记录一次,而自定义性能计数器则没有)

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?

以下是WAD表演计数器表:

Here is the WAD Performanc Counters Table:

以下是日志:

这里是Windows日志(每个日志重复10次,但我删除了便携式设备枚举器服务进入停止状态"和应用程序体验服务进入停止状态"的重复项,以及有关时间的一个重复项改变. ,这样您就可以看到它们.为什么要创建10个相同的日志?)

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?)

那么如何使AZURE将自定义性能路由器放在WADPerformanceCoutersTable中?

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

我已经为此苦苦挣扎了两天.请帮忙!我使用Azure,而不是模拟器

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

谢谢

推荐答案

我设法使其正常运行.我不知道这是怎么回事(我什至删除了部署并再次发布-也许已经修复了它),但是这里的文件可以正常工作

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文件

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");

网络配置

   <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>

在服务定义中.cs

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

在ServiceConfiguration.Cloud中

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>

这篇关于自定义性能计数器未记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆