問題情形
通過Application Insights收集到名額資料後,如Request,Trace,Exception。但是預設的Insights圖表不能滿足業務的需求,需要自定義相應的類SQL語句并制作圖表以便直覺的顯示,避免每次都需要重新查詢資料并轉換為圖表。
類SQL的查詢語句在Applicaiton Insights示例為:
// Response time trend
// Chart request duration over the last 12 hours.
requests
| where timestamp > ago(12h)
| summarize avgRequestDuration=avg(duration) by bin(timestamp, 10m) // use a time grain of 10 minutes
| render timechart
// Operations performance
// Calculate request count and duration by operations.
requests
| summarize RequestsCount=sum(itemCount), AverageDuration=avg(duration), percentiles(duration, 50, 95, 99) by operation_Name // you can replace 'operation_Name' with another value to segment by a different property
| order by RequestsCount desc // order from highest to lower (descending)
// Top 10 countries by traffic
// Chart the amount of requests from the top 10 countries.
requests
| summarize CountByCountry=count() by client_CountryOrRegion
| top 10 by CountByCountry
| render piechart
// Top 3 browser exceptions
// What were the highest reported exceptions today?
exceptions
| where notempty(client_Browser) and client_Type == 'Browser'
| summarize total_exceptions = sum(itemCount) by problemId
| top 3 by total_exceptions desc
// Failed requests – top 10
// What are the 3 slowest pages, and how slow are they?
requests
| where success == false
| summarize failedCount=sum(itemCount) by name
| top 10 by failedCount desc
| render barchart
// Failed operations
// Calculate how many times operations failed, and how many users were impacted.
requests
| where success == false
| summarize failedCount=sum(itemCount), impactedUsers=dcount(user_Id) by operation_Name
| order by failedCount desc
操作步驟
Application Insights提供了非常簡單的辦法來完成制作圖表的步驟,隻需要在Logs頁面中,按照上面的類SQL語句寫好後,點選右上角的固定到儀表盤(Pin To Dashboard)即可。
參考資料:
建立診斷設定以在 Azure 中收集資源日志和名額:https://docs.azure.cn/zh-cn/azure-monitor/platform/diagnostic-settings
當在複雜的環境中面臨問題,格物之道需:濁而靜之徐清,安以動之徐生。 雲中,恰是如此!