這次主要介紹的是 Azure Log Analytics ,我們將使用 KQL (Kusto query language) 去分析 Application Insights 中收集得來的資訊。
首先我們可以到 Azure Portal
分析頁面
exceptions
| project operation_Name , outerMessage , timestamp
這個有點像是 SQL
SELECT operation_Name, outerMessage , timestamp
FROM exceptions
exceptions
| project operation_Name , outerMessage , timestamp
| order by timestamp desc
| take 1
這個有點像是 SQL
SELECT top 1 operation_Name, outerMessage , timestamp
FROM exceptions
ORDER BY timestamp DESC
exceptions
| summarize Count=count() by operation_Name
這個有點像是 SQL
SELECT operation_Name, COUNT(*)
FROM exceptions
GROUP BY operation_Name
requests
| join kind= leftouter
(exceptions) on $left.operation_Id == $right.operation_Id
| order by timestamp desc
| project operation_Id , name, resultCode , outerMessage ,timestamp
這個有點像是 SQL
SELECT operation_Id , name, resultCode , outerMessage ,timestamp
FROM requests
LEFT JOIN exceptions
ON requests.operation_Id = exceptions.operation_Id
ORDER BY timestamp desc
requests
| join kind= leftouter
(exceptions) on $left.operation_Id == $right.operation_Id
| where resultCode startswith "4" or resultCode startswith "5"
| project operation_Id , name, resultCode , outerMessage ,timestamp
這個有點像是 SQL
SELECT operation_Id , name, resultCode , outerMessage ,timestamp
FROM requests
LEFT JOIN exceptions
ON requests.operation_Id = exceptions.operation_Id
WHERE resultCode LIKE '4%' OR resultCode LIKE '5%'
當然目前這個語法我還在學當中,跟 SQL 還有有一點差別,目前我用的不是很順,囧。
像是我本來想要直接用 resultCode 轉成 int 但是不知道怎麼轉,不然我第五個示範應該是這樣寫的 where resultCode >= 400 or resultCode < 599