分类: LINUX
2019-08-10 08:21:04
perl和python,以及zabbix-agent已是可用状态。
1:每秒IO数,即iops或tps 2:吞吐率 3:平均IO尺寸,avgrq-sz 4:IO等待队列长度,avgqu-sz 5:磁盘活动时间百分比,util
yum install sysstat -y #centos7安装iostat工具,centos6之前自带
mkdir /usr/lib/zabbix/alertscripts/ -p chown zabbix:zabbix /usr/lib/zabbix/ -R
cd /usr/lib/zabbix/alertscripts/ vim discover_disk.pl #!/usr/bin/perl # give disk dmname, returns Proxmox VM name sub get_vmname_by_id { $vmname=`cat /etc/qemu-server/$_[0].conf | grep name | cut -d \: -f 2`; $vmname =~ s/^\s+//; #remove leading spaces $vmname =~ s/\s+$//; #remove trailing spaces return $vmname } $first = 1; print "{\n"; print "\t\"data\":[\n\n"; for (`cat /proc/diskstats`) { ($major,$minor,$disk) = m/^\s*([0-9]+)\s+([0-9]+)\s+(\S+)\s.*$/; $dmnamefile = "/sys/dev/block/$major:$minor/dm/name"; $vmid= ""; $vmname = ""; $dmname = $disk; $diskdev = "/dev/$disk"; # DM name if (-e $dmnamefile) { $dmname = `cat $dmnamefile`; $dmname =~ s/\n$//; #remove trailing \n $diskdev = "/dev/mapper/$dmname"; # VM name and ID if ($dmname =~ m/^.*--([0-9]+)--.*$/) { $vmid = $1; #$vmname = get_vmname_by_id($vmid); } } #print("$major $minor $disk $diskdev $dmname $vmid $vmname \n"); print "\t,\n" if not $first; $first = 0; print "\t{\n"; print "\t\t\"{#DISK}\":\"$disk\",\n"; print "\t\t\"{#DMNAME}\":\"$dmname\",\n"; print "\t\t\"{#VMNAME}\":\"$vmname\",\n"; print "\t\t\"{#VMID}\":\"$vmid\"\n"; print "\t}\n"; } print "\n\t]\n"; print "}\n";
vim zbx_parse_iostat_values.sh #!/bin/bash dev=$1 type=$2 #enable debug mode debug=0 if [[ -z "$dev" ]]; then echo "error: wrong input value (device)" exit 1 fi if [[ -z "$type" ]]; then echo "error: wrong input value (type)" exit 1 fi columns=`iostat -xN |egrep -o "^Device.*"` columnsarray=($columns) column_id=1 for i in "${columnsarray[@]}" do #echo "column: $i" if [[ "$i" = "$type" ]]; then if [[ $debug -eq 1 ]]; then echo "right column (${i}) found...column_id: $column_id " fi id="$" column_id_id=$id$column_id iostats=`iostat -xN |egrep -o "^${dev}[[:space:]]+.*" |awk "{print ${column_id_id}}"` fi column_id=$[column_id + 1] done if [ -z "$iostats" ]; then echo "error: \"device\" or \"type\" not found (${dev},${type})" exit 3 fi iostats_lines=`wc -l < << "$iostats"` if [ $iostats_lines -ne 1 ]; then echo "error: wrong output value (${iostats_lines})" exit 2 fi echo $iostats if [[ $debug -eq 1 ]]; then echo "- - - - - - - - - -" echo $columns iostats_debug=`iostat -xN |egrep -o "^${dev}[[:space:]]+.*"` echo $iostats_debug echo "- - - - - - - - - -" fi exit 0
chmod +x /usr/lib/zabbix/alertscripts/*
vim /etc/zabbix/zabbix_agentd.conf # diskio discovery UserParameter=discovery.disks.iostats,/usr/lib/zabbix/alertscripts/discover_disk.pl UserParameter=custom.vfs.dev.iostats.rrqm[*],/usr/lib/zabbix/alertscripts/zbx_parse_iostat_values.sh $1 "rrqm/s" UserParameter=custom.vfs.dev.iostats.wrqm[*],/usr/lib/zabbix/alertscripts/zbx_parse_iostat_values.sh $1 "wrqm/s" UserParameter=custom.vfs.dev.iostats.rps[*],/usr/lib/zabbix/alertscripts/zbx_parse_iostat_values.sh $1 "r/s" UserParameter=custom.vfs.dev.iostats.wps[*],/usr/lib/zabbix/alertscripts/zbx_parse_iostat_values.sh $1 "w/s" UserParameter=custom.vfs.dev.iostats.avgrq[*],/usr/lib/zabbix/alertscripts/zbx_parse_iostat_values.sh $1 "avgrq-sz" UserParameter=custom.vfs.dev.iostats.avgqu[*],/usr/lib/zabbix/alertscripts/zbx_parse_iostat_values.sh $1 "avgqu-sz" UserParameter=custom.vfs.dev.iostats.await[*],/usr/lib/zabbix/alertscripts/zbx_parse_iostat_values.sh $1 "await" UserParameter=custom.vfs.dev.iostats.svctm[*],/usr/lib/zabbix/alertscripts/zbx_parse_iostat_values.sh $1 "svctm" UserParameter=custom.vfs.dev.iostats.util[*],/usr/lib/zabbix/alertscripts/zbx_parse_iostat_values.sh $1 "%util" UserParameter=custom.vfs.dev.iostats.rkB[*],/usr/lib/zabbix/alertscripts/zbx_parse_iostat_values.sh $1 "rkB/s" UserParameter=custom.vfs.dev.iostats.wkB[*],/usr/lib/zabbix/alertscripts/zbx_parse_iostat_values.sh $1 "wkB/s"
systemctl restart zabbix-agent.service
wget
#这里的名称一定要是它,建议复制粘贴 "Linux disks for autodiscovery"