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=<job_name>` 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

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值