azure - 使用遥测客户端的 Get-Metric 方法出现错误“尝试通过指定 2 个维度来获取指标系列,但此指标有 3 个维度”
问题描述
string source = string.IsNullOrEmpty(this.logger.PStore[Constants.CurrentKey]) ? "NA" : this.logger.PStore[Constants.CurrentKey];
string cId = string.IsNullOrEmpty(this.logger.Store[Constants.CId]) ? "NA" : this.logger.Store[Constants.CId];
public virtual void GetMetric(string metricId, double metricValue, string source = "", string cId = "")
{
Metric metric = this.TelemetryClient.GetMetric(metricId, "Source", "CorrelationId");
metric.TrackValue(metricValue, source, cId);
}
我用于在应用程序洞察力中记录数据的上述代码。GetMetric 具有 2 个维度和一个 metricId,Track 值具有值和维度。
Microsoft.ApplicationInsights,版本=2.17.0.146
解决方案
事实上,除了metricId
,这个度量有 3 个维度metricValue
:source
和cId
。
MetricIdentifier
当维度超过三个时可以使用:
MetricIdentifier id = new MetricIdentifier("metricNamespace", "metricId","metricValue", "source ", "cId");
Metric metric = client.GetMetric(cId);
metric.TrackValue(metricNamespace,metricID,metricValue, source, cId);
三个以上维度可以参考TelemetryClient.GetMetric 方法、TrackMetric以及如何使用 MetricIdentifier
推荐阅读
- c# - 如何从 Lua 调用 C# 委托,委托可以抛出异常
- c# - TaskCompletionSource - 处理时代码停止执行
- python - 使用 OpenCV 和 Python 识别注册细节
- oracle - Oracle Apex 用户图标更改为图像
- c# - C#:如何表达可以从字符串转换类型的约束?
- concave-hull - 是否有可以指定要排除的点的凹壳算法?
- spring-boot - 搜索时的Spring数据弹性搜索日期问题
- azure - 是否可以通过 docker 映像将我的 Azure 应用服务迁移到自托管服务器?
- api - 从 API 获取 Facebook 广告活动变更日志和管理员
- linux - 用于检查简单打字稿文件中的值的 Shell 脚本