--- title: 設定數據源 # 簡報的名稱 tags: Grafana # 簡報的標籤 --- # 設定數據源 > [name=李俊毅] > [time=Wed, Jan 22, 2020 6:21 PM] --- ## Agenda * Terraform 建立 * K8S 建立 * GUI 建立 --- ## Terraform 建立 ---- 需建立 API Key,首先登入 Grafana ,開啟 Configuration 的 API Keys  ---- 建立一把 API Key  ---- 設定 Key 的名稱、權限與使用期限  ---- Add 後會出現一次性的私鑰,記得要記錄下來  ---- 完成後會在 Existing Keys 看到  ---- 到 Terraform 腳本中 Variable.tf 變數 grafana_url ,改成要匯入 Dashboard 的 Grafana URL ``` variable "grafana_url" { type = "string" default = "https://xsgtest.grafana.net/" } ``` ---- 接著繼續修改 Variable.tf 變數 grafana_auth ,把剛剛產出的私鑰取代掉變數 ``` variable "grafana_auth" { type = "string" default = "eyJrIjoibGVKb2RBb0Q3d0d5cDJEOEZNRDVVMEJOTmxGdjFoZXoiLCJuIjoiYWJjIiwiaWQiOjF9" } ``` ---- Terraform 主程式 ``` resource "grafana_data_source" "Prometheus" { type = "prometheus" name = "Prometheus" url = "http://Prometheus:9090" } ``` ---- 執行 Terraform 腳本 --- ## K8S 建立 ---- 在 Deployment 內新增 datasource.yaml 的路徑 ``` volumeMounts: - name: grafana-datasources mountPath: /etc/grafana/provisioning/datasources/datasource.yaml subPath: datasource.yaml volumes: - name: grafana-datasources configMap: name: grafana-datasources ``` ---- 接著新增一個 ConfigMap 設定 Datasource ,設定完畢後大功告成 ``` data: datasource.yaml: |- apiVersion: 1 datasources: - name: Prometheus type: prometheus access: proxy org_id: 1 url: http://Prometheus:9090 isDefault: true editable: false ``` --- ## GUI 建立 ---- 開啟 Grafana ,到 Configuration 的 Data Sources  ---- 新增一個 Data Source  ---- 選擇一個 Data Source 的類型  ---- 這次示範的是 Prometheus ,設定 Name、URL、Auth...等資料,設定完畢後,按下 Save & Test ,確認是否連線到 Prometheus  ----  ---- 最後就會在畫面上看到設定的內容 
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up