网站架设建设,苏州集团网站建设,阿里企业邮箱怎么注册,WordPress评论加入ip一、 介绍
Prometheus 是一种开源的监控系统和时序数据库#xff0c;旨在收集和处理大量数据并提供可视化、监控警报等功能。它支持多种语言、多种部署方式#xff0c;并且非常灵活#xff0c;而且社区支持非常活跃#xff0c;为用户提供了很多优秀的解决方案。 MySQL 是一…一、 介绍
Prometheus 是一种开源的监控系统和时序数据库旨在收集和处理大量数据并提供可视化、监控警报等功能。它支持多种语言、多种部署方式并且非常灵活而且社区支持非常活跃为用户提供了很多优秀的解决方案。 MySQL 是一种流行的关系型数据库管理系统用于存储和管理结构化数据。MySQL 数据库对于 web 应用程序、企业级应用程序和数据仓库等应用场景都非常适用。
Prometheus 提供了许多适用于 MySQL 监控的插件和可视化界面让用户可以方便地监控 MySQL 数据库的健康状态、性能指标以及异常情况。下面是使用 Prometheus 进行 MySQL 性能监控的步骤
二、mysql 指标采集器安装与使用
步骤1安装和配置 Prometheus
首先需要安装和配置 Prometheus可以参考官方文档进行操作。
步骤2安装 mysqld_exporter
mysqld_exporter 是一个用于采集 MySQL 数据库的指标信息的工具。可以通过以下命令进行下载和安装
wget https://github.com/prometheus/mysqld_exporter/releases/download/v0.12.1/mysqld_exporter-0.12.1.linux-amd64.tar.gz
tar -zxvf mysqld_exporter-0.12.1.linux-amd64.tar.gz
cd mysqld_exporter-0.12.1.linux-amd64/步骤3配置 mysqld_exporter
打开 mysqld_exporter 的主配置文件 my.cnf根据实际需求修改其中的配置项。例如如果要指定 MySQL 数据库的用户名和密码则需要在 my.cnf 文件中添加以下内容
[client]
userUSERNAME
passwordPASSWORD步骤4启动 mysqld_exporter
启动 mysqld_exporter 之前最好先执行一遍检查
./mysqld_exporter --config.my-cnfmy.cnf然后再执行启动命令
./mysqld_exporter --config.my-cnfmy.cnf 步骤5配置 Prometheus 抓取配置
编辑 prometheus.yml 文件添加以下内容
scrape_configs:- job_name: mysqlscrape_interval: 1mstatic_configs:- targets: [YOUR_MYSQL_SERVER_IP:9104]步骤6重启 Prometheus 和 mysqld_exporter
重新加载 prometheus.yml 文件
kill -HUP prometheus_PID重新启动 mysqld_exporter
ps aux | grep mysqld_exporter
kill -9 mysqld_exporter_PID
./mysqld_exporter --config.my-cnfmy.cnf 步骤7可视化监控数据
使用 Grafana 等数据可视化工具将 MySQL 的监控指标展示分析出来。例如可以展示 CPU 使用率、磁盘 I/O 速度、网络连接数、线程数等各种监控数据。
三、prometheus 中 Mysql 采用监控指标
指标名prometheus 指标mysql 获取指标方式当前连接数mysql_global_status_threads_connected登录 mysql执行 SQL \n SHOW GLOBAL STATUS LIKE ‘threads_connected’;最大连接数mysql_global_variables_max_connections登录 mysql执行 SQL \n SHOW VARIABLES LIKE ‘max_connections’;MYSQL 缓存命中率mysql_global_status_qcache_hits 和 mysql_global_status_commands_total{command~“select”}登录 mysql执行 SQL \n SHOW GLOBAL STATUS \n LIKE ‘Qcache_hits’; \n SHOW GLOBAL STATUS LIKE ‘Com_select’;InnoDB 缓存命中率mysql_global_status_innodb_buffer_pool_reads \n mysql_global_status_innodb_buffer_pool_read_requests登录 mysql执行 SQL \n SHOW GLOBAL STATUS LIKE ‘Innodb_buffer_pool_reads%’; \n SHOW GLOBAL STATUS LIKE ‘Innodb_buffer_pool_read_request%’;MYISAM 缓存命中率mysql_global_status_key_reads 和 mysql_global_status_key_read_requests登录 mysql执行 SQL \n SHOW GLOBAL STATUS LIKE ‘Key_reads%’; \n SHOW GLOBAL STATUS LIKE ‘Key_read_requests%’;CPU 使用率container_cpu_usage_seconds_total 和 kube_pod_container_resource_limitsk8s 集群 master 机器执行 \n kubectl top pod -n coding | grep mariadb-primary核对 use 是否一致 \n kubectl get pod mariadb-primary-0 -n coding -ojsonpath‘{.spec.containers[*].resources.limits.memory}’ 核对 limit 是否一致内存占用container_memory_usage_bytesk8s 集群 master 机器执行 \n kubectl top pod -n coding | grep mariadb-primary核对 use 是否一致内存利用率container_memory_usage_bytes 和 kube_pod_container_resource_limits{resource“memory”,unit“byte”}k8s 集群 master 机器执行 \n kubectl top pod -n coding | grep mariadb-primary核对 use 是否一致 \n kubectl get pod mariadb-primary-0 -n coding -ojsonpath‘{.spec.containers[*].resources.limits.cpu}’ 核对 limit 是否一致发送数据量mysql_global_status_bytes_sent登录 mysql执行 SQL \n SHOW GLOBAL STATUS LIKE ‘Bytes_received’;接受数据量mysql_global_status_bytes_received登录 mysql执行 SQL \n SHOW GLOBAL STATUS LIKE ‘Bytes_sent’;所有SQL语句无论其是否执行成功mysql_global_status_queries登录 mysql执行 SQL \n SHOW GLOBAL STATUS LIKE ‘Queries’;慢查询数mysql_global_status_slow_queries登录 mysql执行 SQL \n SHOW GLOBAL STATUS LIKE ‘Slow_queries’;全表查询数mysql_global_status_select_scan登录 mysql执行 SQL \n SHOW GLOBAL STATUS LIKE ‘Select_scan’;执行 DELETE 查询的次数mysql_global_status_commands_total{command~“delete”}登录 mysql执行 SQL \n SHOW GLOBAL STATUS LIKE ‘Com_delete’;执行 INSERT 查询的次数mysql_global_status_commands_total{command~“insert”}登录 mysql执行 SQL \n SHOW GLOBAL STATUS LIKE ‘Com_insert’;执行 UPDATE 查询的次数mysql_global_status_commands_total{command~“update”}登录 mysql执行 SQL \n SHOW GLOBAL STATUS LIKE ‘Com_update’;执行 REPLACE 查询的次数mysql_global_status_commands_total{command~“replace”}登录 mysql执行 SQL \n SHOW GLOBAL STATUS LIKE ‘Com_replace’;执行 SELECT 查询的次数mysql_global_status_commands_total{command~“select”}登录 mysql执行 SQL \n SHOW GLOBAL STATUS LIKE ‘Com_select’;现场运行数mysql_global_status_threads_running登录 mysql执行 SQL \n SHOW STATUS LIKE ‘Threads_running’;线程创建数mysql_global_status_threads_created登录 mysql执行 SQL \n SHOW STATUS LIKE ‘Threads_created’;InnoDB 磁盘写次数 \n 单位: 次/smysql_global_status_innodb_data_writes登录 mysql执行 SQL \n SHOW GLOBAL STATUS LIKE ‘innodb_data_writes’; \n 或者 \n SHOW ENGINE INNODB STATUS; 查看 OS file writes 一行InnoDB 磁盘读次数 \n 单位: 次/smysql_global_status_innodb_data_reads登录 mysql执行 SQL \n SHOW GLOBAL STATUS LIKE ‘innodb_data_reads’; \n 或者 \n SHOW ENGINE INNODB STATUS; 查看 OS file reads 一行InnoDB 磁盘 fsync 次数 \n 单位: 次/smysql_global_status_innodb_data_fsyncs登录 mysql执行 SQL \n SHOW GLOBAL STATUS LIKE ‘innodb_data_fsyncs’; \n 或者 \n SHOW ENGINE INNODB STATUS; 查看 OS fsyncs 一行InnoDB 读取的数据量 \n 单位: 字节/smysql_global_status_innodb_data_reads登录 mysql执行 SQL \n SHOW GLOBAL STATUS LIKE ‘Innodb_data_reads’;InnoDB 写入的数据量 \n 单位: 字节/smysql_global_status_innodb_data_writes登录 mysql执行 SQL \n SHOW GLOBAL STATUS LIKE ‘Innodb_data_written’;InnoDB行删除量mysql_global_status_innodb_row_ops_total{operation“deleted”}登录 mysql执行 SQL \n SHOW GLOBAL STATUS LIKE ‘Innodb_rows_deleted’;InnoDB行插入量mysql_global_status_innodb_row_ops_total{operation“inserted”}登录 mysql执行 SQL \n SHOW GLOBAL STATUS LIKE ‘Innodb_rows_inserted’;InnoDB行读取量mysql_global_status_innodb_row_ops_total{operation“read”}登录 mysql执行 SQL \n SHOW GLOBAL STATUS LIKE ‘Innodb_rows_read’;InnoDB行更新量mysql_global_status_innodb_row_ops_total{operation“updated”}登录 mysql执行 SQL \n SHOW GLOBAL STATUS LIKE ‘Innodb_rows_updated’;