TelemetryClient在Application Insights中产生不一致的结果 [英] TelemetryClient produces inconsistent results in Application Insights

查看:54
本文介绍了TelemetryClient在Application Insights中产生不一致的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试跟踪自定义指标(是否刷新).但是,这些指标只会间歇性地显示在自定义"部分下的"Application Insights"中.第一个问题:是否需要在每个"TrackMetric(metric)"调用之后运行"flush()",以便将遥测发送到Application Insights?第二:为什么会出现这种间歇性行为?我一次只写一个指标,所以这好像并没有使Application Insights重载成千上万个单独的调用.这是我的代码(来自简单的控制台应用程序):

 公共课程{公共静态无效的Main(string [] args){var telemetryClient =新的TelemetryClient(){上下文= {InstrumentationKey ="{{隐藏的仪器密钥}}"}};var metric = new MetricTelemetry{名称="ImsWithContextMetric2",总和= 42.0};telemetryClient.TrackMetric(metric);telemetryClient.Flush();}} 

我在Application Insights中也遇到了这种奇怪的行为,我添加的自定义指标显示在不可用/不建议使用的指标"部分下.在自定义"部分下,我什至没有添加一个指标,即进程CPU(所有内核)".为什么会出现这种奇怪行为的任何想法?:

解决方案

是否需要在每个"TrackMetric(metric)"调用之后运行"flush()",才能将遥测发送到Application Insights?

由于您正在使用控制台应用程序将事件发送到Application Insights(这可能是短暂的),因此偶尔调用一次 .Flush()绝对是一个好习惯.SDK使用InMemoryChannel发送遥测数据,并使用内存队列将其分批发送.因此,调用 .Flush()以便强制推送数据非常重要.好的做法可能是在事件发生后添加一些等待时间:

  telemetryClient.Flush();Thread.Sleep(1000); 

更多阅读:,用于跟踪CPU使用率.我相信,如果应用程序在IIS或Azure上运行,则SDK仅能够跟踪这些计数器.创建Application Insights资源时,它可能是在内部添加的.您可以忽略它,因为它没有要绘制的数据.

希望这会有所帮助!

I tried tracking custom metrics with and without flushing it. However, the metrics only intermittently shows up in Application Insights under the "Custom" section. First question: Is it required to run "flush()" after every single "TrackMetric(metric)" call in order for the telemetry to be sent to Application Insights? Second: Why is there this intermittent behavior? I'm only writing one metric at a time, so it's not as if I'm overloading Application Insights with thousands of separate calls. Here is my code (This is from a simple Console App):

    public class Program
{
    public static void Main(string[] args)
    {
        var telemetryClient = new TelemetryClient()
        {
            Context = { InstrumentationKey = "{{hidden instrumentation key}}" }
        };
        var metric = new MetricTelemetry
        {
            Name = "ImsWithContextMetric2",
            Sum = 42.0
        };
        telemetryClient.TrackMetric(metric);
        telemetryClient.Flush();
    }
}

I'm also getting this strange behavior in Application Insights in which the custom metric I add shows up under a "Unavailable/deprecated Metrics" section. And a metric that I didn't even add called "Process CPU (all cores)" pops up under the "Custom" section. Any ideas why this strange behavior would occur?:

解决方案

Is it required to run "flush()" after every single "TrackMetric(metric)" call in order for the telemetry to be sent to Application Insights?

Since you are using a Console Application to send events to Application Insights, which might be short-lived, it is definitely a good practice to call .Flush() every once in a while. The SDK uses the InMemoryChannel to send telemetry and sends it in batches using from an in-memory queue. So it is very important to call the .Flush() so that the data is forcefully pushed. A good practice might be to add a bit of wait after the event:

telemetryClient.Flush();
Thread.Sleep(1000);

More reading: Flushing data, Ensure you don't lose telemetry

However, the metrics only intermittently shows up in Application Insights under the "Custom" section. Why is there this intermittent behavior? I'm only writing one metric at a time, so it's not as if I'm overloading Application Insights with thousands of separate calls.

Sometimes there is a delay in metrics showing up in the Azure Portal. It can be up to a few minutes too. But if you have set it up correctly, you aren't exceeding the throttling limit, and adaptive sampling is disabled, then there is no reason for which telemetry should be intermittent. However if you still feel something is wrong, start a fiddler trace (make sure you are capturing from non-browser sessions) and check if a call is going out to dc.services.visualstudio.com. Make sure the response is 200 OK and if the items were accepted by the server.

I'm also getting this strange behavior in Application Insights in which the custom metric I add shows up under a "Unavailable/deprecated Metrics" section.

What version of the SDK are you using? I just tried out the same scenario and the custom metrics are showing up correctly.

And a metric that I didn't even add called "Process CPU (all cores)" pops up under the "Custom" section.

"Process CPU" is a performance counter which is used to track CPU utilization. I believe the SDK will only be able to track these counters if the app is running under IIS or on Azure. It probably got added internally when you created your Application Insights resource. You can ignore it since it won't have data to chart.

Hope this helps!

这篇关于TelemetryClient在Application Insights中产生不一致的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆