C# 如何将磁盘可用空间性能计数器添加到Azure Application Insights?

C# 如何将磁盘可用空间性能计数器添加到Azure Application Insights?,c#,azure,azure-application-insights,performancecounter,C#,Azure,Azure Application Insights,Performancecounter,我知道Azure Application Insights可以在ApplicationInsights.config中使用以下语法收集其他性能计数器: <Counters> <Add PerformanceCounter="\LogicalDisk(_total)\% Free Space" ReportAs="the space perc"/> <Add PerformanceCounter="\LogicalDisk(_tota

我知道Azure Application Insights可以在ApplicationInsights.config中使用以下语法收集其他性能计数器:

 <Counters>
        <Add PerformanceCounter="\LogicalDisk(_total)\% Free Space" ReportAs="the space perc"/>
        <Add PerformanceCounter="\LogicalDisk(_total)\Free Megabytes" ReportAs="the space left"/>
 </Counters>

...
PerformanceCounter必须是\CategoryName(InstanceName)\CounterName或\CategoryName\CounterName
-->
如何将“可用磁盘空间”和“可用磁盘空间%”性能计数器添加到此文件

另外,请注意,我希望ApplicationInsights已经收集到了这一点,令人惊讶的是,我们不得不花这么长的时间来添加它


非常感谢您的帮助

请尝试ApplicationInsights.config中的以下设置:

 <Counters>
        <Add PerformanceCounter="\LogicalDisk(_total)\% Free Space" ReportAs="the space perc"/>
        <Add PerformanceCounter="\LogicalDisk(_total)\Free Megabytes" ReportAs="the space left"/>
 </Counters>

除了Ivan Yang的回答,还可以用代码完成:

var perfCollectorModule = new PerformanceCollectorModule();
perfCollectorModule.Counters.Add(new PerformanceCounterCollectionRequest(@"\Sales(photo)\# Items Sold", "Photo sales"));
perfCollectorModule.Initialize(TelemetryConfiguration.Active);