zabbix监控io磁盘

1.导入模板

https://github.com/H-Software/Zabbix-II/blob/master/zabbix-templates/linux-disk-io-stats/zbx_templates_linux_disk_io_stats.xml


安装IOSTAT工具

yum install sysstat -y

测试iostat 查看所有硬盘io ,输入iostat

2.部署脚本

mkdir-p /etc/zabbix/zabbix-agent/scripts/

vim /etc/zabbix/scripts/zabbix-iostat.sh



#!/bin/bash

ZBX_DEV="$1"

ZBX_METRIC="$2"

IOSTAT_LOG=/tmp/iostat.log

# Check iostat util

if ! which iostat 2>&1>/dev/null; then

  >&2 echo "Can't find 'iostat' binary in \$PATH"

  >&2 echo "Make sure that you've installed 'sysstat' package"

  exit 1

fi

# Check args

[[ $# -lt 1 ]] && { echo "Give some more arguments, please :)"; exit 1; }

# Discovering devices and spits out JSON

if [ "$ZBX_DEV" = 'discovery' ]; then

  iostat -d | \

  tail -n +4 |

  awk 'BEGIN {

    ORS="";

    print "{\"data\":["}

    /\d/ {printf "%s{\"%s\":\"%s\"}", separator, "{#DEVICENAME}", $1, separator = ","}

    END {print "]}" }'

  exit 0

fi

# Test iostat log

[[ ! -f "${IOSTAT_LOG}" ]] && echo "[m|ZBX_NOTSUPPORTED] [No such file ${IOSTAT_LOG}]" && exit 1

# Parse iostat file

function parse_iostat() {

  grep ${ZBX_DEV} ${IOSTAT_LOG} | \

  tr ',' '.' | \

  awk -v field="$1" '

  {sum+=$field; n++;}

  END {if (n > 0) print sum/n;

  else {print "[m|ZBX_NOTSUPPORTED] [Nodata.]" > "/dev/stderr"; exit 1};}'

}

# Exec parse funcion with number of column

case ${ZBX_METRIC} in

  rrqm/s    ) parse_iostat '2';;

  wrqm/s    ) parse_iostat '3';;

  r/r      ) parse_iostat '4';;

  w/r      ) parse_iostat '5';;

  rkb/s    ) parse_iostat '6';;

  wkb/s    ) parse_iostat '7';;

  avgrq-sz  ) parse_iostat '8';;

  avgqu-sz  ) parse_iostat '9';;

  await    ) parse_iostat '10';;

  r_await  ) parse_iostat '11';;

  w_await  ) parse_iostat '12';;

  svctm    ) parse_iostat '13';;

  util      ) parse_iostat '14';;

  *        ) echo "[m|ZBX_NOTSUPPORTED] [Unsupported item key.]" && exit 1;;

esac



添加脚本权限

chmod+x /etc/zabbix/scripts/zabbix-iostat.sh

设置参数

echo  'UserParameter=iostat[*],/etc/zabbix/zabbix-agent/scripts/zabbix-iostat.sh "$1" "$2"'> /etc/zabbix/zabbix_agentd.d/iostat.conf

重启zabbix_agentd

service zabbix-agent restart

测试自动发现

zabbix_agentd -t iostat[discovery]

3.加入crontab -e

* * * * * (sleep10&& iostat -dxk120> /tmp/iostat.tmp &&mv/tmp/iostat.tmp /tmp/iostat.log )

* * * * * (sleep40&& iostat -dxk120> /tmp/iostat.tmp &&mv/tmp/iostat.tmp /tmp/iostat.log )

重启计划任务

service crond restart

测试监控项

zabbix_agentd -t iostat[sda,rkb/s]

4.添加模板

Template_Linux_DISK_IO_Discovery_English.xml



https://www.cnblogs.com/reblue520/p/7255573.html

你可能感兴趣的:(zabbix监控io磁盘)