当前位置:网站首页>利用Zabbix动态监控磁盘I/O
利用Zabbix动态监控磁盘I/O
2022-07-03 11:02:00 【星哥玩云】
最近在看Linux I/O子系统相关的资料,需要监控每台服务器的磁盘I/O,特别是MongoDB数据库服务器的磁盘I/O,由于每台服务器的磁盘名称可能不一样,所以需要用到Zabbix的LLD功能来发现磁盘并监控I/O
参考文章
http://www.programering.com/a/MDOwYDNwATc.html
1.编写发现磁盘的脚步
shell版本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版本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.编写获取磁盘I/O信息的脚本
使用iostat收集磁盘I/O信息
#/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.修改Zabbix agent配置文件
添加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
这里需要注意,Zabbix agent默认的Timeout值为3秒,由于这里使用iostat -ydxkt 1 3,每隔1秒刷新一次,刷新3次,所以如果获取磁盘信息Timeout设置时间短了的话会出现ZBX_NOTSUPPORTED这样的错误
然后重新加载zabbix agent
4.通过在zabbix server或zabbix proxy端使用zabbix_get获取磁盘信息
$ /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
边栏推荐
- Programmers' entrepreneurial trap: taking private jobs
- Program process management tool -go Supervisor
- R语言使用data.table包进行数据聚合统计计算滑动窗口统计值(Window Statistics)、计算滑动分组中位数(median)并合并生成的统计数据到原数据集中
- Gut | 香港中文大学于君组揭示吸烟改变肠道菌群并促进结直肠癌(不要吸烟)
- POI excel cell wrap
- Gut | Yu Jun group of the Chinese University of Hong Kong revealed that smoking changes intestinal flora and promotes colorectal cancer (do not smoke)
- Yintai department store ignites the city's "night economy"
- Visual Studio 2022下载及配置OpenCV4.5.5
- R language uses the aggregate function to calculate the mean value (sum) of dataframe data grouping aggregation without setting na The result of RM calculation. If the group contains the missing value
- MySQL union和union all区别
猜你喜欢
Processes and threads
Cadence background color setting
Yintai department store ignites the city's "night economy"
After watching the video, AI model learned to play my world: cutting trees, making boxes, making stone picks, everything is good
Intel 13th generation core flagship exposure, single core 5.5ghz
用了这么久线程池,你真的知道如何合理配置线程数吗?
uniapp scroll view 解决高度自适应、弹框滚动穿透等问题。
STL教程10-容器共性和使用场景
金额计算用 BigDecimal 就万无一失了?看看这五个坑吧~~
Numpy np. Max and np Maximum implements the relu function
随机推荐
Encapsulate a koa distributed locking middleware to solve the problem of idempotent or repeated requests
How to make others fear you
How to clean up v$rman_ backup_ job_ Details view reports error ora-02030
.\vmware-vdiskmanager.exe -k “c:\\xxxxx.vmdk”
Phpcms prompt message page Jump showmessage
Yintai department store ignites the city's "night economy"
MATLAB提取不規則txt文件中的數值數據(簡單且實用)
同事写了一个责任链模式,bug无数...
MCDF实验1
[OBS] configFile in ini format of OBS
Nestjs configuration service, configuring cookies and sessions
Double linked list of linear list
Excel表格转到Word中,表格不超边缘纸张范围
Mysql根据时间搜索常用方法整理
Redis things
Qt+VTK+OCCT读取IGES/STEP模型
Application of high-precision indoor positioning technology in safety management of smart factory
How to become a senior digital IC Design Engineer (1-5) Verilog coding syntax: operand
Kubernetes 三打探针及探针方式
Multi dimensional monitoring: the data base of intelligent monitoring