簡體   English   中英

如何使用 REST API 過濾 AppInsights 自定義指標

[英]How to filter AppInsights custom metrics with REST API

我正在嘗試使用 REST API 來檢索 AppInsights 自定義指標並在查詢中使用過濾器。

創建指標的代碼:

var telemetry = new MetricTelemetry();
telemetry.Context.InstrumentationKey = instrumentationKey;
telemetry.Name = FacebookFupMetricName;
telemetry.Value = amount;
telemetry.Timestamp = DateTime.Now;
telemetry.Properties["agencyCode"] = agencyCode;
telemetry.Properties["accountCode"] = accountCode;
telemetry.Properties["category"] = category;
telemetry.Properties["action"] = action;
var client = new TelemetryClient();
client.TrackMetric(telemetry);
client.Flush();

運行此代碼時,該指標在 Azure 中創建。

現在我想使用 REST API 來檢索指標並在查詢中使用過濾器。 當我使用過濾器時

category eq 'cat001'

查詢以錯誤結束

以下維度在此指標的過濾子句中無效:類別

查詢 url 是:

https://dev.applicationinsights.io/apiexplorer/metrics?appId=<appId>&apiKey=<apiKey>&metricId=customMetrics%2FFacebookFupAction&timespan=P1D&aggregation=sum&filter=category%20eq%20%27cat001%27

問題是,是否可以使用維度過濾自定義指標?

在過濾器字段中,您應該使用customDimensions/category eq 'cat001'

生成的 url 格式如下:

`https://dev.applicationinsights.io/apiexplorer/metrics?appId=<appId>&apiKey=<apiKey>&metricId=customMetrics%2FFacebookFupMetricName&aggregation=sum&filter=customDimensions%2Fcategory%20eq%20'cat001'`

截圖如下:

在此處輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM