我编写了一个小脚本来确定每小时的平均 IOP,然后我手动将其转换为图表和电子表格,以供管理层讨论即将进行的扩展项目的潜在 SAN 升级。当前运行的系统是运行 RHEL 6 的物理机。
我已在 root 的 crontab 中安排了如下脚本:
0 * * * * /bin/bash /IOPsLogs/IOPs.sh >> /var/log/cronjobIOPs.log 2>&1
我的脚本 IOPs.sh 如下所示:
#!/bin/bash
date >> /var/log/cronjobIOPs.log
date +"%Y-%m-%d--%H:00" >> /IOPsLogs/Daily$(date +%Y-%m-%d).log
timeout -sHUP 60m iostat -x 1 | grep sda -B 1 >> /IOPsLogs/IOPs_$(date +%Y-%m-%d--%H:00).log
grep "sda" /IOPsLogs/IOPs_$(date +%Y-%m-%d--%H:00 -d "1 hour ago").log | awk '{sum+=$4} END { print "Average IOPs read'/'sec= ",sum/NR}' >> /IOPsLogs/Daily$(date +%Y-%m-%d).log
grep "sda" /IOPsLogs/IOPs_$(date +%Y-%m-%d--%H:00 -d "1 hour ago").log | awk '{sum+=$5} END { print "Average IOPs write'/'sec= ",sum/NR}' >> /IOPsLogs/Daily$(date +%Y-%m-%d).log
日志文件“/var/log/cronjobIOPs.log”如下所示:(这很好,因为我没有看到任何错误。)
Mon Apr 27 00:00:01 MST 2015
Mon Apr 27 01:00:01 MST 2015
Mon Apr 27 02:00:01 MST 2015
Mon Apr 27 03:00:01 MST 2015
Mon Apr 27 04:00:01 MST 2015
Mon Apr 27 05:00:01 MST 2015
Mon Apr 27 06:00:01 MST 2015
Mon Apr 27 07:00:01 MST 2015
Mon Apr 27 08:00:01 MST 2015
Mon Apr 27 09:00:01 MST 2015
Mon Apr 27 10:00:01 MST 2015
Mon Apr 27 11:00:01 MST 2015
Mon Apr 27 12:00:01 MST 2015
Mon Apr 27 13:00:01 MST 2015
Mon Apr 27 14:00:01 MST 2015
Mon Apr 27 15:00:01 MST 2015
Mon Apr 27 16:00:01 MST 2015
Mon Apr 27 17:00:01 MST 2015
Mon Apr 27 18:00:01 MST 2015
Mon Apr 27 19:00:01 MST 2015
Mon Apr 27 20:00:01 MST 2015
Mon Apr 27 21:00:01 MST 2015
Mon Apr 27 22:00:01 MST 2015
Mon Apr 27 23:00:01 MST 2015
Tue Apr 28 00:00:01 MST 2015
Tue Apr 28 01:00:01 MST 2015
Tue Apr 28 02:00:01 MST 2015
Tue Apr 28 03:00:01 MST 2015
Tue Apr 28 04:00:01 MST 2015
Tue Apr 28 05:00:01 MST 2015
Tue Apr 28 06:00:01 MST 2015
Tue Apr 28 07:00:01 MST 2015
Tue Apr 28 08:00:01 MST 2015
Tue Apr 28 09:00:01 MST 2015
现在我的问题是每日日志不一致,它每小时提供一次读写平均值。有时它会对一个时间戳或两个时间戳提供两个以上的答案。时间似乎有点不对劲?(不是虚拟机,多年来没有看到任何时间滑移。)如果我每小时手动运行一次,那么它就可以正常工作。有人有什么想法或其他方法吗?
Average IOPs read/sec= 0.0442611
Average IOPs write/sec= 13.4663
2015-04-27--00:00
Average IOPs read/sec= 79.1727
Average IOPs write/sec= 22.7509
2015-04-27--01:00
2015-04-27--02:00
Average IOPs read/sec= 0.0370389
Average IOPs write/sec= 13.1389
Average IOPs read/sec= 36.6858
2015-04-27--03:00
Average IOPs write/sec= 250.514
Average IOPs read/sec= 32.6261
2015-04-27--04:00
Average IOPs write/sec= 391.811
Average IOPs read/sec= 1.64334
Average IOPs write/sec= 84.6204
2015-04-27--05:00
2015-04-27--06:00
Average IOPs read/sec= 0.0487056
Average IOPs write/sec= 12.8323
Average IOPs read/sec= 0.0617611
Average IOPs write/sec= 14.0306
2015-04-27--07:00
2015-04-27--08:00
Average IOPs read/sec= 0.11815
Average IOPs write/sec= 14.094
Average IOPs read/sec= 0.0817611
Average IOPs write/sec= 14.9651
2015-04-27--09:00
Average IOPs read/sec= 0.0434278
Average IOPs write/sec= 13.6037
2015-04-27--10:00
Average IOPs read/sec= 0.613706
Average IOPs write/sec= 14.9003
2015-04-27--11:00
Average IOPs read/sec= 0.0389833
Average IOPs write/sec= 13.9256
2015-04-27--12:00
2015-04-27--13:00
Average IOPs read/sec= 0.0642528
Average IOPs write/sec= 15.1321
Average IOPs read/sec= 0.144817
Average IOPs write/sec= 13.8244
2015-04-27--14:00
Average IOPs read/sec= 0.0384222
2015-04-27--15:00
Average IOPs write/sec= 13.0468
Average IOPs read/sec= 0.0312028
Average IOPs write/sec= 12.7255
2015-04-27--16:00
Average IOPs read/sec= 0.0781472
Average IOPs write/sec= 13.7179
2015-04-27--17:00
Average IOPs read/sec= 0.0798139
Average IOPs write/sec= 15.9144
2015-04-27--18:00
Average IOPs read/sec= 0.138147
Average IOPs write/sec= 13.7297
2015-04-27--19:00
Average IOPs read/sec= 0.0362028
Average IOPs write/sec= 13.2324
2015-04-27--20:00
Average IOPs read/sec= 0.254536
Average IOPs write/sec= 14.9013
2015-04-27--21:00
Average IOPs read/sec= 0.0314806
Average IOPs write/sec= 12.8527
2015-04-27--22:00
2015-04-27--23:00
Average IOPs read/sec= 21.6865
Average IOPs write/sec= 70.7389
答案1
这是脚本的一次执行与一小时后执行的一次执行之间的重叠。有时,新执行在第一次执行写完最后两行之前就写出了第一行。
前两行来自 2015-04-26 的最后一次执行。写入时的日期是 2015-04-27,因为使用的日志文件基于写入时的时间,而不是执行开始时的时间。
一种选择是将日期和时间存储在变量中,并同时将所有三行写入正确的日期文件中。