Prometheus. Monitor MySQL server using Prometheus: различия между версиями
Cless (обсуждение | вклад) (Новая страница: «Категория:Prometheus __ОБЯЗАТЕЛЬНОЕ_ОГЛАВЛЕНИЕ__») |
Cless (обсуждение | вклад) |
||
| Строка 1: | Строка 1: | ||
[[Категория:Prometheus]] | [[Категория:Prometheus]] | ||
__ОБЯЗАТЕЛЬНОЕ_ОГЛАВЛЕНИЕ__ | __ОБЯЗАТЕЛЬНОЕ_ОГЛАВЛЕНИЕ__ | ||
== At Client - MySQL Server (192.168.199.181) == | |||
<code>mysql -u -root -p</code> | |||
<code>CREATE USER 'mysqlexporter'@'localhost' IDENTIFIED BY 'dispersia85D';</code> | |||
<code>GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO 'mysqlexporter'@'localhost';</code> | |||
<code>FLUSH PRIVILEGES;</code> | |||
Download mysqld_exporter from the official download page | |||
<code>wget <nowiki>https://github.com/prometheus/mysqld_exporter/releases/download/v0.11.0/mysqld_exporter-0.11.0.linux-amd64.tar.gz</nowiki></code> | |||
<code>tar -xvzf mysqld_exporter-0.11.0.linux-amd64.tar.gz</code> | |||
<code>useradd -rs /bin/false mysqld_exporter</code> | |||
Copy mysqld_exporter file to /usr/bin. | |||
<code>mv mysqld_exporter-0.11.0.linux-amd64/mysqld_exporter /usr/bin</code> | |||
<code>chown mysqld_exporter:mysqld_exporter /usr/bin/mysqld_exporter</code> | |||
<code>mkdir -p /etc/mysql_exporter</code> | |||
<code>nano /etc/mysql_exporter/.my.cnf</code> | |||
[client] | |||
user=mysqlexporter | |||
password=dispersia85D | |||
<code>chown -R mysqld_exporter:mysqld_exporter /etc/mysql_exporter</code> | |||
<code>chmod 600 /etc/mysql_exporter/.my.cnf</code> | |||
<code>nano /etc/systemd/system/mysql_exporter.service</code> | |||
[Unit] | |||
Description=MySQL Server fosslinux | |||
After=network.target | |||
[Service] | |||
User=mysqld_exporter | |||
Group=mysqld_exporter | |||
Type=simple | |||
ExecStart=/usr/bin/mysqld_exporter --config.my-cnf=/etc/mysql_exporter/.my.cnf | |||
Restart=always | |||
[Install] | |||
WantedBy=multi-user.target | |||
<code>systemctl daemon-reload</code> | |||
<code>systemctl enable mysql_exporter</code> | |||
<code>systemctl start mysql_exporter</code> | |||
Web | |||
<code>http://<mysql_Server_IP>:9104/metrics</code> | |||
== At Prometheus Server == | |||
<code>nano /etc/prometheus/prometheus.yml</code> | |||
... | |||
- job_name: 'mysql_exporter_fosslinux' | |||
scrape_interval: 5s | |||
static_configs: | |||
- targets: ['192.168.199.181:9104'] | |||
<code>systemctl restart prometheus</code> | |||
Web | |||
<code>http://<prometheus-IP>:9090/targets</code> | |||
Версия 11:55, 21 июля 2022
At Client - MySQL Server (192.168.199.181)
mysql -u -root -p
CREATE USER 'mysqlexporter'@'localhost' IDENTIFIED BY 'dispersia85D';
GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO 'mysqlexporter'@'localhost';
FLUSH PRIVILEGES;
Download mysqld_exporter from the official download page
wget https://github.com/prometheus/mysqld_exporter/releases/download/v0.11.0/mysqld_exporter-0.11.0.linux-amd64.tar.gz
tar -xvzf mysqld_exporter-0.11.0.linux-amd64.tar.gz
useradd -rs /bin/false mysqld_exporter
Copy mysqld_exporter file to /usr/bin.
mv mysqld_exporter-0.11.0.linux-amd64/mysqld_exporter /usr/bin
chown mysqld_exporter:mysqld_exporter /usr/bin/mysqld_exporter
mkdir -p /etc/mysql_exporter
nano /etc/mysql_exporter/.my.cnf
[client] user=mysqlexporter password=dispersia85D
chown -R mysqld_exporter:mysqld_exporter /etc/mysql_exporter
chmod 600 /etc/mysql_exporter/.my.cnf
nano /etc/systemd/system/mysql_exporter.service
[Unit] Description=MySQL Server fosslinux After=network.target [Service] User=mysqld_exporter Group=mysqld_exporter Type=simple ExecStart=/usr/bin/mysqld_exporter --config.my-cnf=/etc/mysql_exporter/.my.cnf Restart=always [Install] WantedBy=multi-user.target
systemctl daemon-reload
systemctl enable mysql_exporter
systemctl start mysql_exporter
Web
http://<mysql_Server_IP>:9104/metrics
At Prometheus Server
nano /etc/prometheus/prometheus.yml
... - job_name: 'mysql_exporter_fosslinux' scrape_interval: 5s static_configs: - targets: ['192.168.199.181:9104']
systemctl restart prometheus
Web
http://<prometheus-IP>:9090/targets