MySQL 监控 第01期:Prometheus+Grafana 监控 MySQL
Posted 悦专栏
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MySQL 监控 第01期:Prometheus+Grafana 监控 MySQL相关的知识,希望对你有一定的参考价值。
作者简介
马听,多年 DBA 实战经验,对 mysql、 Redis、ClickHouse 等数据库有一定了解,专栏《一线数据库工程师带你深入理解 MySQL》、《Redis 运维实战》作者。
1 架构图
2 实验环境介绍
被监控的 MySQL 机器:192.168.150.123(MySQL 版本:8.0.22);
Prometheus 服务器:192.168.150.253(Prometheus 版本:2.25.2);
Grafana 服务器:192.168.21.126(Grafana 版本:7.4.5);
服务器版本均为:CentOS 7.4;
防火墙、Selinux 均关闭。
3 部署 Prometheus
tar zxvf prometheus-2.25.2.linux-amd64.tar.gz -C /opt
ln -s /opt/prometheus-2.25.2.linux-amd64/ /opt/prometheus
# my global config
global:
scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
# scrape_timeout is set to the global default (10s).
# Alertmanager configuration
alerting:
alertmanagers:
static_configs:
targets:
# - alertmanager:9093
# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
# - "first_rules.yml"
# - "second_rules.yml"
# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
job_name: 'prometheus'
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
targets: ['192.168.150.253:9090']
nohup /opt/prometheus/prometheus --config.file=/opt/prometheus/prometheus.yml &
4 部署 node_exporter 组件
tar zxvf node_exporter-1.1.2.linux-amd64.tar.gz -C /opt/
创建软链接:
ln -s /opt/node_exporter-1.1.2.linux-amd64/ /opt/node_exporter
nohup /opt/node_exporter/node_exporter &
5 部署 mysqld_exporter 组件
tar zxvf mysqld_exporter-0.12.1.linux-amd64.tar.gz -C /opt
ln -s /opt/mysqld_exporter-0.12.1.linux-amd64/ /opt/mysqld_exporter
create user 'exporter'@'localhost' IDENTIFIED BY 'eXpIHB666QWE!';
GRANT SELECT, PROCESS, SUPER, REPLICATION CLIENT, RELOAD ON *.* TO 'exporter'@'localhost';
vim /opt/mysqld_exporter/mysqld_exporter.cnf
[client]
user=exporter
password=eXpIHB666QWE!
nohup /opt/mysqld_exporter/mysqld_exporter --config.my-cnf=/opt/mysqld_exporter/mysqld_exporter.cnf &
6 配置 Prometheus 获取监控数据
# my global config
global:
scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
# scrape_timeout is set to the global default (10s).
# Alertmanager configuration
alerting:
alertmanagers:
- static_configs:
- targets:
# - alertmanager:9093
# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
# - "first_rules.yml"
# - "second_rules.yml"
# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
- job_name: 'prometheus'
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ['192.168.150.253:9090']
- job_name: 'mysql-123'
static_configs:
- targets: ['192.168.150.123:9104']
- job_name: 'node-123'
static_configs:
- targets: ['192.168.150.123:9100']
pkill prometheus
nohup /opt/prometheus/prometheus --config.file=/opt/prometheus/prometheus.yml &
7 部署 Grafana
wget https://dl.grafana.com/oss/release/grafana-7.4.5-1.x86_64.rpm
yum install grafana-7.4.5-1.x86_64.rpm -y
systemctl start grafana-server.service
用户名密码都是 admin。登录后,会让我们修改密码,则按提示操作即可,当然也可以点击跳过。
这里就可以看到 Grafana 的主界面了:
8 为 Grafana 配置 Prometheus 数据源
9 Grafana 展示 Linux 的监控数据
10 Grafana 展示 MySQL 的监控数据
11 告警配置
对 Prometheus 中获取的数据进行告警配置,目前有很多方式,比如:
通过 Grafana 配置邮件告警
等等
systemctl start grafana-server.service
12 告警测试
-
A 对 A 类(A 是 Query 中定义的)指标; -
5m,now 表示从 5 分钟前到现在; -
IS ABOVE 5 定义阈值的类型和阈值。
LIKECOLUMN
悦专栏
悦专栏 ,从小白到大神的起点
以上是关于MySQL 监控 第01期:Prometheus+Grafana 监控 MySQL的主要内容,如果未能解决你的问题,请参考以下文章