1. 安装mysqld_exporter
$ wget https://github.com/prometheus/mysqld_exporter/releases/download/v0.14.0/mysqld_exporter-0.14.0.linux-amd64.tar.gz
$ tar xf mysqld_exporter-0.14.0.linux-amd64.tar.gz -C /usr/local/
$ cd /usr/local/
$ mv mysqld_exporter-0.14.0.linux-amd64/ mysqld_exporter
2. 配置mysql密码手动启动测试
$ vim /usr/local/mysqld_exporter/.my.cnf
[client]
port=3306
user=root
password=admin@123456
$ /usr/local/mysqld_exporter/mysqld_exporter --config.my-cnf="/usr/local/mysqld_exporter/.my.cnf"
3. 创建mysqld_exporter服务
$ vim /usr/lib/systemd/system/mysqld_exporter.service
[Unit]
Description=https://prometheus.io
[Service]
ExecStart=/usr/local/mysqld_exporter/mysqld_exporter --config.my-cnf=/usr/local/mysqld_exporter/.my.cnf
Restart=on-failure
[Install]
WantedBy=multi-user.target
4. 启动、开机自启mysqld_exporter服务
$ systemctl start mysqld_exporter
$ systemctl enable mysqld_exporter
5. prometheus添加主机
- job_name: 'mysql'
static_configs:
- targets: ['192.168.2.224:9104']
6. prometheus热加载主机
$ curl -XPOST 127.0.0.1:9090/-/reload
7.grafana导入图表模板json文件(附件中)