Prometheus 采集Mysql监控数据
Posted CIAS
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Prometheus 采集Mysql监控数据相关的知识,希望对你有一定的参考价值。
download mysqld_exporter
mysqld_exporter 一键监控安装脚本
- host=YOU_IP
- port=3306
- user=root
- password=root
- 采集端口是9104
vim /mysqld_exporter.sh
#!/bin/sh
# -*- coding: utf-8 -*-
# Date: 2022/11/18
echo "download mysqld_exporter"
sleep 2
wget -N -P /opt/ https://github.com/prometheus/mysqld_exporter/releases/download/v0.14.0/mysqld_exporter-0.14.0.linux-amd64.tar.gz
echo "download mysqld_exporter"
sleep 2
tar -xf /opt/mysqld_exporter-0.14.0.linux-amd64.tar.gz -C /opt/ && mv /opt/mysqld_exporter-0.14.0.linux-amd64 /opt/mysqld_exporter
echo "config mysqld_exporter"
sleep 2
cat << EOF > /opt/mysqld_exporter/.my.cnf
[client]
host=192.168.11.98
port=3306
user=root
password=root
EOF
echo "firewall mysqld_exporter port"
sleep 2
firewall-cmd --zone=public --add-port=9104/tcp --permanent && firewall-cmd --reload
echo "add mysqld_exporter.service"
sleep 2
cat << EOF > /usr/lib/systemd/system/mysqld_exporter.service
[Unit]
Description=mysqld_exporter
Documentation=https://prometheus.io/
Wants=network-online.target
After=network-online.target
[Service]
User=root
Group=root
Type=simple
ExecStart=/opt/mysqld_exporter/mysqld_exporter --config.my-cnf=/opt/mysqld_exporter/.my.cnf
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF
echo "start mysqld_exporter.service"
sleep 2
systemctl daemon-reload && systemctl enable --now mysqld_exporter
执行安装
sh /mysqld_exporter.sh
以上是关于Prometheus 采集Mysql监控数据的主要内容,如果未能解决你的问题,请参考以下文章