性能计数器正在工作,但其数据未记录在 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,而不是模拟器
谢谢