当前位置:网站首页>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
边栏推荐
- 机器学习 3.2 决策树模型 学习笔记(待补)
- Excel表格转到Word中,表格不超边缘纸张范围
- How to get started embedded future development direction of embedded
- 优化接口性能
- 量化计算调研
- vulnhub之momentum
- The uniapp scroll view solves the problems of high adaptability and bullet frame rolling penetration.
- 836. 合并集合(DAY 63)并查集
- C language AES encryption and decryption
- 剑指offer专项32-96题做题笔记
猜你喜欢
随机推荐
P3250 [hnoi2016] Network + [necpc2022] f.tree path tree section + segment tree maintenance heap
Gut | Yu Jun group of the Chinese University of Hong Kong revealed that smoking changes intestinal flora and promotes colorectal cancer (do not smoke)
ORACLE进阶(一) 通过EXPDP IMPDP命令实现导dmp
Using onvif protocol to operate the device
软件测试周刊(第78期):你对未来越有信心,你对现在越有耐心。
简单工厂和工厂方法模式
【学习笔记】dp 状态与转移
聊聊Flink框架中的状态管理机制
鸿蒙第三次培训(项目实训)
Excel quick cross table copy and paste
R语言ggplot2可视化:gganimate包创建动态折线图动画(gif)、使用transition_reveal函数在动画中沿给定维度逐步显示数据、在折线移动方向添加数据点
.\vmware-vdiskmanager.exe -k “c:\\xxxxx.vmdk”
Program process management tool -go Supervisor
Programmers' entrepreneurial trap: taking private jobs
How should intermediate software designers prepare for the soft test
Numpy np. Max and np Maximum implements the relu function
小鹏 P7 撞护栏安全气囊未弹出,官方回应称撞击力度未达到弹出要求
R language uses grid of gridextra package The array function combines multiple visual images of the ggplot2 package horizontally, and the ncol parameter defines the number of columns of the combined g
R语言使用data.table包进行数据聚合统计计算滑动窗口统计值(Window Statistics)、计算滑动分组中位数(median)并合并生成的统计数据到原数据集中
STL教程8-map









