1.Install MySQL Exporter
#curl -s https://api.github.com/repos/prometheus/mysqld_exporter/releases/latest | grep browser_download_url | grep linux-amd64 | cut -d '"' -f 4 | wget -qi -
#tar xvf mysqld_exporter*.tar.gz
#sudo mv mysqld_exporter-*.linux-amd64/mysqld_exporter /usr/local/bin/
#sudo chmod +x /usr/local/bin/mysqld_exporter
2.Checking version of mysql exporter
#mysqld_exporter --version
3.Create a user to collect the matrices of MySQL
#mysql -u root -p
CREATE USER 'mysqld_exporter'@'localhost' IDENTIFIED BY 'StrongPassword';
GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO 'mysqld_exporter'@'localhost';
FLUSH PRIVILEGES;
EXIT
4.Create database credentials file
#sudo vi /etc/.mysqld_exporter.cnf
[client]
user=mysqld_exporter
password=StrongPassword
5.Enable ownership permission
#chown root:prometheus /etc/.mysqld_exporter.cnf
6.Create a service for mysql exporter
#vi /etc/systemd/system/mysql_exporter.servic
[Unit]
Description=Prometheus MySQL Exporter
After=network.target
User=prometheus
Group=prometheus
[Service]
Type=simple
Restart=always
ExecStart=/usr/local/bin/mysqld_exporter \
--config.my-cnf /etc/.mysqld_exporter.cnf \
--collect.global_status \
--collect.info_schema.innodb_metrics \
--collect.auto_increment.columns \
--collect.info_schema.processlist \
--collect.binlog_size \
--collect.info_schema.tablestats \
--collect.global_variables \
--collect.info_schema.query_response_time \
--collect.info_schema.userstats \
--collect.info_schema.tables \
--collect.perf_schema.tablelocks \
--collect.perf_schema.file_events \
--collect.perf_schema.eventswaits \
--collect.perf_schema.indexiowaits \
--collect.perf_schema.tableiowaits \
--collect.slave_status \
--web.listen-address=0.0.0.0:9104
[Install]
WantedBy=multi-user.target
7.Enable and start the mysql exporter service
#systemctl daemon-reload
#systemctl enable mysql_exporter
#systemctl start mysql_exporter
#systemctl status mysql_exporter
8.Configure the endpoint in “Prometheus.yaml” file
# mysql exporter
- job_name: "mysqld"
metrics_path: '/metrics'
scheme: http
static_configs:
- targets: ["X.X.X.X:9104"]
9.Import dashboard from Grafana.com with ID:7362
source : https://shrihariharidas73.medium.com/unlocking-database-insights-monitoring-mysql-with-prometheus-and-grafana-ddd2c4f01929
0 comments:
Post a Comment