当前位置:网站首页>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
边栏推荐
- POI excel cell wrap
- 软件测试周刊(第78期):你对未来越有信心,你对现在越有耐心。
- The uniapp scroll view solves the problems of high adaptability and bullet frame rolling penetration.
- PHP Basics
- Some common terms
- STL Tutorial 9 deep copy and shallow copy of container elements
- vulnhub之cereal
- R语言使用aggregate函数计算dataframe数据分组聚合的均值(sum)、不设置na.rm计算的结果、如果分组中包含缺失值NA则计算结果也为NA
- ftp登录时,报错“530 Login incorrect.Login failed”
- Stm32hal library upgrades firmware based on flash analog U disk (detailed explanation)
猜你喜欢
vulnhub之Ripper
After watching the video, AI model learned to play my world: cutting trees, making boxes, making stone picks, everything is good
抓包整理外篇fiddler———— 会话栏与过滤器[二]
rxjs Observable filter Operator 的实现原理介绍
ArcGIS应用(二十一)Arcmap删除图层指定要素的方法
The excel table is transferred to word, and the table does not exceed the edge paper range
The uniapp scroll view solves the problems of high adaptability and bullet frame rolling penetration.
牛牛的组队竞赛
鸿蒙第四次培训
小鹏 P7 撞护栏安全气囊未弹出,官方回应称撞击力度未达到弹出要求
随机推荐
剑指offer专项32-96题做题笔记
C language utf8toutf16 (UTF-8 characters are converted to hexadecimal encoding)
鸿蒙第三次培训(项目实训)
How to make others fear you
Program process management tool -go Supervisor
小鹏 P7 撞护栏安全气囊未弹出,官方回应称撞击力度未达到弹出要求
Ripper of vulnhub
简单工厂和工厂方法模式
Programmers' entrepreneurial trap: taking private jobs
MySQL searches and sorts out common methods according to time
Unity3D学习笔记5——创建子Mesh
After using the thread pool for so long, do you really know how to reasonably configure the number of threads?
Kibana - installation and configuration of kibana
R language ggplot2 visualization: gganimate package creates dynamic line graph animation (GIF) and uses transition_ The reveal function displays data step by step along a given dimension in the animat
Capturing and sorting out external Fiddler -- Conversation bar and filter [2]
R语言使用gridExtra包的grid.arrange函数将lattice包的多个可视化图像横向组合起来,ncol参数自定义组合图列数、nrow参数自定义组合图行数
vulnhub之Ripper
Software testing weekly (issue 78): the more confident you are about the future, the more patient you are about the present.
Use typora to draw flow chart, sequence diagram, sequence diagram, Gantt chart, etc. for detailed explanation
Using onvif protocol to operate the device