性能计数器正在运行,但它们的数据未记录在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 Performanc计数器表:
以下是日志:
以下是Windows日志(每个日志重复10次,但我删除了“便携式设备枚举器服务服务进入停止状态”和“应用程序体验服务进入停止状态”和关于时间的重复项更改。 “所以你可以看到它们。为什么要创建10个相同的日志?”
那我怎么能让AZURE把自定义性能路由器放在WADPerformanceCoutersTable中呢?
我一直在为此奋斗两天。请帮忙!我使用Azure,而不是模拟器
谢谢
答案 0 :(得分: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");
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>
在service definition.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>