本文僅探討如何新增 Azure Monitor 的 Data Source,Azure Log Analytics 與 Application Insights 日後有機會再來討論。
在 Grafana 要新增 Azure Monitor 時,需要下列三項資訊:
- Directory (tenant) ID
- Application (client) ID
- Client Secret
要取得 Application ID 與 Client Secret,必須在 Azure 之中先建立一個 App。
以下為取得上述三個資料的步驟(含建立新 App):
Step 1: 註冊新的 App
在 Azure 中,選擇「Azure Active Directory」,然後點選「App registrations」來建立新 App。

下圖以建立 grafana 這個 App 為例:

註冊成功之後,就可以得到前兩項資訊了!

Step 2: 取得 Client Secret
同樣在剛剛建立的 App 頁面中左欄,可以點選「Certificates & Secrets」來取得 Client Secret:

新增之後,就可以取得第三項資訊 Client Secret 了。

Step 3: 設定外部讀取權限
取得三項資訊讓 Grafana 連接存取還不夠,還必須賦予 Grafana 等外部讀取的權限。
先進入 Azure 的「Subscription」,選取需要存取的訂閱帳戶:

點選 IAM,再新增 role assignment,將「Reader」的權限指派給剛剛新增的 App。


Step 4: 在 Grafana 中新增 Data Source

在下圖中填入前面取得的資訊,點選「Load Subscription」取得訂閱帳戶,再點選最下方的「Save & Test」,就完成了。

Step 5: 建立 Grafana Panel
下圖為建立 Virtual Machine 的 CPU Percentage 的 Panel 設定:

下圖為結果:
