zabbix应用之Low-level discovery监控磁盘IO

参考文章:

http://qicheng0211.blog.51cto.com/3958621/1599776/

zabbix自带的"Template OS Linux"模板支持监控已经挂载的磁盘空间利用率,是利用LLD(Low-level discovery )实现的,却没有对磁盘IO监控。

思 路:首先创建Discovery rules,在agent端配置对应的UserParameter,调用shell脚本,动态查找出已经挂载的磁盘分区;然后创建Item prototypes,使用vfs.dev.read[device,<type>,<mode>]和 vfs.dev.write[device,<type>,<mode>]来监控磁盘分区的IO,包括磁盘读写速率、每秒读写扇 区数、每秒写操作数;然后创Graph prototypes,生成磁盘IO图表。(zabbix服务器端通过与zabbix agent通信来获取客户端服务器的数据;agent分为两个版本,其中一个是主动一个是被动,在配置主机我们可以看到一个agent,另一个是 agent(active)。前者为被动检测,后者为主动检 测;关建点来了vfs.dev.read[device,<type>,<mode>]就是监控项keys)

zabbix agent类型所有key:http://ju.outofmemory.cn/entry/76305

首先做io动态监控的zabbix_agent端执行该脚本:

#!/bin/sh
#
# Filename: autoMonitorDiskIO.sh
# Date: 2017-02-15
# Description: 部署zabbix low-level discovery 监控磁盘IO
# Notes: 在被监控客户端运行此脚本,前提条件已经安装好zabbix agent
# ROOT_UID=0
if [ "$UID" -ne "$ROOT_UID" ];then
echo "Error: Please run this script as root user."
exit 1
fi # 自行修改为你的zabbix agent配置文件路径
AGENT_CONF="/etc/zabbix/zabbix_agentd.conf" mkdir -p /etc/zabbix/monitor_scripts
# 创建 low-level discovery mounted disk 脚本
cat > /etc/zabbix/monitor_scripts/mount_disk_discovery.sh << 'EOF'
#!/bin/bash
#Function: low-level discovery mounted disk
#Script_name: mount_disk_discovery.sh mount_disk_discovery()
{
local regexp="\b(btrfs|ext2|ext3|ext4|jfs|reiser|xfs|ffs|ufs|jfs|jfs2|vxfs|hfs|ntfs|fat32|zfs)\b"
local tmpfile="/tmp/mounts.tmp"
:> "$tmpfile"
egrep "$regexp" /proc/mounts > "$tmpfile"
local num=$(cat "$tmpfile" | wc -l)
printf '{\n'
printf '\t"data":[ '
while read line;do
DEV_NAME=$(echo $line | awk '{print $1}')
FS_NAME=$(echo $line | awk '{print $2}')
SEC_SIZE=$(sudo /sbin/blockdev --getss $DEV_NAME 2>/dev/null)
printf '\n\t\t{'
printf "\"{#DEV_NAME}\":\"${DEV_NAME}\","
printf "\"{#FS_NAME}\":\"${FS_NAME}\","
printf "\"{#SEC_SIZE}\":\"${SEC_SIZE}\"}"
((num--))
[ "$num" == 0 ] && break
printf ","
done < "$tmpfile"
printf '\n\t]\n'
printf '}\n'
} case "$1" in
mount_disk_discovery)
"$1"
;;
*)
echo "Bad Parameter."
echo "Usage: $0 mount_disk_discovery"
exit 1
;;
esac
EOF
touch /tmp/mounts.tmp
chown zabbix:zabbix /tmp/mounts.tmp
chown -R zabbix:zabbix /etc/zabbix/monitor_scripts
chmod 755 /etc/zabbix/monitor_scripts/mount_disk_discovery.sh # 判断配置文件是否存在
[ -f "${AGENT_CONF}" ] || { echo "ERROR: File ${AGENT_CONF} does not exist.";exit 1;} include=`grep '^Include' ${AGENT_CONF} | cut -d'=' -f2`
# 在配置文件中添加自定义参数
if [ -d "$include" ];then
cat > $include/disk_lld.conf << 'EOF'
UserParameter=mount_disk_discovery,/bin/bash /etc/zabbix/monitor_scripts/mount_disk_discovery.sh mount_disk_discovery
EOF
else
grep -q '^UserParameter=mount_disk_discovery' ${AGENT_CONF} || cat >> ${AGENT_CONF} << 'EOF'
UserParameter=mount_disk_discovery,/bin/bash /etc/zabbix/monitor_scripts/mount_disk_discovery.sh mount_disk_discovery
EOF
fi # 授权zabbix用户无密码运行/sbin/blockdev命令
chmod +w /etc/sudoers
sed -i '/^Defaults\s\+requiretty/s/^/#/' /etc/sudoers
grep -q '^zabbix ALL=(ALL).*blockdev' /etc/sudoers || echo 'zabbix ALL=(ALL) NOPASSWD: /sbin/blockdev' >> /etc/sudoers
chmod 440 /etc/sudoers # 重启agent服务
[ -f '/etc/init.d/zabbix-agent' ] && /etc/init.d/zabbix-agent restart || echo "需手动重启zabbix agent服务."

然后在zabbix_server的web端,导入下面的模板:

模板的名子为: TemplateLinuxDiskIO.xml

内容如下:<version>2.0</version>这里的版本号不能与zabbix_server的版本号差的太多,不然会失败!!!!!

<?xml version="1.0" encoding="UTF-8"?>
<zabbix_export>
<version>2.0</version>
<date>--15T05::12Z</date>
<groups>
<group>
<name>Templates</name>
</group>
</groups>
<templates>
<template>
<template>Template Linux DiskIO</template>
<name>Template Linux DiskIO</name>
<description/>
<groups>
<group>
<name>Templates</name>
</group>
</groups>
<applications>
<application>
<name>Disk IO</name>
</application>
</applications>
<items/>
<discovery_rules>
<discovery_rule>
<name>Mount Disk discovery</name>
<type></type>
<snmp_community/>
<snmp_oid/>
<key>mount_disk_discovery</key>
<delay></delay>
<status></status>
<allowed_hosts/>
<snmpv3_contextname/>
<snmpv3_securityname/>
<snmpv3_securitylevel></snmpv3_securitylevel>
<snmpv3_authprotocol></snmpv3_authprotocol>
<snmpv3_authpassphrase/>
<snmpv3_privprotocol></snmpv3_privprotocol>
<snmpv3_privpassphrase/>
<delay_flex/>
<params/>
<ipmi_sensor/>
<authtype></authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<filter>
<evaltype></evaltype>
<formula/>
<conditions/>
</filter>
<lifetime></lifetime>
<description/>
<item_prototypes>
<item_prototype>
<name>Operations read per second on {#FS_NAME}</name>
<type></type>
<snmp_community/>
<multiplier></multiplier>
<snmp_oid/>
<key>vfs.dev.read[{#DEV_NAME},ops]</key>
<delay></delay>
<history></history>
<trends></trends>
<status></status>
<value_type></value_type>
<allowed_hosts/>
<units>oper/s</units>
<delta></delta>
<snmpv3_contextname/>
<snmpv3_securityname/>
<snmpv3_securitylevel></snmpv3_securitylevel>
<snmpv3_authprotocol></snmpv3_authprotocol>
<snmpv3_authpassphrase/>
<snmpv3_privprotocol></snmpv3_privprotocol>
<snmpv3_privpassphrase/>
<formula></formula>
<delay_flex/>
<params/>
<ipmi_sensor/>
<data_type></data_type>
<authtype></authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<description/>
<inventory_link></inventory_link>
<applications>
<application>
<name>Disk IO</name>
</application>
</applications>
<valuemap/>
<logtimefmt/>
</item_prototype>
<item_prototype>
<name>Operations write per second on {#FS_NAME}</name>
<type></type>
<snmp_community/>
<multiplier></multiplier>
<snmp_oid/>
<key>vfs.dev.write[{#DEV_NAME},ops]</key>
<delay></delay>
<history></history>
<trends></trends>
<status></status>
<value_type></value_type>
<allowed_hosts/>
<units>oper/s</units>
<delta></delta>
<snmpv3_contextname/>
<snmpv3_securityname/>
<snmpv3_securitylevel></snmpv3_securitylevel>
<snmpv3_authprotocol></snmpv3_authprotocol>
<snmpv3_authpassphrase/>
<snmpv3_privprotocol></snmpv3_privprotocol>
<snmpv3_privpassphrase/>
<formula></formula>
<delay_flex/>
<params/>
<ipmi_sensor/>
<data_type></data_type>
<authtype></authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<description/>
<inventory_link></inventory_link>
<applications>
<application>
<name>Disk IO</name>
</application>
</applications>
<valuemap/>
<logtimefmt/>
</item_prototype>
<item_prototype>
<name>Read speed on {#FS_NAME}</name>
<type></type>
<snmp_community/>
<multiplier></multiplier>
<snmp_oid/>
<key>vfs.dev.read[{#DEV_NAME},Bps]</key>
<delay></delay>
<history></history>
<trends></trends>
<status></status>
<value_type></value_type>
<allowed_hosts/>
<units>B/s</units>
<delta></delta>
<snmpv3_contextname/>
<snmpv3_securityname/>
<snmpv3_securitylevel></snmpv3_securitylevel>
<snmpv3_authprotocol></snmpv3_authprotocol>
<snmpv3_authpassphrase/>
<snmpv3_privprotocol></snmpv3_privprotocol>
<snmpv3_privpassphrase/>
<formula></formula>
<delay_flex/>
<params>last(&quot;vfs.dev.read[{#DEV_NAME},sps]&quot;)*{#SEC_SIZE}</params>
<ipmi_sensor/>
<data_type></data_type>
<authtype></authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<description/>
<inventory_link></inventory_link>
<applications>
<application>
<name>Disk IO</name>
</application>
</applications>
<valuemap/>
<logtimefmt/>
</item_prototype>
<item_prototype>
<name>Sectors read per second on {#FS_NAME}</name>
<type></type>
<snmp_community/>
<multiplier></multiplier>
<snmp_oid/>
<key>vfs.dev.read[{#DEV_NAME},sps]</key>
<delay></delay>
<history></history>
<trends></trends>
<status></status>
<value_type></value_type>
<allowed_hosts/>
<units>sec/s</units>
<delta></delta>
<snmpv3_contextname/>
<snmpv3_securityname/>
<snmpv3_securitylevel></snmpv3_securitylevel>
<snmpv3_authprotocol></snmpv3_authprotocol>
<snmpv3_authpassphrase/>
<snmpv3_privprotocol></snmpv3_privprotocol>
<snmpv3_privpassphrase/>
<formula></formula>
<delay_flex/>
<params/>
<ipmi_sensor/>
<data_type></data_type>
<authtype></authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<description/>
<inventory_link></inventory_link>
<applications>
<application>
<name>Disk IO</name>
</application>
</applications>
<valuemap/>
<logtimefmt/>
</item_prototype>
<item_prototype>
<name>Sectors write per second on {#FS_NAME}</name>
<type></type>
<snmp_community/>
<multiplier></multiplier>
<snmp_oid/>
<key>vfs.dev.write[{#DEV_NAME},sps]</key>
<delay></delay>
<history></history>
<trends></trends>
<status></status>
<value_type></value_type>
<allowed_hosts/>
<units>sec/s</units>
<delta></delta>
<snmpv3_contextname/>
<snmpv3_securityname/>
<snmpv3_securitylevel></snmpv3_securitylevel>
<snmpv3_authprotocol></snmpv3_authprotocol>
<snmpv3_authpassphrase/>
<snmpv3_privprotocol></snmpv3_privprotocol>
<snmpv3_privpassphrase/>
<formula></formula>
<delay_flex/>
<params/>
<ipmi_sensor/>
<data_type></data_type>
<authtype></authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<description/>
<inventory_link></inventory_link>
<applications>
<application>
<name>Disk IO</name>
</application>
</applications>
<valuemap/>
<logtimefmt/>
</item_prototype>
<item_prototype>
<name>Write speed on {#FS_NAME}</name>
<type></type>
<snmp_community/>
<multiplier></multiplier>
<snmp_oid/>
<key>vfs.dev.write[{#DEV_NAME},Bps]</key>
<delay></delay>
<history></history>
<trends></trends>
<status></status>
<value_type></value_type>
<allowed_hosts/>
<units>B/s</units>
<delta></delta>
<snmpv3_contextname/>
<snmpv3_securityname/>
<snmpv3_securitylevel></snmpv3_securitylevel>
<snmpv3_authprotocol></snmpv3_authprotocol>
<snmpv3_authpassphrase/>
<snmpv3_privprotocol></snmpv3_privprotocol>
<snmpv3_privpassphrase/>
<formula></formula>
<delay_flex/>
<params>last(&quot;vfs.dev.write[{#DEV_NAME},sps]&quot;)*{#SEC_SIZE}</params>
<ipmi_sensor/>
<data_type></data_type>
<authtype></authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<description/>
<inventory_link></inventory_link>
<applications>
<application>
<name>Disk IO</name>
</application>
</applications>
<valuemap/>
<logtimefmt/>
</item_prototype>
</item_prototypes>
<trigger_prototypes/>
<graph_prototypes>
<graph_prototype>
<name>Operations read and write on {#FS_NAME}</name>
<width></width>
<height></height>
<yaxismin>0.0000</yaxismin>
<yaxismax>100.0000</yaxismax>
<show_work_period></show_work_period>
<show_triggers></show_triggers>
<type></type>
<show_legend></show_legend>
<show_3d></show_3d>
<percent_left>0.0000</percent_left>
<percent_right>0.0000</percent_right>
<ymin_type_1></ymin_type_1>
<ymax_type_1></ymax_type_1>
<ymin_item_1></ymin_item_1>
<ymax_item_1></ymax_item_1>
<graph_items>
<graph_item>
<sortorder></sortorder>
<drawtype></drawtype>
<color>0000C8</color>
<yaxisside></yaxisside>
<calc_fnc></calc_fnc>
<type></type>
<item>
<host>Template Linux DiskIO</host>
<key>vfs.dev.read[{#DEV_NAME},ops]</key>
</item>
</graph_item>
<graph_item>
<sortorder></sortorder>
<drawtype></drawtype>
<color>C800C8</color>
<yaxisside></yaxisside>
<calc_fnc></calc_fnc>
<type></type>
<item>
<host>Template Linux DiskIO</host>
<key>vfs.dev.write[{#DEV_NAME},ops]</key>
</item>
</graph_item>
</graph_items>
</graph_prototype>
<graph_prototype>
<name>Read and Write speed on {#FS_NAME}</name>
<width></width>
<height></height>
<yaxismin>0.0000</yaxismin>
<yaxismax>100.0000</yaxismax>
<show_work_period></show_work_period>
<show_triggers></show_triggers>
<type></type>
<show_legend></show_legend>
<show_3d></show_3d>
<percent_left>0.0000</percent_left>
<percent_right>0.0000</percent_right>
<ymin_type_1></ymin_type_1>
<ymax_type_1></ymax_type_1>
<ymin_item_1></ymin_item_1>
<ymax_item_1></ymax_item_1>
<graph_items>
<graph_item>
<sortorder></sortorder>
<drawtype></drawtype>
<color>C80000</color>
<yaxisside></yaxisside>
<calc_fnc></calc_fnc>
<type></type>
<item>
<host>Template Linux DiskIO</host>
<key>vfs.dev.read[{#DEV_NAME},Bps]</key>
</item>
</graph_item>
<graph_item>
<sortorder></sortorder>
<drawtype></drawtype>
<color>00C800</color>
<yaxisside></yaxisside>
<calc_fnc></calc_fnc>
<type></type>
<item>
<host>Template Linux DiskIO</host>
<key>vfs.dev.write[{#DEV_NAME},Bps]</key>
</item>
</graph_item>
</graph_items>
</graph_prototype>
<graph_prototype>
<name>Sectors read and write on {#FS_NAME}</name>
<width></width>
<height></height>
<yaxismin>0.0000</yaxismin>
<yaxismax>100.0000</yaxismax>
<show_work_period></show_work_period>
<show_triggers></show_triggers>
<type></type>
<show_legend></show_legend>
<show_3d></show_3d>
<percent_left>0.0000</percent_left>
<percent_right>0.0000</percent_right>
<ymin_type_1></ymin_type_1>
<ymax_type_1></ymax_type_1>
<ymin_item_1></ymin_item_1>
<ymax_item_1></ymax_item_1>
<graph_items>
<graph_item>
<sortorder></sortorder>
<drawtype></drawtype>
<color>C80000</color>
<yaxisside></yaxisside>
<calc_fnc></calc_fnc>
<type></type>
<item>
<host>Template Linux DiskIO</host>
<key>vfs.dev.read[{#DEV_NAME},sps]</key>
</item>
</graph_item>
<graph_item>
<sortorder></sortorder>
<drawtype></drawtype>
<color>00C800</color>
<yaxisside></yaxisside>
<calc_fnc></calc_fnc>
<type></type>
<item>
<host>Template Linux DiskIO</host>
<key>vfs.dev.write[{#DEV_NAME},sps]</key>
</item>
</graph_item>
</graph_items>
</graph_prototype>
</graph_prototypes>
<host_prototypes/>
</discovery_rule>
</discovery_rules>
<macros/>
<templates/>
<screens/>
</template>
</templates>
</zabbix_export>

如图:

Configuration------>Templates--------->import

zabbix应用之Low-level discovery监控磁盘IO

Configuration----->Templates 来查看导入的模板:

zabbix应用之Low-level discovery监控磁盘IO

查看添加的Template:

zabbix应用之Low-level discovery监控磁盘IO

现在就可以了,接下来要做的就是:把这个Template加入zabbix_agent的步骤如下:

Configuration--->Host---->test2:如图:

zabbix应用之Low-level discovery监控磁盘IO

点击Templates,选择模板 下图所示:

zabbix应用之Low-level discovery监控磁盘IO

zabbix应用之Low-level discovery监控磁盘IO

查看test2的items:

zabbix应用之Low-level discovery监控磁盘IO

下面看看一下效果:

zabbix应用之Low-level discovery监控磁盘IO

zabbix应用之Low-level discovery监控磁盘IO

zabbix应用之Low-level discovery监控磁盘IO

在部署后,不会马上看到效果,而是这种效果 Template Linux DiskIO: Disk IO 的Items (0) 等 一段时间 就会好的!!
zabbix应用之Low-level discovery监控磁盘IO

zabbix应用之Low-level discovery监控磁盘IO

上一篇:Cacti:添加监控磁盘IO


下一篇:第七章——DMVs和DMFs(4)——用DMV和DMF监控磁盘IO