简体   繁体   English

.NET应用程序见解| 自定义指标未显示在portal.azure.com中的指标下

[英]Application insight .NET | Custom metrics don't show up in portal.azure.com under metrics

I have application insight running with a "pay as you go" model. 我具有“按需付费”模型运行的应用程序见解。 Standard performance metrics show up in the portal. 标准性能指标显示在门户中。 Custom metrics don't show up in the metrics section. 自定义指标不会显示在“指标”部分中。

My Environment. 我的环境。 A custom .NET core console app running plain TCP sockets. 运行纯TCP套接字的自定义.NET核心控制台应用程序。 (no ASP.NET CORE) using (无ASP.NET CORE)使用

<PackageReference Include="Microsoft.ApplicationInsights" Version="2.7.2" />

The Telemetry class is constructed with the default constructor ( and no XML config file) 遥测类是使用默认构造函数构造的(并且没有XML配置文件)

The custom metrics are created like 自定义指标的创建方式如下

Telemetry.Client.GetMetric("number of clients").TrackValue(600.0);

Question: What do i miss or doing wrong, that the custom metrics don't show up? 问题:自定义指标未显示,我想念或做错了什么? Is the "metrics" section in the azure portal the wrong place to look for custom metrics? 天蓝色门户中的“度量标准”部分在寻找自定义度量标准的地方不正确吗?

Update 更新

The sample code also doesn't upload any custom metrics to azure. 该示例代码也没有将任何自定义指标上传到Azure。

        TelemetryClient client = new TelemetryClient();
        client.InstrumentationKey = "a valid key";
        client.GetMetric("test me").TrackValue(200);
        client.Flush();
        Thread.Sleep(5000);

This issue due to the instrumentation key is not configured correctly. 由于检测键配置不正确,导致此问题。

When use GetMetric().TrackValue() , we should use this way to configure instrumentation key: 当使用GetMetric().TrackValue() ,我们应该使用这种方式来配置检测键:

TelemetryConfiguration.Active.InstrumentationKey = "your key" ; TelemetryConfiguration.Active.InstrumentationKey = "your key" ;

My code as below: 我的代码如下:

  TelemetryClient client = new TelemetryClient();
  TelemetryConfiguration.Active.InstrumentationKey = "your key";  
  client.GetMetric("test33").TrackValue(100);  

  System.Threading.Thread.Sleep(1000*5);
  client.Flush();

  Console.WriteLine("Hello World!");
  Console.ReadLine();

Then in the visual studio output window, you can see the ikey is showing there: 然后在visual studio输出窗口中,您可以看到ikey显示在其中: 在此处输入图片说明

Then go to azure portal -> application insights -> metrics, you can see your metric: 然后转到azure门户->应用程序见解->指标,您可以看到您的指标: 在此处输入图片说明

For comparison, when you use the following code: 为了进行比较,当您使用以下代码时:

client.InstrumentationKey = "a valid key";
client.GetMetric("test me").TrackValue(200);

after execution, in the visual studio, you can see there is no ikey in the output window, so no metric would be sent to azure portal: 执行后,在Visual Studio中,您可以看到输出窗口中没有ikey,因此不会将度量标准发送到azure门户: 在此处输入图片说明

Thanks to Ivan Yang i found a github issue which is discussing this problem in detail. 多亏了Ivan Yang,我找到了一个github问题,正在详细讨论这个问题。

It looks like there are multiple cases to create invalid configurations. 似乎有多种情况创建无效的配置。

For example this is currently also a INVALID configuration 例如,当前这也是无效的配置

TelemetryConfiguration tcConfig = new TelemetryConfiguration();

TelemetryClient tc = new TelemetryClient(tcConfig)
{
    InstrumentationKey = ikey
};

More details on https://github.com/Microsoft/ApplicationInsights-dotnet/issues/826 and on https://www.reddit.com/r/Unity3D/comments/8igabt/using_microsoft_azure_app_insights_and_unity/ https://github.com/Microsoft/ApplicationInsights-dotnet/issues/826https://www.reddit.com/r/Unity3D/comments/8igabt/using_microsoft_azure_app_insights_and_unity/上的更多详细信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM