一、背景

使用 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信息的更多相关文章

  1. Grafan+Prometheus 监控 MySQL

    架构图 环境 IP 环境 需装软件 192.168.0.237 mysql-5.7.20 node_exporter-0.15.2.linux-amd64.tar.gz mysqld_exporter ...

  2. 使用Prometheus+Grafana监控MySQL实践

    一.介绍Prometheus Prometheus(普罗米修斯)是一套开源的监控&报警&时间序列数据库的组合,起始是由SoundCloud公司开发的.随着发展,越来越多公司和组织接受采 ...

  3. 采用prometheus 监控mysql

    1. prometheus 是什么 开源的系统监控和报警工具,监控项目的流量.内存量.负载量等实时数据. 它通过直接或短时jobs中介收集监控数据,在本地存储所有收集到的数据,并且通过定义好的rule ...

  4. Grafana+Prometheus 监控 MySQL

    转自:Grafana+Prometheus 监控 MySQL 架构图 环境 IP 环境 需装软件 192.168.0.237 mysql-5.7.20 node_exporter-0.15.2.lin ...

  5. Prometheus 监控Mysql服务器及Grafana可视化

    Prometheus 监控Mysql服务器及Grafana可视化. mysql_exporter:用于收集MySQL性能信息. 使用版本 mysqld_exporter 0.11.0 官方地址 使用文 ...

  6. Prometheus 监控MySQL

    目录 0.简介 1.mysql_exporter部署 2.mysql报警规则 0.简介 文中主要监控MySQL/MySQL主从信息 版本:mysql-5.7,mysql_exporter-0.12.1 ...

  7. mysqld_exporter的源码分析和定制化(单个mysqld_exporter监控多个数据库实例)

    mysqld_exporter是prometheus官方提供的用于监控mysql运行状态的exporter.其相关信息可以参考:https://github.com/prometheus/mysqld ...

  8. 【DB宝41】监控利器PMM的使用--监控MySQL、PG、MongoDB、ProxySQL等

    目录 一.PMM简介 二.安装使用 三.监控MySQL数据库 MySQL慢查询分析 四.监控PG数据库 五.监控MongoDB数据库 六.监控ProxySQL中间件 一.PMM简介 之前发布过一篇Pr ...

  9. 【Prometheus+Grafana系列】监控MySQL服务

    前言 前面的一篇文章已经介绍了 docker-compose 搭建 Prometheus + Grafana 服务.当时实现了监控服务器指标数据,是通过 node_exporter.Prometheu ...

随机推荐

  1. Java关键字-static汇总

    1.静态变量(被static修饰的成员变量) 1-静态变量 运行时,Java虚拟机只为静态变量分配一次内存(加载类的过程中完成静态变量的内存分配) 类的内部可以在任何方法内直接访问静态变量 其他类中可 ...

  2. 远程线程注入DLL

    远程线程注入 0x00 前言 远程线程注入是一种经典的DLL注入技术.其实就是指一个新进程中另一个进程中创建线程的技术. 0x01 介绍 1.远程线程注入原理 画了一个图大致理解了下远程线程注入dll ...

  3. weblogic漏洞分析之CVE-2021-2394

    weblogic漏洞分析之CVE-2021-2394 简介 Oracle官方发布了2021年7月份安全更新通告,通告中披露了WebLogic组件存在高危漏洞,攻击者可以在未授权的情况下通过IIOP.T ...

  4. C# 多线程编程之锁的使用【互斥锁(lock)和读写锁(ReadWriteLock)】

    多线程编程之锁的使用[互斥锁(lock)和读写锁(ReadWriteLock)] http://blog.csdn.net/sqqyq/article/details/18651335 多线程程序写日 ...

  5. AtCoder Regular Contest 069 D - Menagerie 枚举起点 模拟递推

    arc069.contest.atcoder.jp/tasks/arc069_b 题意:一堆不明身份的动物排成一圈,身份可能是羊或狼,羊一定说实话,狼一定说假话.大家各自报自己的两边是同类还是不同类, ...

  6. git介绍-常用操作(一)

    Table of Contents 1  系列文章 2  git说明 3  git常用命令 3.1  基本操作 3.2  远程操作 4  查看git的配置 4.1  查看已配置项 4.2  其他配置 ...

  7. 基于swoole框架hyperf开发的纯API接口化的后台RBAC管理工具hyperfly@v1.0.0发布

    hyperfly@v1.0.0发布 本文地址http://yangjianyong.cn/?p=323转载无需经过作者本人授权 github地址:https://github.com/vankour/ ...

  8. PHP的加密伪随机数生成器的使用

    今天我们来介绍的是 PHP 中的加密伪随机数生成器(CSPRNG 扩展).随机数的生成其实非常简单,使用 rand() 或者 mt_rand() 函数就可以了,但是我们今天说的这个则是使用了更复杂算法 ...

  9. CentOS下安装libmcrypt失败

    libmcrypt是什么?? 是加密算法扩展库---支持DES, 3DES, RIJNDAEL, Twofish, IDEA, GOST, CAST-256, ARCFOUR, SERPENT, SA ...

  10. Consul+Ocelot+Polly在.NetCore中使用(.NET5)-Ocelot+Polly缓存、限流、熔断、降级

    相关文章 Consul+Ocelot+Polly在.NetCore中使用(.NET5)-Consul服务注册,服务发现 Consul+Ocelot+Polly在.NetCore中使用(.NET5)-网 ...