8.prometheus监控--监控Mysql8.0
一、环境搭建
docker-compose安装mysql
mkdir /data/mysql -p
cd /data/mysql cat > docker-compose.yaml <<"EOF"
version: '3.1'
services:
db:
image: mysql:8.0
restart: always
container_name: mysql
environment:
TZ: Asia/Shanghai
LANG: en_US.UTF-8
MYSQL_ROOT_PASSWORD: 123456
command:
--default-authentication-plugin=mysql_native_password
--character-set-server=utf8mb4
--collation-server=utf8mb4_general_ci
--lower_case_table_names=1
--performance_schema=1
--sql-mode=""
--skip-log-bin
volumes:
#- /data/mysql/conf:/etc/mysql/conf.d #数据文件挂载
- /data/mysql/data:/var/lib/mysql #数据文件挂载
ports:
- 3306:3306
EOF
启动:
docker-compose up -d
二、监控mysql
2.1 创建监控用户
[root@test mysql]# docker exec -it mysql mysql -u root -p
Enter password:
输入密码:123456 # 创建用户:
CREATE USER 'exporter'@'%' IDENTIFIED BY 'password' WITH MAX_USER_CONNECTIONS 3;
GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO 'exporter'@'%';
flushprivileges # 验证登录
docker exec -it mysql mysql -uexporter -p
2.2 mysql_exporter安装
2.2.1 二进制安装
下载地址:https://github.com/prometheus/mysqld_exporter/releases/download/v0.15.1/mysqld_exporter-0.15.1.linux-amd64.tar.gz
# 1.下载
wget https://github.com/prometheus/mysqld_exporter/releases/download/v0.15.1/mysqld_exporter-0.15.1.linux-amd64.tar.gz
tar vxf mysqld_exporter-0.14.0.linux-amd64.tar.gz
mkdir /opt/prometheus/
mv mysqld_exporter-0.15.1.linux-amd64 /opt/prometheus/mysqld_exporter # 2.创建用户
useradd -M -s /usr/sbin/nologin prometheus # 3.创建连接数据库文件
cat >/opt/prometheus/mysqld_exporter/.mysqld_exporter.cnf << "EOF"
[client]
user=exporter
password=password
host=192.168.10.100
port=3306
EOF # 4.更改exporter 文件夹权限
chmod 600 /opt/prometheus/mysqld_exporter/.mysqld_exporter.cnf
chown prometheus:prometheus -R /opt/prometheus # 5.创建systemd服务
cat > /etc/systemd/system/mysqld_exporter.service <<"EOF"
[Unit]
Description=Prometheus MySQL Exporter
After=network.target [Service]
Type=simple
User=prometheus
Group=prometheus
Restart=always
ExecStart=/opt/prometheus/mysqld_exporter/mysqld_exporter \
--config.my-cnf=/opt/prometheus/mysqld_exporter/.mysqld_exporter.cnf \
--collect.auto_increment.columns \
--collect.info_schema.processlist \
--collect.binlog_size \
--collect.info_schema.tablestats \
--collect.info_schema.innodb_metrics \
--collect.info_schema.userstats \
--collect.info_schema.tables \
--collect.perf_schema.tablelocks \
--collect.perf_schema.indexiowaits \
--collect.perf_schema.tableiowaits \
--collect.slave_status [Install]
WantedBy=multi-user.target
EOF # 6.启动mysqld_exporter
systemctl daemon-reload
systemctl start mysqld_exporter
systemctl enable mysqld_exporter
2.2.2 docker或docker-compose安装
docker-compose运行安装
mkdir /data/mysqld_exporter -p
cd /data/mysqld_exporter cat >docker-compose.yaml<<"EOF"
version: '3.3'
services:
mysqld-exporter:
image: prom/mysqld-exporter
container_name: mysqld-exporter
restart: always
command:
- '--collect.info_schema.processlist'
- '--collect.info_schema.innodb_metrics'
- '--collect.info_schema.tablestats'
- '--collect.info_schema.tables'
- '--collect.info_schema.userstats'
- '--collect.engine_innodb_status'
- '--config.my-cnf=/my.cnf'
volumes:
- ./my.cnf:/my.cnf
ports:
- 9104:9104
EOF
创建my.cnf配置文件
cat > my.cnf << "EOF"
[client]
host=192.168.11.62
user=exporter
password=password
port=3306
EOF
启动:docker-compose up -d
2.3 参数解释
|
Name |
MySQL Version |
Description |
|
collect.auto_increment.columns |
5.1 |
从 information_schema 收集 auto_increment 列和最大值. |
|
collect.binlog_size |
5.1 |
收集所有注册的binlog文件的当前大小 |
|
collect.engine_innodb_status |
5.1 |
收集SHOW ENGINE INNODB STATUS |
|
collect.engine_tokudb_status |
5.6 |
收集SHOW ENGINE TOKUDB STATUS . |
|
collect.global_status |
5.1 |
收集SHOW GLOBAL STATUS(默认启用) |
|
collect.global_variables |
5.1 |
收集SHOW GLOBAL VARIABLES(默认启用) |
|
collect.info_schema.clientstats |
5.5 |
如果以 userstat=1 运行,设置为 true 以收集客户端统计信息 |
|
collect.info_schema.innodb_metrics |
5.6 |
从 information_schema.innodb_metrics收集指标 |
|
collect.info_schema.innodb_tablespaces |
5.7 |
从information_schema.innodb_sys_tablespaces收集指标 |
|
collect.info_schema.innodb_cmp |
5.5 |
从information_schema.innodb_cmp收集 InnoDB 压缩表指标。 |
|
collect.info_schema.innodb_cmpmem |
5.5 |
从information_schema.innodb_cmpmem缓冲池压缩指标。 |
|
collect.info_schema.processlist |
5.1 |
从 information_schema.processlist 收集线程状态计数 |
|
collect.info_schema.processlist.min_time |
5.1 |
线程必须处于要计算的每个状态的最短时间。 (默认值:0) |
|
collect.info_schema.query_response_time |
5.5 |
如果 query_response_time_stats 为 ON,则收集查询响应时间分布。 |
|
collect.info_schema.replica_host |
5.6 |
从 information_schema.replica_host_status 收集指标。 |
|
collect.info_schema.tables |
5.1 |
从information_schema.tables收集指标。 |
|
collect.info_schema.tables.databases |
5.1 |
要为其收集表统计信息的数据库列表,或为所有 |
|
collect.info_schema.tablestats |
5.1 |
如果以 userstat=1 运行,设置为 true 以收集表统计信息。 |
|
collect.info_schema.schemastats |
5.1 |
如果以 userstat=1 运行,设置为 true 以收集架构统计信息 |
|
collect.info_schema.userstats |
5.1 |
如果以 userstat=1 运行,设置为 true 以收集用户统计信息。 |
|
collect.mysql.user |
5.5 |
从 mysql.user 表中收集数据 |
|
collect.perf_schema.eventsstatements |
5.6 |
从 performance_schema.events_statements_summary_by_digest 收集指标。 |
|
collect.perf_schema.eventsstatements.digest_text_limit |
5.6 |
规范化语句文本的最大长度。 (默认值:120) |
|
collect.perf_schema.eventsstatements.limit |
5.6 |
按响应时间限制事件语句摘要的数量。 (默认值:250) |
|
collect.perf_schema.eventsstatements.timelimit |
5.6 |
以秒为单位限制“last_seen”事件语句的存在时间。 (默认值:86400) |
|
collect.perf_schema.eventsstatementssum |
5.7 |
从 performance_schema.events_statements_summary_by_digest 汇总收集指标。 |
|
collect.perf_schema.eventswaits |
5.5 |
从 performance_schema.events_waits_summary_global_by_event_name 收集指标 |
|
collect.perf_schema.file_events |
5.6 |
从 performance_schema.file_summary_by_event_name 收集指标 |
|
collect.perf_schema.file_instances |
5.5 |
从 performance_schema.file_summary_by_instance 收集指标。 |
|
collect.perf_schema.file_instances.remove_prefix |
5.5 |
删除 performance_schema.file_summary_by_instance 中的路径前缀。 |
|
collect.perf_schema.indexiowaits |
5.6 |
从 performance_schema.table_io_waits_summary_by_index_usage 收集指标。 |
|
collect.perf_schema.memory_events |
5.7 |
从 performance_schema.memory_summary_global_by_event_name 收集指标。 |
|
collect.perf_schema.memory_events.remove_prefix |
5.7 |
删除 performance_schema.memory_summary_global_by_event_name 中的仪器前缀。 |
|
collect.perf_schema.tableiowaits |
5.6 |
从 performance_schema.table_io_waits_summary_by_table 收集指标。 |
|
collect.perf_schema.tablelocks |
5.6 |
从 performance_schema.table_lock_waits_summary_by_table 收集指标。 |
|
collect.perf_schema.replication_group_members |
5.7 |
从 performance_schema.replication_group_members 收集指标。 |
|
collect.perf_schema.replication_group_member_stats |
5.7 |
从 performance_schema.replication_group_member_stats 收集指标。 |
|
collect.perf_schema.replication_applier_status_by_worker |
5.7 |
从 performance_schema.replication_applier_status_by_worker 收集指标。 |
|
collect.slave_status |
5.1 |
从 SHOW SLAVE STATUS 收集(默认启用) |
|
collect.slave_hosts |
5.1 |
从 SHOW SLAVE HOSTS 收集 |
|
collect.heartbeat |
5.1 |
从心跳收集 |
|
collect.heartbeat.database |
5.1 |
从哪里收集心跳数据的数据库。 (默认:心跳) |
|
collect.heartbeat.table |
5.1 |
从哪里收集心跳数据的表。 (默认:心跳) |
|
collect.heartbeat.utc |
5.1 |
使用 UTC 作为当前服务器的时间戳(使用 调用 )。 (默认值:假) |
2.4 Prometheus配置
配置prometheus去采集(拉取)mysql_exporter的监控样本数据
cd /data/docker-prometheus #在scrape_configs(搜刮配置):下面增加如下配置: cat >> prometheus/prometheus.yml << "EOF"
- job_name: 'mysqld_exporter'
static_configs:
- targets: ['192.168.10.100:9104']
labels:
instance: test服务器
EOF
重新加载配置并检查:
curl -X POST http://localhost:9090/-/reload
http://192.168.10.100:9104/metrics
2.5 常用监控指标
mysql_up # 服务器是否在线
mysql_global_status_uptime # 运行时长,单位 s
delta(mysql_global_status_bytes_received[1m]) # 网络接收的 bytes
delta(mysql_global_status_bytes_sent[1m]) # 网络发送的 bytes mysql_global_status_threads_connected # 当前的客户端连接数
mysql_global_variables_max_connections # 允许的最大连接数
mysql_global_status_threads_running # 正在执行命令的客户端连接数,即非 sleep 状态
delta(mysql_global_status_aborted_connects[1m]) # 客户端建立连接失败的连接数,比如登录失败
delta(mysql_global_status_aborted_clients[1m]) # 客户端连接之后,未正常关闭的连接数 delta(mysql_global_status_commands_total{command="xx"}[1m]) > 0 # 每分钟各种命令的次数
delta(mysql_global_status_handlers_total{handler="xx"}[1m]) > 0 # 每分钟各种操作的次数
delta(mysql_global_status_handlers_total{handler="commit"}[1m]) > 0 # 每分钟 commit 的次数
delta(mysql_global_status_table_locks_immediate[1m]) # 请求获取锁,且立即获得的请求数
delta(mysql_global_status_table_locks_waited[1m]) # 请求获取锁,但需要等待的请求数。该值越少越好 delta(mysql_global_status_queries[1m]) # 每分钟的查询数
delta(mysql_global_status_slow_queries[1m]) # 慢查询数。如果未启用慢查询日志,则为 0
mysql_global_status_innodb_page_size # innodb 数据页的大小,单位 bytes
mysql_global_variables_innodb_buffer_pool_size # innodb_buffer_pool 的限制体积
mysql_global_status_buffer_pool_pages{state="data"} # 包含数据的数据页数,包括洁页、脏页
mysql_global_status_buffer_pool_dirty_pages # 脏页数 锁指标
mysql_global_status_innodb_row_lock_current_waits #当前正在等待的 InnoDB 行锁数量。
mysql_global_status_innodb_row_lock_time #从服务器启动以来的总 InnoDB 行锁等待时间(以毫秒为单位)。
mysql_global_status_innodb_row_lock_time_avg #每次等待 InnoDB 行锁的平均时间(以毫秒为单位)
mysql_global_status_innodb_row_lock_time_max #单次等待 InnoDB 行锁的最长时间(以毫秒为单位)。
mysql_global_status_innodb_row_lock_waits #从服务器启动以来的总 InnoDB 行锁等待次数。
2.6 mysql触发器告警规则配置
cat >> prometheus/rules/mysqld.yml <<"EOF"
groups:
- name: MySQL
rules:
- alert: MysqlDown
expr: mysql_up == 0
for: 30s
labels:
severity: critical
annotations:
summary: "MySQL Down,实例:{{ $labels.instance }}"
description: "MySQL_exporter连不上MySQL了,当前状态为:{{ $value }}"
- alert: MysqlTooManyConnections
expr: max_over_time(mysql_global_status_threads_connected[1m]) / mysql_global_variables_max_connections * 100 > 80
for: 2m
labels:
severity: warning
annotations:
summary: "Mysql连接数过多告警,实例:{{ $labels.instance }}"
description: "MySQL连接数>80%,当前值:{{ $value }}"
- alert: MysqlHighThreadsRunning
expr: max_over_time(mysql_global_status_threads_running[1m]) > 20
for: 2m
labels:
severity: warning
annotations:
summary: "Mysql运行的线程过多,实例:{{ $labels.instance }}"
description: "Mysql运行的线程 > 20,当前运行的线程:{{ $value }}"
- alert: MysqlSlowQueries
expr: increase(mysql_global_status_slow_queries[2m]) > 0
for: 2m
labels:
severity: warning
annotations:
summary: "Mysql慢日志告警,实例:{{ $labels.instance }}"
description: "MySQL在过去2分钟有新的{{ $value }}条慢查询"
#MySQL innodb 日志写入停滞
- alert: MysqlInnodbLogWaits
expr: rate(mysql_global_status_innodb_log_waits[15m]) > 10
for: 0m
labels:
severity: warning
annotations:
summary: "MySQL innodb日志等待,实例:{{ $labels.instance }}"
description: "MySQL innodb日志写入停滞,当前值: {{ $value }}"
- alert: MysqlRestarted
expr: mysql_global_status_uptime < 60
for: 0m
labels:
severity: info
annotations:
summary: "MySQL 重启,实例:{{ $labels.instance }}"
description: "不到一分钟前,MySQL重启过" - alert: RowLockCurrentWaits
expr: mysql_global_status_innodb_row_lock_current_waits > 0
for: 1m
labels:
severity: info
annotations:
summary: "MySQL有锁等待,实例:{{ $labels.instance }}"
description: "当前有{{ $value }}个锁等待"
EOF
检查配置并加载
docker exec -it prometheus promtool check config /etc/prometheus/prometheus.yml
curl -X POST http://localhost:9090/-/reload
页面检查:
http://192.168.10.14:9090/targets?search=

http://192.168.10.14:9090/rules

http://192.168.10.14:9090/alerts?search=

2.7 grafana dashboard展示
如果没有图形显示,可以edit下监控框,将里面的参数拿到http://192.168.10.14:9090/graph中搜索看看是否有这个参数
grafana展示prometheus从mysql_exporter收集到的的数据
Top Process States和 Process States图形修改为如下:
mysql_info_schema_threads 替换成:
mysql_info_schema_processlist_threads
https://grafana.com/grafana/dashboards/20016-mysql-8-0/
id:20016
数据库表监控
https://grafana.com/grafana/dashboards/9625
注意:2个图表没有数据,是因为只支持percona server 和 mariadb
Buffer pool size of total ram图形问题
如果mysql安装在linux服务上,并且这台linux服务器也是用node_exporter对其监控。那Buffer pool size of total ram这个图形面板显示不正常,解决如下:
(mysql_global_variables_innodb_buffer_pool_size{instance="$host"} * 100) / on (instance) node_memory_MemTotal_bytes{instance="$host"}
修改为,然后在看看图形显示
(label_replace(mysql_global_variables_innodb_buffer_pool_size{instance="$host"}, "nodename", "$1", "instance", "(.*):.*") * 100) / on(nodename) (label_replace(node_memory_MemTotal_bytes, "nodename", "$1", "instance", "(.*):.*"))
8.prometheus监控--监控Mysql8.0的更多相关文章
- Prometheus 系统监控方案 一
最近一直在折腾时序类型的数据库,经过一段时间项目应用,觉得十分不错.而Prometheus又是刚刚推出不久的开源方案,中文资料较少,所以打算写一系列应用的实践过程分享一下. Prometheus 是什 ...
- 安装prometheus+grafana监控mysql redis kubernetes等
1.prometheus安装 wget https://github.com/prometheus/prometheus/releases/download/v1.5.2/prometheus-1.5 ...
- Grafana+Prometheus系统监控之webhook
概述 Webhook是一个API概念,并且变得越来越流行.我们能用事件描述的事物越多,webhook的作用范围也就越大.Webhook作为一个轻量的事件处理应用,正变得越来越有用. 准确的说webho ...
- cAdvisor+Prometheus+Grafana监控docker
cAdvisor+Prometheus+Grafana监控docker 一.cAdvisor(需要监控的主机都要安装) 官方地址:https://github.com/google/cadvisor ...
- 基于Docker+Prometheus+Grafana监控SpringBoot健康信息
在微服务体系当中,监控是必不可少的.当系统环境超过指定的阀值以后,需要提醒指定的运维人员或开发人员进行有效的防范,从而降低系统宕机的风险.在CNCF云计算平台中,Prometheus+Grafana是 ...
- 使用Prometheus+Grafana监控MySQL实践
一.介绍Prometheus Prometheus(普罗米修斯)是一套开源的监控&报警&时间序列数据库的组合,起始是由SoundCloud公司开发的.随着发展,越来越多公司和组织接受采 ...
- [转帖]Prometheus+Grafana监控Kubernetes
原博客的位置: https://blog.csdn.net/shenhonglei1234/article/details/80503353 感谢原作者 这里记录一下自己试验过程中遇到的问题: . 自 ...
- [k8s]prometheus+grafana监控node和mysql(普罗/grafana均vm安装)
https://github.com/prometheus/prometheus Architecture overview Prometheus Server Prometheus Server 负 ...
- Prometheus+Grafana监控部署实践
参考文档: Prometheus github:https://github.com/prometheus grafana github:https://github.com/grafana/graf ...
- Prometheus Operator 监控Kubernetes
Prometheus Operator 监控Kubernetes 1. Prometheus的基本架构 Prometheus是一个开源的完整监控解决方案,涵盖数据采集.查询.告警.展示整个监控流程 ...
随机推荐
- 记录--你还在使用websocket实现实时消息推送吗?
这里给大家分享我在网上总结出来的一些知识,希望对大家有所帮助 前言 在日常的开发中,我们经常能碰见服务端需要主动推送给客户端数据的业务场景,比如数据大屏的实时数据,比如消息中心的未读消息,比如聊天功能 ...
- 记录--通过Promise实现分批处理接口请求
这里给大家分享我在网上总结出来的一些知识,希望对大家有所帮助 如何通过 Promise 实现百条接口请求? 实际项目中遇到需要批量发起上百条接口请求怎么办? 最新案例代码在此!点击看看 前言 不知你项 ...
- kali 2018.2镜像安装
本文链接来源 Kali Linux 前身是著名渗透测试系统BackTrack ,是一个基于 Debian 的 Linux 发行版,包含很多安全和取证方面的相关工具.此次通过VMware虚拟机安装201 ...
- 快速上手系列:Oracle
一 简介 1.为何需要数据库?存储大量数据,方便检索和访问. 2.文件组成: 数据文件:扩展名是.DBF,用于存储数据库数据的文件,数据库表和数据文件不存在一对一对应关系 控制文件:扩展名是.CTL, ...
- Elastic实战:彻底解决spring-data-elasticsearch日期、时间类型数据读取报错问题
0. 引言在使用spring-data-elasticsearch读取es中时间类型的数据时出现了日期转换报错,不少初学者会在这里困惑很久,所以今天我们专门来解读该问题的几种解决方案. 1. 问题分析 ...
- Docker网络模型以及容器通信
本篇接着上篇:[Docker0网络及原理探究],继续深入探究容器网络通信原理,通过学习Docker网路驱动模型,更好地解决容器间的通信问题 1.Docker的网络驱动模型 1.1.Docker的网络驱 ...
- 什么是GRAY色彩空间
GRAY色彩空间通常指的是灰度图像,灰度图像是一种每个像素都是从黑到白,被处理为256个灰度级别的单色图像.这256个灰度级别分别用区间[0,255]中的数值表示,其中,"0"表示 ...
- OpenCV 方法及应用速查表
序 号 方 法 说 明 技术分类 1 image = cv2.imread(filename, flags) 读取图像 基本操作 2 cv2.imshow(winname, mat) 显 ...
- #Kruskal重构树,主席树,倍增#洛谷 4197 Peaks
题目传送门 分析 首先第\(k\)大一般都是主席树 问题是困难值的限制有点束手无措 又是\(\text{Kruskal重构树}\) 将困难值为边权跑最小生成树,重新建树,实际上让困难值跳到尽量大的位置 ...
- HttpOnly的笔记
HttpOnly是什么 简单的说: HttpOnly是Cookie的属性: Web服务器通过为Cookie设置这个属性,告诉浏览器应当避免页面端的脚本访问对应Cookie的值,保证被Cookie承载的 ...