【问题标题】:Application insight .NET | Custom metrics don't show up in portal.azure.com under metrics应用洞察 .NET |自定义指标未显示在 portal.azure.com 中的指标下
【发布时间】:2018-09-28 09:47:31
【问题描述】:

我有应用洞察力以“即用即付”模式运行。 标准性能指标显示在门户中。 自定义指标不会显示在指标部分。

我的环境。 运行普通 TCP 套接字的自定义 .NET 核心控制台应用程序。 (没有 ASP.NET 核心) 使用

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

Telemetry 类是使用默认构造函数构造的(并且没有 XML 配置文件)

自定义指标的创建方式类似于

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

问题: 我错过了什么或做错了什么,自定义指标没有显示? Azure 门户中的“指标”部分是否是查找自定义指标的错误位置?

更新

示例代码也不会将任何自定义指标上传到 azure。

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

【问题讨论】:

  • 什么是keyval
  • key = string, val = double, string 里面有空格符
  • 好的,我知道了。我的意思是那个变量的值是什么
  • 嗯,您通常不将TelemetryClient.TrackMetric(string, double) 用于自定义指标吗?或者这是我不喜欢的其他方式? :D
  • 文档说 TelemetryClient.TrackMetric(string, double) 已损坏。 docs.microsoft.com/en-us/azure/application-insights/…

标签: c# .net azure azure-application-insights


【解决方案1】:

此问题是由于未正确配置检测密钥所致。

当使用GetMetric().TrackValue()时,我们应该使用这种方式来配置instrumentation key:

TelemetryConfiguration.Active.InstrumentationKey = "your key";

我的代码如下:

  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();

然后在 Visual Studio 输出窗口中,您可以看到 ikey 显示在那里:

然后去azure portal -> application insights -> metrics,就可以看到你的metric了:

为了比较,当你使用以下代码时:

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

执行后,在 Visual Studio 中,您可以看到输出窗口中没有 ikey,因此不会将任何指标发送到 azure 门户:

【讨论】:

    【解决方案2】:

    感谢 Ivan Yang,我发现了一个 github 问题,它正在详细讨论这个问题。

    似乎有多种情况会创建无效配置。

    例如这当前也是一个无效的配置

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

    有关https://github.com/Microsoft/ApplicationInsights-dotnet/issues/826https://www.reddit.com/r/Unity3D/comments/8igabt/using_microsoft_azure_app_insights_and_unity/ 的更多详细信息

    【讨论】:

    • 我也提交了一个问题here,他们会帮助确认它是否是一个错误。
    猜你喜欢
    • 1970-01-01
    • 2016-06-13
    • 2019-11-18
    • 1970-01-01
    • 2022-06-15
    • 2018-07-09
    • 1970-01-01
    • 2016-04-25
    • 2021-04-23
    相关资源
    最近更新 更多