0

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

在 webrole.cs 我有

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

在我的一个页面加载方法中,我添加了

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

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

我可以在 WebLogsTable 中看到“访问的用户”日志,button1Counter.Increment 也有效(我可以看到它是使用日志计算的原始值)。

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

为什么我创建的自定义性能计数器没有被记录?

这是 WAD 性能计数器表: 在此处输入图像描述

以下是日志: 在此处输入图像描述

这是 Windows 日志(每个日志重复 10 次,但我删除了“便携式设备枚举器服务服务进入停止状态。”和“应用程序体验服务进入停止状态”的重复项以及关于时间更改的内容。“所以你可以看到它们。为什么要创建 10 个相同的日志?)

在此处输入图像描述

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

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

谢谢

4

1 回答 1

0

我设法使它工作。我不知道是什么东西(我什至删除了部署并再次发布 - 也许修复了它),但这里是有效的文件

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

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

于 2012-12-29T18:03:01.553 回答