查看Application Insights內訊息的docker是屬於那個Host

Edward Kuo
Aug 21 · 5 min read
Image for post
Image for post

當我們把有加入Application Insights的Application放入到Docker,同時,這個Docker被佈署在多個Host時候,在Application Insights裡面看到這個Application 訊息是看不到問題是發生在那一個Host上面,因為,對於Application Insights只能收到這個Docker的本身的名字。如果是在非Docker環境下,在Cloud_RoleInstance是顯示HostName

Image for post
Image for post

這樣困惱會是在維運時候,有些狀況會發生在某幾台Host的Docker就容易出問題,要去找到這台Host就不容易。因此,目前可以透過方法就是必須先在每一台Host 安裝好Azure Monitor,並且加入Container的解決方案

Image for post
Image for post

一旦有安裝Container解決方案,就可以在Log Analytics內看到這四個資料集

Image for post
Image for post

這四個資料集分別是代表每個Container在這台Host的狀態log,當然也包含每個Host裡面有多少的Container、每個Container耗用多少CPU或是RAM…等等相關資訊。

ContainerInventory 這份資料集內,就會記載著每個ContainerName所對應的Host Name

Image for post
Image for post

既然有了這樣資訊資訊,就可以將Application Insights內的資訊和ContainerInventory 整合起來

舉例來說想要知道該Application Container所發生的Exception是分布在那些Host的數量,可以先取得被記錄在Application Insight的Exception數量

let AP=exceptions
| summarize count_sum = sum(itemCount) by bin(timestamp,15m),host=cloud_RoleInstance
| order by timestamp desc;

然後再取得被記錄在Azure Monitor的ContainerInventory 資訊,如果是在Application Insights的Log Query,就需要做到跨資源查詢的功能,要做到跨資源查詢可以參考 Azure 監視器中執行跨資源記錄查詢 方式,就可以做到

因此,這時候就可以查詢ContainerInventory 資料,並產生一個資料集

let dockername=workspace('AzureMonitorName').ContainerInventory
| project Computer,host=ContainerHostname
| distinct Computer,host;

當我們有這兩個資料集的時候,就只需要把資料集做left join就可以串出我們要的資料。然後用上面兩個資料集中欄位是Host作為Key值

let Result=AP
| join kind = leftouter
dockername
on host;

這樣方式就可以取得該Application Container問題發生是在那一台Host上面了

雖然麻煩一點,但是還是可以達到想要的需求,在找問題時候,也會方便許多

參考資料

EK.Technology Learn

Design,Thinking,Coding & have fun every thing

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store