普罗米修斯]监控 MySQL 和可视化
目录
一、概述
1.1下载解压mysqld_exporter
1.2创建MySQL授权用户
1.3配置my.cnf
1.4启动mysqld_exporter
1.5prometheus配置修改
二、Grafana展示
【Prometheus】概念和工作原理介绍_prometheus工作原理
【Prometheus】k8s集群部署node-exporter
【prometheus】k8s集群部署prometheus server-****博客
【prometheus】k8s集群部署Grafana安装和配置
【prometheus】k8s集群部署AlertManager实现邮件和钉钉告警-****博客
一、概述
mysqld_exporter 是一个用于监控 MySQL 服务器的开源工具,它是由 Prometheus 社区维护的一个官方 Exporter。该工具通过连接到 MySQL 服务器并执行各种查询来收集关于 MySQL 服务器性能和状态的指标,并将这些指标暴露给 Prometheus 监控系统。
以下是 mysqld_exporter 的一些主要特点和功能:
- 指标收集: mysqld_exporter 通过执行 SQL 查询来收集关于 MySQL 服务器的各种指标,包括查询性能、连接状态、InnoDB 状态、复制状态等。
- Prometheus 兼容: mysqld_exporter 输出的指标符合 Prometheus 的指标格式,并且可以直接由 Prometheus 进行收集和存储。
- 灵活的配置: 用户可以通过配置文件或命令行参数来配置 mysqld_exporter 的行为,包括指定要监控的 MySQL 实例、连接参数、指标的收集频率等。
- 安全性: mysqld_exporter 支持通过 TLS/SSL 进行安全连接,以确保监控数据的机密性和完整性。
- 多版本支持: mysqld_exporter 可以与多个 MySQL 版本兼容,并且可以通过配置选择性地启用或禁用特定版本的指标收集。
- 自定义查询: 用户可以通过配置文件自定义要执行的 SQL 查询,以收集特定于其环境的自定义指标。
- 易于部署: mysqld_exporter 可以作为一个独立的二进制文件部署,并且支持多种部署方式,包括 Docker 容器、系统服务等。
总的来说,mysqld_exporter 是一个功能强大且易于使用的工具,可以帮助用户监控和诊断其 MySQL 服务器的性能和健康状态,从而及时发现和解决潜在的问题。
官网:Download | Prometheus
MySQLExpoter: GitHub - prometheus/mysqld_exporter: Exporter for MySQL server metrics
【Linux】Centos7 shell实现MySQL5.7 tar 一键安装_shell一键安装mysql5.7.44-****博客
1.1下载解压mysqld_exporter
wget --no-check-certificate https://github.com/prometheus/mysqld_exporter/releases/download/v0.15.1/mysqld_exporter-0.15.1.linux-amd64.tar.gz
cd mysqld_exporter-0.15.1.linux-amd64
cp -ar mysqld_exporter /usr/local/bin/
chmod +x /usr/local/bin/mysqld_exporter
1.2创建MySQL授权用户
# 创建数据库用户。
CREATE USER 'mysql_exporter'@'192.168.2.139' IDENTIFIED BY 'Abcdef123!.';
# 对mysql_exporter用户授权
GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO 'mysql_exporter'@'192.168.2.139';
1.3配置my.cnf
创建mysql配置文件、运行时可免密码连接数据库
cd mysqld_exporter-0.15.1.linux-amd64
cat > my.cnf << EOF
[client]
host=192.168.2.211
port=3306
user=mysql_exporter
password=Abcdef123!.
[client.servers]
host=192.168.2.211
port=3306
user=mysql_exporter
password=Abcdef123!.
EOF
1.4启动mysqld_exporter
直接命令行启动mysql_exporter客户端
nohup ./mysqld_exporter --config.my-cnf=./my.cnf &
也可以注册为服务
cat <<EOF>> /usr/lib/systemd/system/mysqld-exporter.service
[Unit]
Description=mysqld_exporter
[Service]
User=root
ExecStart=/root/prome/mysqld_exporter-0.15.1.linux-amd64/mysqld_exporter --config.my-cnf /root/prome/mysqld_exporter-0.15.1.linux-amd64/my.cnf --web.listen-address=0.0.0.0:9104 \
--collect.slave_status \
--collect.binlog_size \
--collect.info_schema.processlist \
--collect.info_schema.innodb_metrics \
--collect.engine_innodb_status \
--collect.perf_schema.file_events \
--collect.perf_schema.replication_group_member_stats
Restart=on-failure
[Install]
WantedBy=multi-user.targe
EOF
1.5prometheus配置修改
修改prometheus-cfg.yaml文件,添加如下
- job_name: 'mysql'
static_configs:
- targets: ['192.168.124.16:9104']
kubectl apply -f prometheus-alertmanager-cfg.yaml
kubectl delete -f prometheus-deploy.yaml
kubectl apply -f prometheus-deploy.yaml
curl -XPOST localhost:9090/-/reload
登录 promethetus 可以看到采集到了
二、Grafana展示
官网模板地址Dashboards | Grafana Labs
mysql-overview_rev5.json
导入模板
选择“Import Json File”
导入模板后,选择import
展示成功
参考链接:
mysqld_exporter部署-****博客
推荐阅读
-
普罗米修斯]监控 MySQL 和可视化
-
智能消防:如何构建基于视频监控和智能分析技术的消防可视化风险预警平台?
-
利用 Monit 和电子邮件警报监控 MySQL 并自动重启
-
搭建性能测试监控平台:用JMeter、Grafana和Influxdb实现数据可视化
-
玩转Java底层:JMX详解 - jconsole与自定义MBean监控工具的实际应用与区别" 在日常JVM调优中,我们熟知的jconsole工具通过JMX包装的bean以图形化形式展示管理数据,而像jstat和jmap这类内建监控工具则由JVM直接支持。本文将以jconsole为例,深入讲解其实质——基于JMX的MBean功能,包括可视化界面上的bean属性查看和操作调用。 MBeans在jconsole中的体现是那些可观察的组件属性和方法,如上图所示,通过名为"Verbose"的属性能看到其值为false,同时还能直接操作该bean的方法,例如"closeJerryMBean"。 尽管jconsole给我们提供了直观的可视化界面,但请注意,这里的MBean并非固定不变,开发者可根据JMX提供的接口将自己的自定义bean展示到jconsole。以下步骤展示了如何创建并注册一个名为"StudyJavaMBean"的自定义MBean: 1. 首先定义接口`StudyJavaMBean`,接口需遵循MBean规范,即后缀为"MBean"且包含getter方法代表属性,如`getApplicationName`,和无返回值的setter方法代表操作,如`closeJerryMBean`。 ```java public interface StudyJavaMBean { String getApplicationName(); void closeJerryMBean(); } ``` 2. 编写接口的实现类`StudyJavaMBeanImpl`,实现接口中的方法: ```java public class StudyJavaMBeanImpl implements StudyJavaMBean { @Override public String getApplicationName() { return "每天学Java"; } @Override public void closeJerryMBean() { System.out.println("关闭Jerry应用"); } } ``` 3. 在代码中注册自定义MBean,涉及的关键步骤包括: - 获取平台MBeanServer - 定义ObjectName,指定唯一的MBean标识符 - 注册MBean到服务器 - 启动RMI连接器服务,以便jconsole能够访问 ```java public void registerMBean() throws Exception { // ... 具体实现省略 ... } ``` 实际运行注册后的MBean,您将在jconsole中发现并查看自定义bean的属性和调用相关方法。然而,这种方式相较于传统的属性/日志查看和HTTP接口,实用性相对有限,可能存在潜在的安全风险。但不可否认的是,JMX及其MBean机制对于获取操作系统信息、内存状态等关键性能指标仍然具有重要价值。例如: 1. **获取操作系统信息**:通过JMX MBean,可以直接获取到诸如CPU使用率、操作系统版本等系统级信息,这对于资源管理和优化工作具有显著帮助。
-
用Flask、Mysql和Echarts打造豆瓣电影Top250数据分析系统——可视化实现
-
MySQL监控和性能分析的工具详解(转载)