21. pt-stalk
pt-stalk 适用场景:
MySQL Server 性能波动出现的频率很低、例如、几天一次
MySQL Server 性能波动出现的机率很快、例如、几秒闪过
pt-stalk h=192.168.100.101,P=3306,u=admin,p=admin \
--function status --variable Threads_connected --threshold 5 \
--daemonize --iterations 1 --interval 1 --cycles 3 --run-time 10 --sleep 300
日志默认存储:/var/log/pt-stalk.log
记录文件默认存储:/var/lib/pt-stalk
在上面的示例中触发参数是:
"--function status --variable Threads_connected --threshold 2500",
表示MySQL状态值Threads_connected超过2500时触发数据收集。
常用的触发条件还可以使用Threads_running等。
另外还可以使用SHOW PROCESSLIST的中的结果触发,
例如"--function processlist --variable State --match statistics --threshold 10"表示,
show processlist中State列的值为statistics的线程数超过10则触发收集。
其他的参数:
--iterations:该参数指定pt-stalk在收集几次故障现场后就退出。默认pt-stalk会一直运行
--run-time:触发收集后,该参数指定收集多长时间的数据。默认是30秒
--sleep:为防止一直触发收集数据,该参数指定在某次触发后,必须sleep一段时候才继续观察并触发收集。默认是300秒
--interval:默认情况pt-stalk会每隔一秒检查一次状态数据,判断是否需要触发收集。该参数指定间隔时间,默认是1秒。
--cycles:默认情况pt-stalk只有连续观察到五次状态值满足触发条件时,才触发收集。该参数控制,需要连续几次满足条件,收集被触发,默认是5次。
[root@server01 ~]# cat /var/log/pt-stalk.log
2018_11_23_15_56_44 Starting /usr/local/bin/pt-stalk --function=status --variable=Threads_connected --threshold=5 --match= --cycles=3 --interval=1 --iterations=1 --run-tim
e=10 --sleep=300 --dest=/var/lib/pt-stalk --prefix= --notify-by-email= --log=/var/log/pt-stalk.log --pid=/var/run/pt-stalk.pid --plugin=2018_11_23_15_56_44 Check results: status(Threads_connected)=9, matched=yes, cycles_true=1
2018_11_23_15_56_45 Check results: status(Threads_connected)=9, matched=yes, cycles_true=2
2018_11_23_15_56_46 Check results: status(Threads_connected)=9, matched=yes, cycles_true=3
2018_11_23_15_56_46 Collect 1 triggered
2018_11_23_15_56_47 Collect 1 PID 3770
2018_11_23_15_56_47 Collect 1 done
2018_11_23_15_56_47 Waiting up to 30 seconds for subprocesses to finish...
2018_11_23_15_57_08 Exiting because no more iterations
2018_11_23_15_57_08 /usr/local/bin/pt-stalk exit status 0
[root@server01 pt-stalk]# pwd
/var/lib/pt-stalk
[root@server01 pt-stalk]# ls
2018_11_23_15_56_46-df 2018_11_23_15_56_46-lsof 2018_11_23_15_56_46-output 2018_11_23_15_56_46-sysctl
2018_11_23_15_56_46-disk-space 2018_11_23_15_56_46-meminfo 2018_11_23_15_56_46-pmap 2018_11_23_15_56_46-top
2018_11_23_15_56_46-diskstats 2018_11_23_15_56_46-mpstat 2018_11_23_15_56_46-processlist 2018_11_23_15_56_46-transactions
2018_11_23_15_56_46-hostname 2018_11_23_15_56_46-mpstat-overall 2018_11_23_15_56_46-procstat 2018_11_23_15_56_46-trigger
2018_11_23_15_56_46-innodbstatus1 2018_11_23_15_56_46-mutex-status1 2018_11_23_15_56_46-procvmstat 2018_11_23_15_56_46-variables
2018_11_23_15_56_46-innodbstatus2 2018_11_23_15_56_46-mutex-status2 2018_11_23_15_56_46-ps 2018_11_23_15_56_46-vmstat
2018_11_23_15_56_46-interrupts 2018_11_23_15_56_46-mysqladmin 2018_11_23_15_56_46-ps-locks-transactions 2018_11_23_15_56_46-vmstat-overall
2018_11_23_15_56_46-iostat 2018_11_23_15_56_46-opentables1 2018_11_23_15_56_46-slabinfo
2018_11_23_15_56_46-iostat-overall 2018_11_23_15_56_46-opentables2 2018_11_23_15_56_46-slave-status