当前位置:网站首页>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
边栏推荐
- ASP.NET-酒店管理系統
- .\vmware-vdiskmanager.exe -k “c:\\xxxxx.vmdk”
- 2022 northeast four provinces match VP record / supplementary questions
- 鸿蒙第四次培训
- PHP server interacts with redis with a large number of close_ Wait analysis
- Multi dimensional monitoring: the data base of intelligent monitoring
- R语言使用gridExtra包的grid.arrange函数将ggplot2包的多个可视化图像横向组合起来,ncol参数自定义组合图列数、nrow参数自定义组合图行数
- uniapp实现点击加载更多
- DS90UB949
- ASP. Net hotel management system
猜你喜欢

2022 northeast four provinces match VP record / supplementary questions

Cadence background color setting

Viewing binary bin files with notepad++ editor

AI模型看看视频,就学会了玩《我的世界》:砍树、造箱子、制作石镐样样不差...

STL Tutorial 9 deep copy and shallow copy of container elements

Visual Studio 2022下载及配置OpenCV4.5.5

金额计算用 BigDecimal 就万无一失了?看看这五个坑吧~~

Web security summary

vulnhub之Ripper

vulnhub之Ripper
随机推荐
Ripper of vulnhub
【学习笔记】dp 状态与转移
Sheet1$.输出[Excel 源输出].列[XXX] 出错。返回的列状态是:“文本被截断,或者一个或多个字符在目标代码页中没有匹配项。”。
Unity3D学习笔记5——创建子Mesh
STL教程10-容器共性和使用场景
Hongmeng third training (project training)
How to make others fear you
错排问题 (抽奖,发邮件)
Kibana~Kibana的安装和配置
基于turtlebot3实现SLAM建图及自主导航仿真
C language AES encryption and decryption
Based on MCU, how to realize OTA differential upgrade with zero code and no development?
软件测试周刊(第78期):你对未来越有信心,你对现在越有耐心。
mysql使用update联表更新的方法
DS90UB949
(数据库提权——Redis)Redis未授权访问漏洞总结
在CoreOS下部署WordPress实例教程
vulnhub之Ripper
R语言使用gridExtra包的grid.arrange函数将lattice包的多个可视化图像横向组合起来,ncol参数自定义组合图列数、nrow参数自定义组合图行数
Xml的(DTD,xml解析,xml建模)