IOSTAT获取磁盘性能参数后,通过Zabbix Agent传值给Zabbix Server即可

IOSTAT

单独执行iostat,显示的结果为从系统开机到当前执行时刻的统计信息。以上输出中,除最上面指示系统版本、主机名和日期的一行外,另有两部分:

  • avg-cpu: 总体cpu使用情况统计信息,对于多核cpu,这里为所有cpu的平均值;
  • Device: 各磁盘设备的IO统计信息.

环境:
   Centos 7.3
   Zabbix 3.0

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[root@localhost ~]# iostat
Linux 3.10.0-123.9.3.el7.x86_64 (uulend-Sstones-250) 08/27/2017 _x86_64_ (4 CPU)
avg-cpu: %user %nice %system %iowait %steal %idle
7.05 0.00 1.52 8.46 0.00 82.96
Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn
vda 8.53 23.92 101.76 190838701 811715460
vdb 1508.27 8334.43 896.07 66480462117 7147631044
dm-0 11.32 135.41 181.72 1080084008 1449488199
dm-1 0.02 0.07 0.08 563269 645028
dm-2 0.04 0.35 0.45 2825226 3588173
vdc 0.86 58.49 65.16 466571469 519767308
[root@localhost ~]#

1
2
3
4
5
6
7
8
9
10
11
12
13
[root@localhost ~]# iostat -dxkt
Linux 3.10.0-123.9.3.el7.x86_64 (uulend-Sstones-250) 08/27/2017 _x86_64_ (4 CPU)
08/27/2017 08:02:50 PM
Device: rrqm/s wrqm/s r/s w/s rkB/s wkB/s avgrq-sz avgqu-sz await r_await w_await svctm %util
vda 0.02 3.27 2.05 6.48 23.93 101.79 29.48 0.02 2.91 3.63 2.69 0.80 0.68
vdb 0.10 105.55 1436.35 72.02 8334.63 896.07 12.24 0.29 0.19 0.15 1.12 0.21 31.72
dm-0 0.00 0.00 3.36 7.96 135.39 181.69 56.02 0.04 3.28 2.77 3.49 0.62 0.70
dm-1 0.00 0.00 0.00 0.01 0.07 0.08 18.98 0.00 4.70 2.55 5.31 3.70 0.01
dm-2 0.00 0.00 0.02 0.02 0.35 0.45 38.14 0.00 3.58 1.41 6.00 2.56 0.01
vdc 0.00 0.19 0.60 0.25 58.61 65.29 288.35 0.05 59.65 2.49 195.64 2.03 0.17
[root@localhost ~]#
  • rrqm/s: 每秒对该设备的读请求被合并次数,文件系统会对读取同块(block)的请求进行合并
  • wrqm/s: 每秒对该设备的写请求被合并次数
  • r/s: 每秒完成的读次数
  • w/s: 每秒完成的写次数
  • rkB/s: 每秒读数据量(kB为单位)
  • wkB/s: 每秒写数据量(kB为单位)
  • avgrq-sz:平均每次IO操作的数据量(扇区数为单位)
  • avgqu-sz: 平均等待处理的IO请求队列长度
  • await: 平均每次IO请求等待时间(包括等待时间和处理时间,毫秒为单位)
  • svctm: 平均每次IO请求的处理时间(毫秒为单位)
  • %util: 采用周期内用于IO操作的时间比率,即IO队列非空的时间比率

Zabbix监控

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#扫描磁盘
[root@localhost ~]# cd /etc/zabbix/scripts/
[root@localhost scripts]# cat disk_scan.sh
#!/bin/bash
diskarray=(`cat /proc/diskstats |grep -E "\bvd[abcdefg]\b|\bvd[abcdefg]\b"|grep -i "\b$1\b"|awk '{print $3}'|sort|uniq
2>/dev/null`)length=${#diskarray[@]}
printf "{\n"
printf '\t'"\"data\":["
for ((i=0;i<$length;i++))
do
printf '\n\t\t{'
printf "\"{#DISKNAME}\":\"${diskarray[$i]}\"}"
if [ $i -lt $[$length-1] ];then
printf ','
fi
done
printf "\n\t]\n"
printf "}\n"
[root@localhost scripts]#
1
2
3
4
5
6
7
8
9
10
#执行结果
[root@localhost scripts]# sh disk_scan.sh
{
"data":[
{"{#DISKNAME}":"vda"},
{"{#DISKNAME}":"vdb"},
{"{#DISKNAME}":"vdc"}
]
}
[root@localhost scripts]#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#获取磁盘性能参数
[root@localhost scripts]# cat disk_status.sh
#/bin/sh
device=$1
item=$2
case $item in
rps)
iostat -dxkt |grep "\b$device\b"|tail -1|awk '{print $4}'
;;
wps)
iostat -dxkt |grep "\b$device\b" |tail -1|awk '{print $5}'
;;
util)
iostat -dxkt |grep "\b$device\b" |tail -1|awk '{print $NF}'
;;
idle)
iostat -x | grep -iA1 "\b$device\b" | tail -1 | awk '{print $NF}'
;;
iowait)
iostat -x | grep -iA1 "\b$device\b" | tail -1 | awk '{print $(NF-2)}'
;;
esac
[root@localhost scripts]#
1
2
3
4
#执行结果
[root@Localhost scripts]# sh disk_status.sh vda idle
31.72
[root@Localhost scripts]#
1
2
3
4
5
6
7
8
#配置Zabbix Agent
[root@localhost ~]# cd /etc/zabbix/zabbix_agentd.d/
[root@localhost zabbix_agentd.d]# cat userparameter_io.conf
UserParameter=disk.scandisk[*],sh /etc/zabbix/scripts/disk_scan.sh $1 #扫描磁盘
UserParameter=disk.status[*],sh /etc/zabbix/scripts/disk_status.sh $1 $2
[root@localhost zabbix_agentd.d]#
[root@localhost ~]# systemctl restart zabbix-agent
1
2
3
4
5
6
7
8
9
10
11
12
#测试zabbix是否可以成功获取
[root@localhost ~]# zabbix_get -s localhost -k disk.scandisk
{
"data":[
{"{#DISKNAME}":"vda"},
{"{#DISKNAME}":"vdb"},
{"{#DISKNAME}":"vdc"}
]
}
[root@localhost ~]# zabbix_get -s localhost -k disk.status[vdb,util]
31.72
[root@localhost ~]#

配置Zabbix Monitor

Zabbix_Monitor_IO
Zabbix_Monitor_IO
Zabbix_Monitor_IO
Zabbix_Monitor_IO
Zabbix_Monitor_IO
Zabbix_Monitor_IO
Zabbix_Monitor_IO
Zabbix_Monitor_IO
Zabbix_Monitor_IO
Zabbix_Monitor_IO

附件:
disk_scan.sh
disk_status.sh
userparameter_io.conf
Template IO status.xml

关于Zabbix其他监控指标,请参考:http://yfshare.blog.51cto.com/8611708/d-5


本文出自”Jack Wang Blog”:http://www.yfshare.vip/2017/08/28/Zabbix监控磁盘IO/