Prometheus MySQL_exporter

MySQL Exporter

mysqld_exporter是用來蒐集mysql的性能指標的,適用於mysql5.5及其以上版本mysql

程序安裝

下載地址:https://prometheus.io/download/#mysqld_exporterlinux

安裝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的權限,咱們先爲它建立用戶並賦予所需的權限:git

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 的數據。github

編輯prometheus.yml文件,添加內容sql

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

重啓prometheus,而後在Prometheus頁面中的Targets中就能看到新加入的mysqlcurl

MySQL exporter Dashboard 模板

搜索mysql的Grafana Dashboard,導入進去性能

相關文章
相關標籤/搜索