mysql监控(mysqld_exporter+prometheus+grafana)

本文是根据OCP作者的文档 自己的部署过程记录文档
如有需要请自己购买文档

1.mysqld_exporter安装

https://github.com/prometheus/mysqld_exporter/releases/download/v0.10.0/mysqld_exporter-0.10.0.linux-amd64.tar.gz

tar -xvf mysqld_exporter-0.10.0.linux-amd64.tar.gz

Mysql创建角色并且赋予权限


##密码如果强度不够自己修改
1. GRANT REPLICATION CLIENT, PROCESS ON *.* TO 'exporter'@'localhost' identified by '1q2w3e4r'; 

2. show variables like "%long_query_time%";

3. GRANT SELECT ON performance_schema.* TO 'exporter'@'localhost';
 
4.  flush privileges;

创建.my.cnf文件 vi .my.cnf:

[client]
user=exporter
password=1q2w3e4r

#运行mysqld_exporter:

./mysqld_exporter -config.my-cnf=.my.cnf  &

配置启动文件
vim /usr/lib/systemd/system/mysqld_exporter.service

[Unit]
Description=node_exporter
Documentation=https://prometheus.io/
After=network.target

[Service]
Type=simple
User=root  
ExecStart=/app/mysqld_exporter-0.10.0/mysqld_exporter --config.my-cnf=/app/mysqld_exporter-0.10.0/.my.cnf
Restart=on-failure

[Install]
WantedBy=multi-user.target

4、启动服务
systemctl daemon-reload
systemctl enable mysqld_exporter.service
systemctl start mysqld_exporter.service

5、运行状态
#systemctl status mysqld_exporter.service

6.如果mysql 是在docker容器中 可以将mysql_exporter 也放到docker 中

docker run -d \
  --name mysql_exporter \
  --restart always \
  -p 9104:9104 \
  -e DATA_SOURCE_NAME="root:password@(my-mysql-network:3306)/" \
  prom/mysqld-exporter

配置prometheus.yml

# my global config
global:
  scrape_interval:     15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
  evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
  # scrape_timeout is set to the global default (10s).

# Alertmanager configuration
alerting:
  alertmanagers:
  - static_configs:
    - targets:
       - 39.97.236.63:9093

# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
  - "first_rules.yml"
  # - "second_rules.yml"

# 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=` to any timeseries scraped from this config.
  - job_name: 'prometheus'
    static_configs:
    - targets: ['localhost:9090']

  - job_name: 'mysql'
    static_configs:
     - targets: ['47.113.23.114:9104']
       labels:
         instance: 47.113.23.114:3306
    

重启Prometheus即可

cd /app/prometheus-2.17.1
./prometheus --config.file /app/prometheus.yml --web.enable-lifecycle

mysql监控(mysqld_exporter+prometheus+grafana)_第1张图片

你可能感兴趣的:(笔记,Prometheus,grafana)