MySql for Grafana+Prometheus system monitoring

Abstract: The architecture of grafana and prometheus has been installed and configured before, see: Grafana+Prometheus builds a comprehensive three-dimensional monitoring system MySql The status and importance of installing MySql is self-evident. As an open source product, it is deeply loved by small and medium-sized enterprises and Internet companies. So here we also need to monitor it accordingly.

Architecture
1

Grafana and prometheus have been installed and configured before, see: Grafana+Prometheus builds a comprehensive three-dimensional monitoring system

MySql The status and importance of installing
MySql is self-evident. As an open source product, it is deeply loved by small and medium-sized enterprises and Internet companies, so Here we also need to monitor it accordingly.

Since CentOS7 was recently replaced, MySql is reinstalled here, and by the way, it seems that there is no mysql in the yum source of CentOS7 by default. In order to solve this problem, we need to download the mysql repo source first.

List all version information:

lsb_release -a
Download mysql repo source:

wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
install mysql-community-release-el7-5. noarch.rpm package:

rpm -ivh mysql-community-release-el7-5.noarch.rpm
install mysql:

yum install mysql-server -y
Modify permissions, otherwise an error will be reported:

chown -R root:root /var/lib/mysql
Restart the mysql service:

service mysqld restart
Log in and reset the password:

## Enter directly into the mysql console
mysql -u root
mysql > use mysql;
mysql > update user set password= password('123456') where user='root';
mysql > exit;
mysqld_exporter installation
Download and unzip:

https://github.com/prometheus/mysqld_exporter/releases/download/v0.10.0/mysqld_exporter-0.10.0.linux -amd64.tar.gz

tar -xvf mysqld_exporter-0.10.0.linux-amd64.tar.gz
mysqld_exporter needs to connect to Mysql, first create a user for it and give the required permissions:

GRANT REPLICATION CLIENT, PROCESS ON . TO 'exporter' @'localhost' identified by '123456';
GRANT SELECT ON performance_schema.* TO 'exporter'@'localhost';
flush privileges;
创建.my.cnf文件 vi .my.cnf:

[client]
user=exporter
password=123456
运行mysqld_exporter:

./mysqld_exporter -config.my-cnf=".my.cnf" &
Prometheus配置
修改prometheus.yml加入MySql节点:

global:
  scrape_interval:     15s
  evaluation_interval: 15s

scrape_configs:

  - job_name: prometheus
    static_configs:
      - targets: ['localhost:9090']
        labels:
          instance: prometheus

  - job_name: linux1
    static_configs:
      - targets: ['192.168.1.120:9100']
        labels:
          instance: sys1

  - job_name: linux2
    static_configs:
      - targets: ['192.168.1.130:9100']
        labels:
          instance: sys2

  - job_name: redis1
    static_configs:
      - targets: ['192.168.1.120:9121']
        labels:
          instance: redis1

  - job_name: mysql
    static_configs:
      - targets : ['192.168.1.120:9104']
        labels:
          instance: db1
Restart Prometheus after saving, check targets:

2

Finally log in to grafana to check MySql monitoring information:

3

Reference document:
https://github.com/prometheus/mysqld_exporter

This article is the original content of the Yunqi community and cannot be reproduced without permission. If you need to reprint, please send an email to [email protected]; if you find any content suspected of plagiarism in this community, please send an email to: yqgroup@ service.aliyun.com reports and provides relevant evidence. Once verified, the community will immediately delete the allegedly infringing content.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326108079&siteId=291194637