mysqld_exporter监控mysql信息
mysqld_exporter监控mysql信息
一、背景
使用 mysqld_exporter 来抓取 mysql的一些指标信息。
二、prometheus接入mysqld_exporter
1、安装mysqld_exporter
# 下载 mysqld_exporter
wget https://github.com/prometheus/mysqld_exporter/releases/download/v0.12.1/mysqld_exporter-0.12.1.darwin-amd64.tar.gz
# 解压 并 重命名
tar -zxvf mysqld_exporter-0.12.1.darwin-amd64.tar.gz
mv mysqld_exporter-0.12.1.darwin-amd64 mysqld_exporter

2、创建mysqld_exporter用户并授权
CREATE USER 'mysqld_exporter'@'localhost' IDENTIFIED BY 'mysqldExporter1993' WITH MAX_USER_CONNECTIONS 3;
GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO 'mysqld_exporter'@'localhost';
注意:
在创建用户的时候,推荐执行 MAX_USER_CONNECTIONS参数,避免我们监控使用过多的数据库连接数,导致数据库压力过大。
3、创建 my.cnf 配置文件
在和mysqld_exporter文件同级的文件夹中创建my.cnf文件,文件内容如下。
[client]
user=mysqld_exporter
password=mysqldExporter1993
host=localhost
port=3306
4、启动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 &
参数解释:
| 参数 | 解释 |
|---|---|
| –config.config.my-cnf | 指定配置文件的路径 |
| –web.listen-address | 指定监听的地址,端口 |
| –log.level | 指定日志级别 |
5、查看抓取的mysql指标信息
http://localhost:9088/metrics

6、接入到prometheus中
scrape_configs:
- job_name: 'mysqld-exporter'
static_configs:
- targets: ['localhost:9088']
labels:
nodename: 'mysql'

三、部分告警指标
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
参考连接:https://github.com/prometheus/mysqld_exporter/blob/master/mysqld-mixin/alerts/galera.yaml
四、参考链接
1、mysqld_exporter的github地址
2、mysql的部分告警编写
mysqld_exporter监控mysql信息的更多相关文章
- Grafan+Prometheus 监控 MySQL
架构图 环境 IP 环境 需装软件 192.168.0.237 mysql-5.7.20 node_exporter-0.15.2.linux-amd64.tar.gz mysqld_exporter ...
- 使用Prometheus+Grafana监控MySQL实践
一.介绍Prometheus Prometheus(普罗米修斯)是一套开源的监控&报警&时间序列数据库的组合,起始是由SoundCloud公司开发的.随着发展,越来越多公司和组织接受采 ...
- 采用prometheus 监控mysql
1. prometheus 是什么 开源的系统监控和报警工具,监控项目的流量.内存量.负载量等实时数据. 它通过直接或短时jobs中介收集监控数据,在本地存储所有收集到的数据,并且通过定义好的rule ...
- Grafana+Prometheus 监控 MySQL
转自:Grafana+Prometheus 监控 MySQL 架构图 环境 IP 环境 需装软件 192.168.0.237 mysql-5.7.20 node_exporter-0.15.2.lin ...
- Prometheus 监控Mysql服务器及Grafana可视化
Prometheus 监控Mysql服务器及Grafana可视化. mysql_exporter:用于收集MySQL性能信息. 使用版本 mysqld_exporter 0.11.0 官方地址 使用文 ...
- Prometheus 监控MySQL
目录 0.简介 1.mysql_exporter部署 2.mysql报警规则 0.简介 文中主要监控MySQL/MySQL主从信息 版本:mysql-5.7,mysql_exporter-0.12.1 ...
- mysqld_exporter的源码分析和定制化(单个mysqld_exporter监控多个数据库实例)
mysqld_exporter是prometheus官方提供的用于监控mysql运行状态的exporter.其相关信息可以参考:https://github.com/prometheus/mysqld ...
- 【DB宝41】监控利器PMM的使用--监控MySQL、PG、MongoDB、ProxySQL等
目录 一.PMM简介 二.安装使用 三.监控MySQL数据库 MySQL慢查询分析 四.监控PG数据库 五.监控MongoDB数据库 六.监控ProxySQL中间件 一.PMM简介 之前发布过一篇Pr ...
- 【Prometheus+Grafana系列】监控MySQL服务
前言 前面的一篇文章已经介绍了 docker-compose 搭建 Prometheus + Grafana 服务.当时实现了监控服务器指标数据,是通过 node_exporter.Prometheu ...
随机推荐
- Element UI:级联选择器Cascader_动态加载_多级请求不同接口(已知第一级调取第二级)
ELEMENT UI_CASCADER 使用过饿了么级联动态加载的小伙伴应该都知道,lazyLoad本身是一个无差别返回渲染结点的函数. 当我们存在一个需求:已知级联选择器的第一级结点,现在需要通过第 ...
- ActiveMQ和消息中间件概念
一.概念
- jdbcTemplate快速入门
一. c3p0和dbcp区别 二.导包 hibernate通过映射自动创建表: 三.代码实现
- JAVA安全基础之代理模式(一)
JAVA安全基础之代理模式(一) 代理模式是java的一种很常用的设计模式,理解代理模式,在我们进行java代码审计时候是非常有帮助的. 静态代理 代理,或者称为 Proxy ,简单理解就是事情我不用 ...
- JavaScript中的async/await详解
1.前言 async函数,也就是我们常说的async/await,是在ES2017(ES8)引入的新特性,主要目的是为了简化使用基于Promise的API时所需的语法.async和await关键字 ...
- Collections集合工具类和可变参数
Collections常用的API: public static <T> boolean addAll(Collection<? super T> c, T... elemen ...
- P1088 [NOIP2004 普及组] 火星人
题目描述 人类终于登上了火星的土地并且见到了神秘的火星人.人类和火星人都无法理解对方的语言,但是我们的科学家发明了一种用数字交流的方法.这种交流方法是这样的,首先,火星人把一个非常大的数字告诉人类科学 ...
- PHP 相对路径转换为绝对路径 realpath
* 相对路径 -> 绝对路径 realpath <?php /** * @param string $in_rel: relative directory * @param string ...
- requests接口自动化-pytest框架
pytest框架规则 测试文件以test_开头或者以_test结尾 测试类以Test开头,并且不能带有init方法 测试函数以test_开头 断言使用assert pytest框架运行用例 运行单个文 ...
- 『Python』进程同步
1. Lock(互斥锁) 是可用的最低级的同步指令.Lock处于锁定状态时,不被其他的线程拥有. from multiprocessing import Process, Value, Lock de ...