gpt4 book ai didi

c# - 为什么某些 Azure App Insight 指标没有出现在门户中?

转载 作者:行者123 更新时间:2023-12-03 00:55:55 25 4
gpt4 key购买 nike

我已在我的应用中实现了自定义指标,以便将这些指标发送到 Azure 中的 App Insights:

using (var operation = tc.StartOperation<DependencyTelemetry>("MetricName"))
{
//some long running code
}

如果我运行此代码,例如5 次,然后查看 Azure 门户中的 App Insights 指标:

dependencies 
| where type == 'Other'

然后我通常会看到此指标的大约 1-2 个条目以及时间戳。我一遍又一遍地重复这一点,但总是一样,考虑到代码运行了 5 次,其他缺失的指标会发生什么情况? (每次运行之间有相当大的延迟)

我想知道它们是否被从采样中过滤掉,但根据文档 App Insights 不会采样指标:https://learn.microsoft.com/en-us/azure/azure-monitor/app/sampling

“Application Insights 不会在任何采样技术中对 session 、指标(包括自定义指标)或性能计数器遥测类型进行采样。这些类型始终被排除在采样之外,因为精度降低可能是非常不希望的这些遥测类型。”

我可以确认这不是延迟,我已经尝试等待很多小时来查看丢失的内容是否出现。有什么想法吗?

最佳答案

嗯,您正在跟踪依赖项,而不是指标(它们存储在 customMetrics 表中)。由于您正在跟踪依赖项,采样可能就是原因。

要跟踪指标,请使用描述的方法 in the docs :

_telemetryClient.GetMetric("myMetric").TrackValue(42);

If we want to simply time the duration of a block of code inside a using statement, is StartOperation() not the way to go then? Is that some other concept than metrics?

这绝对是一个选项,因为依赖项遥测确实存储执行所花费的时间。但它与指标存储在不同的表中,并且需要进行采样。因此,您可以从采样中排除依赖性,但这可能会导致大量数据摄入。或者您创建自己的代码来跟踪如下指标:

public class MetricOperation : IDisposable
{
private readonly TelemetryClient _tc;
private readonly Stopwatch _sw = new Stopwatch();
private readonly string _operationName;

public MetricOperation(TelemetryClient tc, string operationName)
{
_tc = tc;
_operationName = operationName;

_sw.Start();
}

public void Dispose()
{
_sw.Stop();
_tc.GetMetric(_operationName).TrackValue(_sw.ElapsedMilliseconds);
}
}

并这样调用它

using(new MetricOperation(tc, "metricName"))
{
// some long running operation
}

关于c# - 为什么某些 Azure App Insight 指标没有出现在门户中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68816109/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com