The background,

Mysqld_exporter = mysqLD_exporter;

2, Prometheus access mysqLD_exporter

Install mysqLD_exporter

# download mysqld_exporterWget HTTP: / / https://github.com/prometheus/mysqld_exporter/releases/download/v0.12.1/mysqld_exporter-0.12.1.darwin-amd64.tar.gzUnzip and renameTar -zxvf mysqLD_bull-0.0.0.97. Darwiny-amd640.tar. gz MV mysqLD_bull-0.0.97Copy the code

Create mysqLD_user and authorize it

CREATE USER 'mysqld_exporter'@'localhost' IDENTIFIED BY 'mysqldExporter1993' WITH MAX_USER_CONNECTIONS 3;
GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO 'mysqld_exporter'@'localhost';
Copy the code

Note: when creating a user, it is recommended that the MAX_USER_CONNECTIONS parameter be executed to avoid overloading the database by monitoring the number of database connections.

3. Create the my.cnf configuration file

Create a my.cnf file in the same folder as the mysqLD_exporter file with the following contents.

[client]
user=mysqld_exporter
password=mysqldExporter1993
host=localhost
port=3306
Copy the code

Start mysqLD_exporter

nohup /Users/huan/soft/prometheus/mysqld_exporter/mysqld_exporter \
--config.my-cnf="/Users/huan/soft/prometheus/mysqld_exporter/my.cnf" \
--web.listen-address="0.0.0.0:9088" \
--log.level=debug \
> logs/mysqld_exporter.out 2>&1 &
Copy the code

Parameter Description:

parameter explain
–config.config.my-cnf Specify the path to the configuration file
–web.listen-address Specify the address and port to listen on
–log.level Specifying a log Level
Mysql > select * from mysql
http://localhost:9088/metrics

6. Connect to Prometheus

scrape_configs:
  - job_name: 'mysqld-exporter'
    static_configs:
    - targets: ['localhost:9088']
      labels:
        nodename: 'mysql'
Copy the code

3. Some alarm indicators

groups:
- name: GaleraAlerts
  rules:
  - alert: MySQLGaleraNotReady
    expr: mysql_global_status_wsrep_ready ! = 1
    for: 5m
    labels:
      severity: warning
    annotations:
      description: '{{$labels.job}} on {{$labels.instance}} is not ready.'
      summary: Galera cluster node not ready
  - alert: MySQLGaleraOutOfSync
    expr: (mysql_global_status_wsrep_local_state ! = 4 and mysql_global_variables_wsrep_desync
      = = 0)
    for: 5m
    labels:
      severity: warning
    annotations:
      description: '{{$labels.job}} on {{$labels.instance}} is not in sync ({{$value}}! = 4). '
      summary: Galera cluster node out of sync
  - alert: MySQLGaleraDonorFallingBehind
    expr: (mysql_global_status_wsrep_local_state = = 2 and mysql_global_status_wsrep_local_recv_queue
      > 100)
    for: 5m
    labels:
      severity: warning
    annotations:
      description: '{{$labels.job}} on {{$labels.instance}} is a donor (hotbackup)
        and is falling behind (queue size {{$value}}). '
      summary: xtradb cluster donor node falling behind
  - alert: MySQLReplicationNotRunning
    expr: mysql_slave_status_slave_io_running = = 0 or mysql_slave_status_slave_sql_running
      = = 0
    for: 2m
    labels:
      severity: critical
    annotations:
      description: Slave replication (IO or SQL) has been down for more than 2 minutes.
      summary: Slave replication is not running
  - alert: MySQLReplicationLag
    expr: (instance:mysql_slave_lag_seconds > 30) and on(instance) (predict_linear(instance:mysql_slave_lag_seconds[5m],
      60 * 2) > 0)
    for: 1m
    labels:
      severity: critical
    annotations:
      description: The mysql slave replication has fallen behind and is not recovering
      summary: MySQL slave replication is lagging
  - alert: MySQLReplicationLag
    expr: (instance:mysql_heartbeat_lag_seconds > 30) and on(instance) (predict_linear(instance:mysql_heartbeat_lag_seconds[5m],
      60 * 2) > 0)
    for: 1m
    labels:
      severity: critical
    annotations:
      description: The mysql slave replication has fallen behind and is not recovering
      summary: MySQL slave replication is lagging
  - alert: MySQLInnoDBLogWaits
    expr: rate(mysql_global_status_innodb_log_waits[15m]) > 10
    labels:
      severity: warning
    annotations:
      description: The innodb logs are waiting for disk at a rate of {{$value}} /
        second
      summary: MySQL innodb log writes stalling
Copy the code

Reference link: github.com/prometheus/…

4. Reference links

Mysqld_exporter: github address