prometheus mysqld_exporter监控mysql-5.7

目录

一、CentOS7.5 Prometheus2.5+Grafana5.4监控部署

二、Prometheus监控node_exporter的告警规则

三、prometheus mysqld_exporter监控mysql-5.7

1、下载及解压安装包
https://github.com/prometheus/mysqld_exporter
tar -xvf mysqld_exporter-0.11.0.linux-amd64.tar.gz -C /app/prometheus

2、创建密码填写内容.my.cnf文件
vim .my.cnf
[client]
host=127.0.0.1
user=root
password=root
3、创建mysqld_exporter.service 的 systemd unit 文件
vim /usr/lib/systemd/system/mysqld_exporter.service
[Unit]
Description=node_exporter
Documentation=https://prometheus.io/
After=network.target

[Service]
Type=simple
User=prometheus
ExecStart=/app/prometheus/mysqld_exporter/mysqld_exporter --config.my-cnf=/app/prometheus/mysqld_exporter/.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
● mysqld_exporter.service - node_exporter
   Loaded: loaded (/usr/lib/systemd/system/mysqld_exporter.service; enabled; vendor preset: disabled)
   Active: active (running) since 一 2019-06-17 00:11:52 CST; 4s ago
     Docs: https://prometheus.io/
 Main PID: 27193 (mysqld_exporter)
   CGroup: /system.slice/mysqld_exporter.service
           └─27193 /app/prometheus/mysqld_exporter/mysqld_exporter --config.my-cnf=/app/prometheus/mysqld_exporter/.my.cnf

6月 17 00:11:52 qas-zabbix4 systemd[1]: Started node_exporter.
6月 17 00:11:52 qas-zabbix4 mysqld_exporter[27193]: time="2019-06-17T00:11:52+08:00" level=info msg="Starting mysqld_exporter (version=0.11.0, branch=HEAD, revision=5d7179615...ter.go:206"
6月 17 00:11:52 qas-zabbix4 mysqld_exporter[27193]: time="2019-06-17T00:11:52+08:00" level=info msg="Build context (go=go1.10.3, user=root@3d3ff666b0e4, date=20180629-15:00:3...ter.go:207"
6月 17 00:11:52 qas-zabbix4 mysqld_exporter[27193]: time="2019-06-17T00:11:52+08:00" level=info msg="Enabled scrapers:" source="mysqld_exporter.go:218"
6月 17 00:11:52 qas-zabbix4 mysqld_exporter[27193]: time="2019-06-17T00:11:52+08:00" level=info msg=" --collect.global_status" source="mysqld_exporter.go:222"
6月 17 00:11:52 qas-zabbix4 mysqld_exporter[27193]: time="2019-06-17T00:11:52+08:00" level=info msg=" --collect.global_variables" source="mysqld_exporter.go:222"
6月 17 00:11:52 qas-zabbix4 mysqld_exporter[27193]: time="2019-06-17T00:11:52+08:00" level=info msg=" --collect.slave_status" source="mysqld_exporter.go:222"
6月 17 00:11:52 qas-zabbix4 mysqld_exporter[27193]: time="2019-06-17T00:11:52+08:00" level=info msg=" --collect.info_schema.tables" source="mysqld_exporter.go:222"
6月 17 00:11:52 qas-zabbix4 mysqld_exporter[27193]: time="2019-06-17T00:11:52+08:00" level=info msg="Listening on :9104" source="mysqld_exporter.go:232"
Hint: Some lines were ellipsized, use -l to show in full.

http://172.16.8.59:9104/metrics
prometheus mysqld_exporter监控mysql-5.7_第1张图片
6、prometheus.service添加配置
vim /app/prometheus/cfg/prometheus.yml 
  - job_name: 'mysqld'     
    file_sd_configs:
      - files: ['/app/prometheus/sd_cfg/mysqld.yml']
        refresh_interval: 5s        
7、基于文件发现添加配置文件
vim /app/prometheus/sd_cfg/mysqld.yml
- targets: ['172.16.8.59:9104']
  labels:
   name: mysql
8、重启服务
systemctl restart prometheus.service 

prometheus mysqld_exporter监控mysql-5.7_第2张图片
9、grafana图像展示

prometheus mysqld_exporter监控mysql-5.7_第3张图片

你可能感兴趣的:(Prometheus)