mysql + grafana监控

 
1、首先需要增加授权
CREATE USER 'exporter'@'localhost' IDENTIFIED BY 'XXXXXXXX' WITH MAX_USER_CONNECTIONS 3;
GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO 'exporter'@'localhost';
flush privileges;
 
2、安装mysqld_exporter
tar xzvf  mysqld_exporter-0.12.1.linux-amd64.tar.gz
mv mysqld_exporter-0.12.1.linux-amd64.tar.gz  mysqld_exporter
 
3、启动
 cat start.sh
export DATA_SOURCE_NAME='root:autodgpmysql@(localhost:3306)/'
./mysqld_exporter --web.listen-address=0.0.0.0:8089 --config.my-cnf /etc/my.cnf
 
监控指标:
collect.slave_status
Collect from SHOW SLAVE STATUS (Enabled by default)
collect.slave_hosts
Collect from SHOW SLAVE HOSTS
--collect.slave_status \
 --collect.slave_hosts \
 
4、配置prometheus.yml
  - job_name: 'mysqld'
    static_configs:
    - targets: ['localhost:8089’]
 
设置报警规则
groups:
- name: GaleraAlerts
  rules:
  - 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
 
Grafana服务
http://monitor_host:3000访问Grafana网页界面(缺省的帐号/密码为admin/admin)
然后我们到Data Sources页面添加数据源
 
Granfana 导入Mysql 监控图表
监控展示
posted @ 2019-10-18 11:26  小兵07  阅读(3107)  评论(0编辑  收藏  举报