iT邦幫忙

2024 iThome 鐵人賽

DAY 12
1
DevOps

Grafana Zero to Hero系列 第 12

Grafana Zero to Hero - Data Source:Relational Database

  • 分享至 

  • xImage
  •  

使用關聯式資料庫是目前最主流的儲存資料方式,Grafana 支援多種關聯式資料庫,例如開源的 PostgreSQL 和 MySQL。只需設定連線資訊並確保連線暢通後,便可輕鬆查詢資料。

pg conn
PostgreSQL 連線設定

mysql conn
MySQL 連線設定

Dashboard 搭配

Table

資料庫資料最基本的呈現方式就是表格,透過 Override 功能,能針對不同欄位設定單位、Threshold 等,進而提升資料的可讀性與視覺效果。

vis table

Time Series

如果資料庫中儲存有時間序列資料,透過 Transform 改變欄位格式,便可使用 Time Series 視覺化數據變化。

vis series

Stat

Stat 適合顯示文字或數字,尤其在需要快速呈現數據庫內的關鍵資訊時非常實用。

vis stat

DB Monitoring

Grafana 更常與關聯式資料庫搭配的應用場景是監控關聯式資料庫。這時我們會使用針對不同服務的 Prometheus Exporter,Exporter 會採集目標系統的資訊,並將其轉換為 Prometheus Metrics,例如 PostgreSQL 使用的 PostgreSQL Exporter 和 MySQL 使用的 MySQL Server Exporter

這些 Exporter 通常都有對應的 Dashboard 可供搭配使用,例如 PostgreSQL StatisticsMySQL Exporter Quickstart and Dashboard

pg monitoring
PostgreSQL Monitoring

mysql monitoring
MySQL Monitoring

Lab

範例程式碼:https://github.com/blueswen/grafana-zero-to-hero/tree/main/04-datasource/03-db

此 Lab 會建立

  1. PostgreSQL:PostgreSQL 資料庫 Service
  2. PostgreSQL Exporter:負責採集 PostgreSQL 的指標並揭露
  3. MySQL:MySQL 資料庫 Service
  4. MySQL Server Exporter:負責採集 MySQL 的指標並揭露
  5. Prometheus:採集 PostgreSQL Exporter、MySQL Server Exporter 的 Metrics
  6. Grafana:
    1. 查看預先建立好的 PostgreSQL 與 MySQL Data Source 設定方式
    2. 操作 Explore 查閱預先建立好的 PostgreSQL 與 MySQL
    3. 查看 PostgreSQL 與 MySQL 的 Monitoring Dashboard 與 Visualization 示範 Dashboard

Quick Start

  1. 啟動所有服務

    docker-compose up -d
    
  2. 檢視服務

    1. Grafana: http://localhost:3000,登入帳號密碼為 admin/admin
      1. 點擊左上 Menu > Dashboards > Provision Dashboards 即可選擇預先建立的 Dashboard
  3. 關閉所有服務

    docker-compose down
    

上一篇
Grafana Zero to Hero - Data Source:Prometheus
下一篇
Grafana Zero to Hero - Data Source:資料多樣性
系列文
Grafana Zero to Hero15
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言