当前位置:   article > 正文

zabbix监控磁盘IO性能

zabbix监控磁盘io

前言

日常工作中,对于磁盘IO的监控必不可少,通过zabbix来实现对磁盘的监控,可以让我们对磁盘的工作状态有充分的了解,对可能由于磁盘的原因造成的性能瓶颈提前预防

1. 客户端配置

1.1 磁盘自动发现脚本

cat /etc/zabbix/scripts/io_stats/discover_disk.pl

# G. Husson - Thalos - 20120713
# Zabbix 2 - disk autodiscovery for linux
# all disks listed in /proc/diskstats are returned
# special processing on LVMs
# special processing on Proxmox VE disks (VM id and VM name are returned)
# rq : in Zabbix, create a regexp filter on which disks you want to monitor on your IT System
# ex : ^(hd[a-z]+|sd[a-z]+|vd[a-z]+|dm-[0-9]+|drbd[0-9]+)$
#      ^(loop[0-9]+|sr[0-9]*|fd[0-9]*)$

# Custom keys :
#UserParameter=custom.vfs.dev.read.ops[*],cat /proc/diskstats | grep "$1" | head -1 | awk '{print $$4}'
#UserParameter=custom.vfs.dev.read.ms[*],cat /proc/diskstats | grep "$1" | head -1 | awk '{print $$7}'
#UserParameter=custom.vfs.dev.write.ops[*],cat /proc/diskstats | grep "$1" | head -1 | awk '{print $$8}'
#UserParameter=custom.vfs.dev.write.ms[*],cat /proc/diskstats | grep "$1" | head -1 | awk '{print $$11}'
#UserParameter=custom.vfs.dev.io.active[*],cat /proc/diskstats | grep "$1" | head -1 | awk '{print $$12}'
#UserParameter=custom.vfs.dev.io.ms[*],cat /proc/diskstats | grep "$1" | head -1 | awk '{print $$13}'
#UserParameter=custom.vfs.dev.read.sectors[*],cat /proc/diskstats | grep "$1" | head -1 | awk '{print $$6}'
#UserParameter=custom.vfs.dev.write.sectors[*],cat /proc/diskstats | grep "$1" | head -1 | awk '{print $$10}'

#Discovery items creation :
#Disk {#VMNAME}:{#DMNAME} io spent      custom.vfs.dev.io.ms[{#DISK}]
#Disk {#VMNAME}:{#DMNAME} read bw       custom.vfs.dev.read.sectors[{#DISK}]
#Disk {#VMNAME}:{#DMNAME} read io       custom.vfs.dev.read.ops[{#DEV}]
#Disk {#VMNAME}:{#DMNAME} write bw      custom.vfs.dev.write.sectors[{#DISK}]
#Disk {#VMNAME}:{#DMNAME} write io      custom.vfs.dev.write.ops[{#DEV}]

#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\"{#DISKDEV}\":\"$diskdev\",\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";
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74

1.2 获取监控值脚本

cat /etc/zabbix/scripts/io_stats/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
#echo $columnsarray
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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65

1.3 监控项配置文件

cat /etc/zabbix/zabbix_agentd.d/diskio_discovery.conf

#diskio discovery
UserParameter=discovery.disks.iostats,/etc/zabbix/scripts/io_stats/discover_disk.pl
UserParameter=custom.vfs.dev.iostats.rrqm[*],/etc/zabbix/scripts/io_stats/zbx_parse_iostat_values.sh $1 "rrqm/s"
UserParameter=custom.vfs.dev.iostats.wrqm[*],/etc/zabbix/scripts/io_stats/zbx_parse_iostat_values.sh $1 "wrqm/s"
UserParameter=custom.vfs.dev.iostats.rps[*],/etc/zabbix/scripts/io_stats/zbx_parse_iostat_values.sh $1 "r/s"
UserParameter=custom.vfs.dev.iostats.wps[*],/etc/zabbix/scripts/io_stats/zbx_parse_iostat_values.sh $1 "w/s"
UserParameter=custom.vfs.dev.iostats.rkB[*],/etc/zabbix/scripts/io_stats/zbx_parse_iostat_values.sh $1 "rkB/s"
UserParameter=custom.vfs.dev.iostats.wkB[*],/etc/zabbix/scripts/io_stats/zbx_parse_iostat_values.sh $1 "wkB/s"
UserParameter=custom.vfs.dev.iostats.avgrq[*],/etc/zabbix/scripts/io_stats/zbx_parse_iostat_values.sh $1 "avgrq-sz"
UserParameter=custom.vfs.dev.iostats.avgqu[*],/etc/zabbix/scripts/io_stats/zbx_parse_iostat_values.sh $1 "avgqu-sz"
UserParameter=custom.vfs.dev.iostats.await[*],/etc/zabbix/scripts/io_stats/zbx_parse_iostat_values.sh $1 "await"
UserParameter=custom.vfs.dev.iostats.svctm[*],/etc/zabbix/scripts/io_stats/zbx_parse_iostat_values.sh $1 "svctm"
UserParameter=custom.vfs.dev.iostats.util[*],/etc/zabbix/scripts/io_stats/zbx_parse_iostat_values.sh $1 "%util"
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

2.服务端配置

2.1 导入监控模版

下载链接

2.2 主机链接导入的模版

按上述配置完成后,稍等一会儿,然后查看最新数据,就可以看到关于磁盘IO的监控数据了
在这里插入图片描述

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Cpp五条/article/detail/161035
推荐阅读
相关标签
  

闽ICP备14008679号