如何监控MySQL

如何监控MySQL,第1张

首先介绍下 pt-stalk,它是 Percona-Toolkit 工具包中的一个工具,说起 PT 工具包大家都不陌生,平时常用的 pt-query-digest、 pt-online-schema-change 等工具都是出自于这个工具包,这里就不多介绍了。

pt-stalk 的主要功能是在出现问题时收集 OS 及 MySQL 的诊断信息,这其中包括:

1. OS 层面的 CPU、IO、内存、磁盘、网络等信息;

2. MySQL 层面的行锁等待、会话连接、主从复制,状态参数等信息。

而且 pt-stalk 是一个 Shell脚本,对于我这种看不懂 perl 的人来说比较友好,脚本里面的监控逻辑与监控命令也可以拿来参考,用于构建自己的监控体系。

三、使用

接着我们来看下如何使用这个工具。

pt-stalk 通常以后台服务形式监控 MySQL 并等待触发条件,当触发条件时收集相关诊断数据。

触发条件相关的参数有以下几个:

function:

∘ 默认为 status,代表监控 SHOW GLOBAL STATUS 的输出;

∘ 也可以设置为 processlist,代表监控 show processlist 的输出;

variable:

∘ 默认为 Threads_running,代表 监控参数,根据上述监控输出指定具体的监控项;

threshold:

∘ 默认为 25,代表 监控阈值,监控参数超过阈值,则满足触发条件;

∘ 监控参数的值非数字时,需要配合 match 参数一起使用,如 processlist 的 state 列;

cycles:

∘ 默认为 5,表示连续观察到五次满足触发条件时,才触发收集;

连接参数:host、password、port、socket。

其他一些重要参数:

iterations:该参数指定 pt-stalk 在触发收集几次后退出,默认会一直运行。

run-time:触发收集后,该参数指定收集多长时间的数据,默认 30 秒。

sleep:该参数指定在触发收集后,sleep 多久后继续监控,默认 300 秒。

interval:指定状态参数的检查频率,判断是否需要触发收集,默认 1 秒。

dest:监控数据存放路径,默认为 /var/lib/pt-stalk。

retention-time :监控数据保留时长,默认 30 天。

daemonize:以后台服务运行,默认不开启。

log:后台运行日志,默认为 /var/log/pt-stalk.log。

collect:触发发生时收集诊断数据,默认开启。

∘ collect-gdb:收集 GDB 堆栈跟踪,需要 gdb 工具。

∘ collect-strace:收集跟踪数据,需要 strace 工具。

∘ collect-tcpdump:收集 tcpdump 数据,需要 tcpdump 工具。

如果您不太熟悉MySQL监控,开始可以看一看流行的监控软件。例如,下面列出了MySQL Cacti Plugin

Innodb Buffer Pool Activity

•Pages Created

•Pages Written

•Pages Read

Innodb Buffer Pool Pages

•Pool Size

•Database Pages

•Free Pages

•Modified Pages

Inoodb File I/O

•File Reads

•Files Writes

•Log Writes

•File Fsyncs

Innodb Pending I/O

•Aio Log Ios

•Aio Sync ios

•Buffer Pool Flushes

•Chkp Writes

•Ibuf Aio Reads

•Log Flushes

•Log Writes

•Normal Aio Reads

•Normal Aio Writes

Innodb Insert Buffer

•Inserts

•Merged

•Merges

Innodb Log

•Log Buffer Size

•Log Bytes Written

•Log Bytes Flushed

•Unflushed Log

Innodb Row Operations

•Rows Read

•Rows Deleted

•Rows Updated

•Rows Inserted

Innodb Semaphores

•Spin Rounds

•Spin Waits

•OS Waits

Innodb Transactions

•Innodb Transactions

•Current Transactions

•History List

•Read Views

MySQL Binary/Relay Logs

•Binlog Cache use

•Binlog Cache Disk Use

•Binary Log Space

•Relay Log Space

MySQL Command Counters

•Questions

•SELECT

•DELETE

•INSERT

•UPDATE

•REPLACE

•LOAD

•DELETE MULTI

•INSERT SELECT

•UPDATE MULTI

•REPLACE SELECT

MySQL Connections

•Max Connections

•Max Used Connections

•Aborted Clients

•Aborted Connects

•Threads Connected

•Connections

MySQL Files and Tables

•Table Cache

•Open Tables

•Open Files

•Opened Tables

MySQL Network Traffic

•Bytes Received

•Bytes Sent

MySQL Processlist

•State Closing Tables

•State Copying to Tmp Table

•State End

•State Freeing Items

•State Init

•State Locked

•State Login

•State Preparing

•State Reading From Net

•State Sending Data

•State Sorting Result

•State Statistics

•State Updating

•State Writing to Net

•State None

•State Other

MySQL Query Cache

•Queries In Cache

•Hits

•Inserts

•Not Cached

•Lowmem Prunes

MySQL Query Cache Memory

•Query Cache Size

•Free Memory

•Total Blocks

•Free Blocks

MySQL Replication

•Slave Running

•Slave Stopped

•Slave Lag

•Slave Open Temp Tables

•Slave Retried Transactions

MySQL Select Types

•Select Full Join

•Select Full Range Join

•Select Range

•Select Range Check

•Select Scan

MySQL Sorts

•Sort Rows

•Sort Range

•Sort Merge Passes

•Sort Scan

MySQL Table Locks

•Table Locks Immediate

•Table Locks Waited

•Slow Queries

MySQL Temporary Objects

•Created Tmp Tables

•Created Tmp Disk Tables

•Created Tmp Files

MySQL Threads

•Thread Cache Size

•Threads Created


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/7403061.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-05
下一篇 2023-04-05

发表评论

登录后才能评论

评论列表(0条)

保存