【數位3C】Grafana系統搭配GCP Monitoring資訊做監控與使用通知告警

【數位3C】Grafana系統搭配GCP Monitoring資訊做監控與使用通知告警 3C/資訊/通訊/網路 GCP-google cloud platform 架站 網路

為了系統的穩定運行, 我們通常會對系統或是服務做監控

放在GCP(Google Cloud Platform)的當然也是如此

雖然GCP本身已經提供了服務的監控Montioring(https://console.cloud.google.com/monitoring)

不過使用上感覺有點複雜, 乍看之下沒有Grafana來的直覺

加上既有的系統還搭配了Telegram做告警服務(Alert), 所以會比較偏向將GCP的監控資料納入Grafana的掌控中

【數位3C】Grafana系統搭配GCP Monitoring資訊做監控與使用通知告警 3C/資訊/通訊/網路 GCP-google cloud platform 架站 網路

 

 

後來發現好像沒有想像中複雜

步驟大概是以下

首先要先啟用兩個API服務, 有的API服務用量大時會有費用, 要注意一下!

  1. Monitoring API (Stackdriver Monitoring API)

https://console.cloud.google.com/apis/library/monitoring.googleapis.com

【數位3C】Grafana系統搭配GCP Monitoring資訊做監控與使用通知告警 3C/資訊/通訊/網路 GCP-google cloud platform 架站 網路

  1. Cloud Resource Manager API

https://console.cloud.google.com/apis/library/cloudresourcemanager.googleapis.com

【數位3C】Grafana系統搭配GCP Monitoring資訊做監控與使用通知告警 3C/資訊/通訊/網路 GCP-google cloud platform 架站 網路

 

再來建立服務帳號

https://console.cloud.google.com/apis/credentials

【數位3C】Grafana系統搭配GCP Monitoring資訊做監控與使用通知告警 3C/資訊/通訊/網路 GCP-google cloud platform 架站 網路

 

設定想用的名稱後選建立

【數位3C】Grafana系統搭配GCP Monitoring資訊做監控與使用通知告警 3C/資訊/通訊/網路 GCP-google cloud platform 架站 網路

 

需要開放權限

這裡是設定Monitor管理員

【數位3C】Grafana系統搭配GCP Monitoring資訊做監控與使用通知告警 3C/資訊/通訊/網路 GCP-google cloud platform 架站 網路

 

最後還要設定使用者名稱

雖然上面顯示選用, 但實測這裡不設定之後會出現錯誤

【數位3C】Grafana系統搭配GCP Monitoring資訊做監控與使用通知告警 3C/資訊/通訊/網路 GCP-google cloud platform 架站 網路

 

建立好後

到這個服務帳號裡面建立金鑰

格式選擇JSON後下載金鑰

【數位3C】Grafana系統搭配GCP Monitoring資訊做監控與使用通知告警 3C/資訊/通訊/網路 GCP-google cloud platform 架站 網路

【數位3C】Grafana系統搭配GCP Monitoring資訊做監控與使用通知告警 3C/資訊/通訊/網路 GCP-google cloud platform 架站 網路

 

接著到Grafana的管理介面設定資料來源

【數位3C】Grafana系統搭配GCP Monitoring資訊做監控與使用通知告警 3C/資訊/通訊/網路 GCP-google cloud platform 架站 網路

 

點選建立…Stackdriver

【數位3C】Grafana系統搭配GCP Monitoring資訊做監控與使用通知告警 3C/資訊/通訊/網路 GCP-google cloud platform 架站 網路

 

到這個頁面後上面自定義來源名稱

接著到下面的認證部分選擇Google JWT File並上傳剛剛產生下載的金鑰

【數位3C】Grafana系統搭配GCP Monitoring資訊做監控與使用通知告警 3C/資訊/通訊/網路 GCP-google cloud platform 架站 網路

【數位3C】Grafana系統搭配GCP Monitoring資訊做監控與使用通知告警 3C/資訊/通訊/網路 GCP-google cloud platform 架站 網路

 

成功上傳後會顯示這樣

【數位3C】Grafana系統搭配GCP Monitoring資訊做監控與使用通知告警 3C/資訊/通訊/網路 GCP-google cloud platform 架站 網路

 

點選Save & Test會顯示有沒有成功

像這個畫面就是有連線成功, 若是失敗, 就會顯示紅色的…

【數位3C】Grafana系統搭配GCP Monitoring資訊做監控與使用通知告警 3C/資訊/通訊/網路 GCP-google cloud platform 架站 網路

 

成功後就可以來產生報表了…開個新面板Show資料吧!

【數位3C】Grafana系統搭配GCP Monitoring資訊做監控與使用通知告警 3C/資訊/通訊/網路 GCP-google cloud platform 架站 網路

 

query的來源要選擇剛剛建立的Stackdriver

【數位3C】Grafana系統搭配GCP Monitoring資訊做監控與使用通知告警 3C/資訊/通訊/網路 GCP-google cloud platform 架站 網路

 

選擇好後

會發現可以查詢的選項跟一般不太一樣

【數位3C】Grafana系統搭配GCP Monitoring資訊做監控與使用通知告警 3C/資訊/通訊/網路 GCP-google cloud platform 架站 網路

 

看起來GCP的監控資料是以服務為基礎來做查詢

所以要先選擇需要顯示的服務才能進一步去選擇篩選項目

【數位3C】Grafana系統搭配GCP Monitoring資訊做監控與使用通知告警 3C/資訊/通訊/網路 GCP-google cloud platform 架站 網路

 

水哥這裡選的是Kubernetes(K8S)

不過可以發現能篩選的項目非常的細, 這部分就是看需求做檢視, 只能慢慢嘗試

【數位3C】Grafana系統搭配GCP Monitoring資訊做監控與使用通知告警 3C/資訊/通訊/網路 GCP-google cloud platform 架站 網路

 

至少已經能show出來囉, Alert再依照想要的限度做調整就可以了

【數位3C】Grafana系統搭配GCP Monitoring資訊做監控與使用通知告警 3C/資訊/通訊/網路 GCP-google cloud platform 架站 網路

 

 

 

 

 

 

 

 

 

請多指教, 有什麼想法都可以說