prometheus監(jiān)控mysql并實(shí)現(xiàn)grafana可視化

一、創(chuàng)建用于性能監(jiān)控的mysql賬號(hào)

1、創(chuàng)建數(shù)據(jù)庫(kù)用戶

CREATE USER 'exporter'@'localhost' INEDTIFIED BY 'exporter'

2、給予權(quán)限

GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO 'exporter'@'localhost'

二、啟動(dòng)用于收集mysql性能信息的mysqld_exporter

vim docker-compose.yml

version: '3'
services:
  mysqld-exporter:
    container_name: mysqld-exporter
    image: prom/mysqld-exporter
    restart: always
    ports:
      - "9104:9104"
    environment:
      - DATA_SOURCE_NAME=exporter:exporter@(xxx.xxx.xxx.xxx:3306)/
    networks:
      - proxy

networks:
  proxy:
    external: true

啟動(dòng)后訪問(wèn)http://xxx.xxx.xxx.xxx:9104/metrics,看數(shù)據(jù)是否可以成功捕獲

記得開(kāi)放9104端口

三、配置prometheus,添加mysql監(jiān)控

1、編輯配置文件

vim prometheus/prometheus.yml

global:
  scrape_interval:     15s # By default, scrape targets every 15 seconds.


  # Attach these labels to any time series or alerts when communicating with
  # external systems (federation, remote storage, Alertmanager).
  external_labels:
    monitor: 'codelab-monitor'

remote_write:
  - url: "http://xxx.xxx.xxx.xxx:8086/api/v1/prom/write?db=prometheus&u=admin&p=***"

remote_read:
  - url: "http://xxx.xxx.xxx.xxx:8086/api/v1/prom/read?db=prometheus&u=admin&p=***"

rule_files:
  - "./rules/*.yml"

alerting:
  alertmanagers:
  - static_configs:
    - targets: ['localhost:9093']

# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
  # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
  - job_name: 'prometheus'

    # Override the global default and scrape targets from this job every 5 seconds.
    scrape_interval: 5s

    static_configs:
      - targets: ['localhost:9090']

  - job_name: 'agent'
    basic_auth:
      username: admin
      password: ***

    static_configs:
      - targets: ['xxx.xxx.xxx.xxx:9100']
      
  # 添加traefik監(jiān)控
  - job_name: 'traefik'
    basic_auth:
      username: admin
      password: ***
    static_configs:
      - targets: ['xxx.xxx.xxx.xxx:8080']
      
  # 添加mysql監(jiān)控      
  - job_name: 'mysql'
    static_configs:
      - targets: ['xxx.xxx.xxx.xxx:9104']

2、重啟prometheus

docker-compose restart

四、grafana添加mysql監(jiān)控儀表盤(pán)

導(dǎo)入mysql監(jiān)控儀表盤(pán),左邊菜單欄點(diǎn)擊import,輸入7362,點(diǎn)擊load即可


導(dǎo)入7362儀表盤(pán).png

mysql監(jiān)控儀表盤(pán).png
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容