2

我在 Windows Azure 中运行自定义性能计数器时遇到了严重问题。在 *.cscfg 文件中的配置更改时,我正在通过在 PostSharp 的帮助下实现的方面动态地创建性能计数器。性能计数器在模拟器和 Azure 环境(通过远程桌面检查)中正确创建,因为我可以在计算机管理控制台中的Performance Tools -> Monitoring Tools -> Performance Monitor下看到性能计数器实例。我在diagnostics.wadcfg中添加了性能计数器。

<?xml version="1.0" encoding="utf-8"?>
<DiagnosticMonitorConfiguration configurationChangePollInterval="PT1M" overallQuotaInMB="4096" xmlns="http://schemas.microsoft.com/ServiceHosting/2010/10/DiagnosticsConfiguration">
  <DiagnosticInfrastructureLogs />
  <Directories>
    <IISLogs container="wad-iis-logfiles" />
    <CrashDumps container="wad-crash-dumps" />
  </Directories>
  <Logs bufferQuotaInMB="1024" scheduledTransferPeriod="PT1M" scheduledTransferLogLevelFilter="Information" />
  <PerformanceCounters bufferQuotaInMB="250" scheduledTransferPeriod="PT1M">
    <PerformanceCounterConfiguration counterSpecifier="\Processor(_Total)\% Processor Time" sampleRate="PT1S" />
    <PerformanceCounterConfiguration counterSpecifier="\Memory\Available MBytes" sampleRate="PT1S" />
    <PerformanceCounterConfiguration counterSpecifier="\_Customer Category\average execution time for member call" sampleRate="PT1S" />
  </PerformanceCounters>
  <WindowsEventLog bufferQuotaInMB="1024" scheduledTransferPeriod="PT1M" scheduledTransferLogLevelFilter="Error">
    <DataSource name="Application!*" />
  </WindowsEventLog>
</DiagnosticMonitorConfiguration>

问题是我从未在WADPerformanceCountersTable中看到性能计数器值。如果我启动模拟器,我会看到这个错误:

[MonAgentHost] Error: MA EVENT: 2013-09-05T15:30:49.373Z
[MonAgentHost] Error:     2
[MonAgentHost] Error:     8360
[MonAgentHost] Error:     12556
[MonAgentHost] Error:     SysCounterListener.dll
[MonAgentHost] Error:     0
[MonAgentHost] Error:     5fd713ae-0085-4ba3-87f6-e21ad86
[MonAgentHost] Error:     liscounter.cpp
[MonAgentHost] Error:     SystemCounter::AddCounter
[MonAgentHost] Error:     660
[MonAgentHost] Error:     ffffffffc0000bb8
[MonAgentHost] Error:     0
[MonAgentHost] Error:     
[MonAgentHost] Error:     PdhAddCounter(\_Customer Category\average execution time for member call) failed

创建类别的代码见下文(_categoryName =“_Custom Category”和_counterName =“成员调用的平均执行时间”)

    private void CreateCategory()
    {
        if (!PerformanceCounterCategory.Exists(_categoryName))
        {
            Trace.TraceInformation("Creating new category '{0}'", _categoryName);

            _counters = new CounterCreationDataCollection
            {
                new CounterCreationData(_counterName, _performanceCounterHelperText, PerformanceCounterType.AverageTimer32),
                new CounterCreationData(_averageBasePerformanceCounterName, string.Empty, PerformanceCounterType.AverageBase)
            };

            PerformanceCounterCategory.Create(_categoryName, string.Empty, PerformanceCounterCategoryType.MultiInstance, _counters);
        }
    }

    private void CreateOrGetPerformanceCounters()
    {
        string averageBasePerformanceCounterName = string.Format("{0} {1}", _counterName, "base");

        Trace.TraceInformation("Get new instance '{0}' of counter '{1}' in the category '{2}'", _instanceName, _counterName, _categoryName);
        _performanceCounterAverage = new PerformanceCounter(
            _categoryName, _counterName, _instanceName, false);

        _performanceCounterAverageBase = new PerformanceCounter(
            _categoryName, averageBasePerformanceCounterName, _instanceName, false);
    }

下一个问题是,如何获取性能计数器的具体实例?在管理控制台中,我可以选择应该显示哪个实例,如何在 Azure 中执行此操作?

4

1 回答 1

1

有两个错误

  1. diagnostics.wadcfg文件中的错字:类别名称是_Custom Category,我写的是CustomER Category
  2. 性能计数器的格式是:\[Category Name]([Instance Name]|*)\[Performance Counter Name],所以在我的例子中是\_Custom Category(*)\average execution time for member call。在这种情况下,asterix 不见了!
于 2013-10-03T14:25:52.890 回答