如何使用REST API过滤AppInsights自定义指标

时间:2019-10-16 14:07:37

标签: c# azure azure-rest-api

我正在尝试使用REST API来检索AppInsights自定义指标,并在查询中使用过滤器。

创建指标的代码:

JDBC

运行此代码时,指标在Azure中创建。

现在,我想使用REST API来检索指标并在查询中使用过滤器。当我使用过滤器

     Connection conn;

     try{
         conn = DriverManager.getConnection(CONN_STRING,USERNAME,PASSWORD);

         PreparedStatement pstmt=conn.prepareStatement("SELECT * FROM airplane.airlinedb WHERE 
         ORIGIN = ? AND DESTINATION = ? LIMIT 100;");
         pstmt.setString(1,j.from); // from is the string variable
         pstmt.setString(2,j.destination); //destination is another string variable
         ResultSet rs=pstmt.executeQuery();  
         User user;
         while(rs.next())
         {
             user = new User(rs.getString("ORIGIN"), 
             rs.getString("DESTINATION"),rs.getInt("FLIGHT_NUMBER"), rs.getInt("TIME_TRAVEL") , 
             rs.getInt("PRICE"));
             usersList.add(user);
         }
         conn.close();


        }
         catch(SQLException e){
         System.err.println(e);
         }
     return usersList;
}

查询以错误结束

  

以下维度在该指标的过滤条件子句中无效:类别

查询网址为:

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

问题是,是否可以按维度过滤自定义指标?

1 个答案:

答案 0 :(得分:1)

在过滤器字段中,您应该使用customDimensions/category eq 'cat001'

生成的网址采用以下格式:

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

以下截图:

enter image description here