Try   HackMD

Grafana新增圖表

賴品璇
Fri, Jan 7, 2021


Agenda

  • Grafana
  • Grafana基本概念
  • 新增Data Source
  • 新增Dashboard
    • 表單配置說明
  • Variables變量配置
  • 新增告警
  • 使用模板

Grafana

  • 開源的分析監控平台
  • 高度定製化:可視化圖表、警報
  • 支援多源數據庫
    • InfluxDB、Prometheus、Zabbix、Elasticsearch、OpenTSDB等。
    • 地圖數據、金融、股票等。

Grafana基本概念

  • Data Source:數據源
  • Dashboard儀表板:一或多個面板組成
  • Row:組織和管理相關的Panel
  • Panel面板:Grafana數據呈現的最小單元
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →

Data Source

  • 此次Demo採用 Telegraf採集、InfluxDB儲存、Grafana展示
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →

新增Data Source

  • 點選設定→選擇Data Source
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →

  • 新增Data Source
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →

  • 本範例為InfluxDB,因此選擇[InfluxDB]
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →

  • Name可以自行取名,本範例使用[InfluxDB]
  • Query Language選擇[InfluxQL]
  • URL需輸入相對應的連結與port號,以下舉三種例子
    • 若InfluxDB與Grafana在同機台可輸入 http://localhost:8086 or http://127.0.0.1:8086

    • 若InfluxDB與Grafana於不同機台,則要輸入安裝InfluxDB機台的外網 ex.!

      Image Not Showing Possible Reasons
      • The image file may be corrupted
      • The server hosting the image is unavailable
      • The image path is incorrect
      • The image format is not supported
      Learn More →

      [pin-granfana]想要讀取[lily-testcdn]的InfluxDB,連結處就要輸入該台外網IP&Port
      Image Not Showing Possible Reasons
      • The image file may be corrupted
      • The server hosting the image is unavailable
      • The image path is incorrect
      • The image format is not supported
      Learn More →

    • 若是使用docker-compose建立InfluxDB與Grafana,可以使用http://container_name:8086,此demo為container_name: influxdb
      因此url可輸入 http://InfluxDB:8086

      Image Not Showing Possible Reasons
      • The image file may be corrupted
      • The server hosting the image is unavailable
      • The image path is incorrect
      • The image format is not supported
      Learn More →


  • Database輸入InfluxDB讀取的檔案名稱:telegraf1
  • 設定完成點選[Save & Test]按鈕
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →

  • 成功寫入
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
  • 失敗
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →

新增Dashboard

  • 點選Dashboard中的Manage
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →

  • 建立新的Dashboard

    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →

  • 建立新面板

    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →


  • 透過下拉式選單選擇要讀取的資料庫InfluxDB
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →

表單配置說明

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

  • FROM Default:默認架構圖,保持不變
    measurement:選取對應的InfluxDB表單名稱
  • WHERE:根據自己的需求選擇條件
  • SELECT field():選擇表單抓取的細項數據
    mean():細項對應InfluxDB內的資料
  • GROUPBY time():根據時間分組
    fill():當無數據時的填充值,默認值為null

數據

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

  • cpu:系統CPU的訊息
  • disk:硬碟佔用信息。
  • diskio:硬碟IO性能
  • kernel:內核
  • mem:記憶體
  • processes:處於執行狀態的程式
  • swap:類似Windows系統下的"虛擬內存"

  • DEMO記憶體的總容量與使用率
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →

  • ALIAS BY輸入資料名稱,即可顯示於圖表
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →

  • 可點選複製以方便快速設定
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →

圖表呈現方式調整-更改折線圖的顏色

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →


圖表呈現方式細項調整

  • 點選show options
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →

  • 點選Panel
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →

  • Settings更改Panel名稱
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →

  • Visualization中可以選擇圖表類型
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →

  • Display 可以設定顯示方式
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →


  • Axes Y軸

    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →

  • 根據觀測的數據來調整出相對應的單位 ex記憶體單位為byte

    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →

    • 小小補充IEC是由國際電工委員會制定,SI為國際單位制
      Image Not Showing Possible Reasons
      • The image file may be corrupted
      • The server hosting the image is unavailable
      • The image path is incorrect
      • The image format is not supported
      Learn More →
  • 顯示正確單位

    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →


  • Axes X軸
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →


新增Variables變量配置

快速切換不同變數來使用同圖表

  • 點選設定

  • 設定中有Variables

  • 增加Variables

依照需求增加變數


  • data source




  • Query :Hostname

    Refresh:控制下拉列表中的值是否更新
    never:從不。 On Dashboard Load:Dashboard加載完成之前更新(會減慢加載速度)
    On Time Range Change:如果變量選項和時間相關,或者依賴dashboard時間範圍選擇

SHOW TAG VALUES FROM "system" WITH KEY = "host" 



新增告警

  • 點選Alert

  • Create Alert

  • 設定告警規則
Rule:此條規則的名稱、多久評估一次值、等待多久從pending 轉為alert的狀態

When avg() of query(A, 5m, now) is ABOVE ___
:當Query A的平均值,從五分鐘前到現在的值超過___
當這個條件式滿足時,符合告警的設定



  • 點選Alerting,Alert Rules中可以看到目前設定好的告警

  • Notification Channels 增加通道類型

  • Demo使用slack

slack url


  • 選擇告警頻道

  • 點選Add Incoming WebHooks integration

  • 複製Webhook URL

  • 貼上url

  • 測試

  • slack 收到測試告警

  • 回到panel ,可設定告警通知訊號

使用模板

有兩種做法可以複製官網的Import ID,也可以使用json code匯入

  1. 使用Import ID,在Gragana官網中找符合需求的模板

  • 輸入條件即可找到符合條件的模板

  • 複製模板代號


  • 將代號填入Import



  • 詳細可以在設定中變更

  1. 使用前輩or自己拉得不錯的儀表板匯出json文件,再匯入
    • ex.將pin-grafana的儀錶板匯出,點選分享

  • Export>View JSON

  • 點選複製到剪貼簿

  • 點開127.0.0.1上的Grafana,Dashboards>Manage>Import

  • 將Josn文件貼上後按Load

  • 點選Import


Reference

參考1
參考2
telegraf 改參數
模板教學
參考
官方模板
https://kknews.cc/zh-tw/career/nv4zq9q.html
參考3
參考4
參考5