Prometheus MySQL_exporter

MySQL Exporter

mysqld_exporter是用来搜集mysql的性能指标的,适用于mysql5.5及其以上版本

程序安装

下载地址:https://prometheus.io/download/#mysqld_exporter

安装mysqld_exporter
tar -zxvf mysqld_exporter-0.11.0.linux-amd64.tar.gz
mv mysqld_exporter-0.11.0.linux-amd64 /usr/local/mysqld_exporter
赋权

mysqld_exporter需要连接到Mysql,所以需要Mysql的权限,我们先为它创建用户并赋予所需的权限:

CREATE USER 'exporter'@'localhost' IDENTIFIED BY 'abc123' WITH MAX_USER_CONNECTIONS 3;
GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO 'exporter'@'localhost';
创建.my.cnf文件
cd /usr/local/mysqld_exporter
cat << EOF > .my.cnf
[client]
user=exporter
password=abc123
EOF
创建systemd服务
cat <<EOF > /etc/systemd/system/mysqld_exporter.service
[Unit]
Description=mysqld_exporter
After=network.target

[Service]
Type=simple
User=prometheus
ExecStart=/usr/local/mysqld_exporter/mysqld_exporter --config.my-cnf=/usr/local/mysqld_exporter/.my.cnf
Restart=on-failure

[Install]
WantedBy=multi-user.target
EOF
启动myslqd_exporter
systemctl daemon-reload
systemctl start mysqld_exporter
systemctl status mysqld_exporter
systemctl enable mysqld_exporter
验证
curl localhost:9104/metrics

拉取数据

利用 Prometheus 的 static_configs 来拉取 mysqld_exporter 的数据。

编辑prometheus.yml文件,添加内容

- job_name: 'mysql'
    static_configs:
    - targets: ['localhost:9104']

重启prometheus,然后在Prometheus页面中的Targets中就能看到新加入的mysql

MySQL exporter Dashboard 模板

搜索mysql的Grafana Dashboard,导入进去

posted @ 2018-12-14 10:56  Bigberg  阅读(2956)  评论(0编辑  收藏  举报