当前位置:网站首页>Dynamically monitor disk i/o with ZABBIX
Dynamically monitor disk i/o with ZABBIX
2022-07-03 11:48:00 【Brother Xing plays with the clouds】
Recently in to see Linux I/O Subsystem related information , Need to monitor each The server Of disks I/O, especially MongoDB database The server Of disks I/O, Because each one The server The disk names of may be different , So you need to use Zabbix Of LLD Function to discover disks and monitor I/O
Reference article
http://www.programering.com/a/MDOwYDNwATc.html
1. Write the steps to discover disk
shell edition disk_discovery.sh
#!/bin/bash
diskarray=(`cat /proc/diskstats |grep -E "\bsd[a-z]\b|\bxvd[a-z]\b|\bvd[a-z]\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 "\"{#DISK_NAME}\":\"
if [ i -lt [
printf ','
fi
done
printf "\n\t]\n"
printf "}\n"
$ sh disk_discovery.sh
{
"data":[
{"{#DISK_NAME}":"xvda"},
{"{#DISK_NAME}":"xvdb"}
]
}
Python edition disk_discovery.py
#/usr/bin/python
#This script is used to discovery disk on the server
import subprocess
import json
args="cat /proc/diskstats |grep -E '\ssd[a-z]\s|\sxvd[a-z]\s|\svd[a-z]\s'|awk '{print $3}'|sort|uniq 2>/dev/null"
t=subprocess.Popen(args,shell=True,stdout=subprocess.PIPE).communicate()[0]
disks=[]
for disk in t.split('\n'):
if len(disk) != 0:
disks.append({'{#DISK_NAME}':disk})
print json.dumps({'data':disks},indent=4,separators=(',',':'))
$ python disk_discovery.py
{
"data":[
{
"{#DISK_NAME}":"xvda"
},
{
"{#DISK_NAME}":"xvdb"
}
]
}
2. Write get disk I/O Script for information
Use iostat Collect disks I/O Information
#/bin/sh
device=$1
item=$2
/usr/bin/iostat -dxkt 1 5 > /tmp/iostat_output 2>/dev/null
case $item in
rrqm)
/usr/bin/tail -n20 /tmp/iostat_output |grep "\b
;;
wrqm)
/usr/bin/tail -n20 /tmp/iostat_output |grep "\b
;;
rps)
/usr/bin/tail -n20 /tmp/iostat_output |grep "\b
;;
wps)
/usr/bin/tail -n20 /tmp/iostat_output |grep "\b
;;
rKBps)
/usr/bin/tail -n20 /tmp/iostat_output |grep "\b
;;
wKBps)
/usr/bin/tail -n20 /tmp/iostat_output |grep "\b
;;
avgrq-sz)
/usr/bin/tail -n20 /tmp/iostat_output |grep "\b
;;
avgqu-sz)
/usr/bin/tail -n20 /tmp/iostat_output |grep "\b
;;
await)
/usr/bin/tail -n20 /tmp/iostat_output |grep "\b
;;
svctm)
/usr/bin/tail -n20 /tmp/iostat_output |grep "\b
;;
util)
/usr/bin/tail -n20 /tmp/iostat_output |grep "\b
;;
esac
3. modify Zabbix agent The configuration file
add to disk_status.conf
Timeout=10
### Option: UserParameter
# User-defined parameter to monitor. There can be several user-defined parameters.
# Format: UserParameter=<key>,<shell command>
# See 'zabbix_agentd' directory for examples.
#
# Mandatory: no
# Default:
# UserParameter=
UserParameter=disk.discovery,/usr/bin/python /usr/local/zabbix/bin/disk_discovery.py
UserParameter=disk.status[*],/usr/local/zabbix/bin/disk_status.sh 1 2
Here we need to pay attention to ,Zabbix agent default Timeout The value is 3 second , Because of the use of iostat -ydxkt 1 3, every other 1 Refresh every second , Refresh 3 Time , So if you get disk information Timeout If the setting time is short, it will appear ZBX_NOTSUPPORTED Such a mistake
Then reload zabbix agent
4. By means of zabbix server or zabbix proxy End use zabbix_get Get disk information
$ /usr/local/zabbix/bin/zabbix_get -s 192.168.1.190 -p 10055 -k "disk.discovery"
{
"data":[
{
"{#DISK_NAME}":"xvda"
},
{
"{#DISK_NAME}":"xvdb"
},
{
"{#DISK_NAME}":"xvdc"
}
]
}
$ /usr/local/zabbix/bin/zabbix_get -s 192.168.1.190 -p 10055 -k "disk.status[xvda,wps]"10.00
边栏推荐
猜你喜欢
The tutor put forward 20 pieces of advice to help graduate students successfully complete their studies: first, don't plan to take a vacation
Cadence background color setting
Xml的(DTD,xml解析,xml建模)
vulnhub之cereal
Yintai department store ignites the city's "night economy"
鸿蒙第三次培训(项目实训)
牛牛的组队竞赛
《剑指offer 04》二维数组查找
Ripper of vulnhub
PHP Basics
随机推荐
量化计算调研
R language uses data The table package performs data aggregation statistics, calculates window statistics, calculates the median of sliding groups, and merges the generated statistical data into the o
外插散点数据
How PHP solves the problem of high concurrency
Go语言实现静态服务器
Keepalived中Master和Backup角色选举策略
Hongmeng fourth training
DS90UB949
The uniapp scroll view solves the problems of high adaptability and bullet frame rolling penetration.
Phpcms prompt message page Jump to showmessage
(database authorization - redis) summary of unauthorized access vulnerabilities in redis
vulnhub之momentum
vulnhub之presidential
牛牛的组队竞赛
GCC compilation process and dynamic link library and static link library
PHP基础
The tutor put forward 20 pieces of advice to help graduate students successfully complete their studies: first, don't plan to take a vacation
The R language uses the hist function in the native package (basic import package, graphics) to visualize the histogram plot
R language uses grid of gridextra package The array function combines multiple visual images of the lattice package horizontally, and the ncol parameter defines the number of columns of the combined g
简单工厂和工厂方法模式