问题
I monitor the execution of an Azure function using the Live Metrics Stream management UI as seen below:
Some of these metrics can be retrieved through the Application Insights REST API. However, metrics concerning overall health data, or Servers data, return a null value. For example,the performanceCounters/processCpuPercentage
endpoint produces the following output when probed:
HTTP/1.1 200
content-type: application/json; charset=utf-8
{
"value": {
"start": "2018-10-16T11:20:37.366Z",
"end": "2018-10-16T12:20:37.366Z",
"performanceCounters/processCpuPercentage": {
"avg": null
}
}
}
Is there a way to get the information appearing under the overall health and servers rows in the UI, through the API?
回答1:
It is not possible to retrieve live data at the moment.
For retrieving historical data you need the following.
1) First to come up with a query which returns data you're interested in. Here is an example (shows Request Count, 95th CPU, 95th Request Duration by Server):
let start = ago(1d);
requests
| where timestamp > start
| summarize ["RequestCount"]=count(), ["Duration"]=percentile(duration, 95) by cloud_RoleInstance
| join (
performanceCounters
| where timestamp > start
| where name == "% Processor Time Normalized"
| where category == "Process"
| summarize ["CPU"]=percentile(value, 95) by cloud_RoleInstance
) on cloud_RoleInstance
| project cloud_RoleInstance, RequestCount, Duration, CPU
| order by RequestCount
You can adjust Analytics query the way you need.
Example output:
2) Use the API reference to run "Query"
来源:https://stackoverflow.com/questions/52839073/how-can-i-retrieve-through-an-api-live-metrics-of-microsoft-application-insigh