前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Zabbix-3.0.X 监测服务器硬盘IO状态

Zabbix-3.0.X 监测服务器硬盘IO状态

作者头像
shaonbean
发布2019-05-26 09:51:47
9690
发布2019-05-26 09:51:47
举报
文章被收录于专栏:运维前线运维前线

版权声明:本文为木偶人shaon原创文章,转载请注明原文地址,非常感谢。 https://cloud.tencent.com/developer/article/1434800

Zabbix-3.0监测服务器硬盘IO状态

一、环境准备

被监控主机已安装zabbix-agent,且zabbix-server能正常监控到zabbix-agent相关数据。

系统环境:

Zabbix-server:192.168.1.142

Zabbix-agent:192.168.1.156

Zabbix-agent安装目录在/opt/zabbix

二、解决思路

1、先在zabbix-agent上面通过zabbix的low-discovery功能自动发现服务器硬盘的名称。

2、通过脚本,利用iostat收集服务器硬盘的相关数据,保存到指定目录,并创建crontab,定时收集服务器硬盘IO数据,便于zabbix-web端绘图。

3、修改zabbix相关配置文件,使zabbix-agent能通过自定义的low-discovery获取硬盘的名称,同时zabbix-server能通过zabbix-get程序去zabbix-agent上面收集iostat脚本采集的zabbix-agent的硬盘IO数据。

4、到zabbix-web上面创建硬盘IO检测模板,并观察绘图数据,创建触发器。

三、详细步骤

1、Zabbix-agent端:

root@mysql-slave ~# cd /opt/zabbix/

root@mysql-slave zabbix# mkdir scripts #存放diskname_discovery脚本目录

root@mysql-slave zabbix# mkdir cron #存放采集硬盘IO数据的脚本目录

root@mysql-slave zabbix# mkdir data #存放脚本采集的硬盘IO数据目录

注:data目录在脚本中会自动创建,此处可以不手动创建。

ll查看zabbix目录下面都有哪些子目录。

root@mysql-slave zabbix# cd scripts/

root@mysql-slave scripts# vim diskname_discovery.sh #获取硬盘名称

root@mysql-slave scripts# bash diskname_discovery.sh

{

代码语言:txt
复制
    "data":[
代码语言:txt
复制
           {"{#DISK\_NAME}":"xvda"}
代码语言:txt
复制
    ]

}

#执行脚本已经能够获取硬盘名称,便于zabbix中进行宏调用。

#下面贴出脚本具体内容:

#!/bin/bash

function:monitor diskstatus from zabbix

License: GPL

author: shaon

version:1.0 date:2016-04-01

diskarray=($(grep '\ba-za-z+\b' /proc/diskstats|awk '{print $3}'))

length=${#diskarray@}

printf "{\n"

printf '\t'"\"data\":["

for ((i=0;i<$length;i++))

do

代码语言:txt
复制
      printf '\n\t\t{'
代码语言:txt
复制
      printf "\"{#DISK\_NAME}\":\"${diskarray[$i]}\"}"
代码语言:txt
复制
      if [ $i -lt $[$length-1] ];then
代码语言:txt
复制
              printf ','
代码语言:txt
复制
      fi

done

printf "\n\t]\n"

代码语言:txt
复制
   printf "}\n"

2、创建收集硬盘IO数据脚本

root@mysql-slave scripts# cd ../cron/

root@mysql-slave cron# vim iostat_cron.sh

下面贴出脚本具体信息:

#!/bin/bash

##################################

zabbix monitoring script

#auther: shaonbean

info:

- cron job to gather iostat data

- can not do real time as iostat data gathering will exceed

zabbix agent timeout

##################################

changelog:

20160519 vv initial creation

##################################

iostat_bin="/usr/bin/iostat"

frequency="10 2"

source data file

zabbix_base_dir=/opt/zabbix

-d $zabbix_base_dir/data || mkdir -p $zabbix_base_dir/data

dest_data=$zabbix_base_dir/data/iostat_data

tmp_data=$zabbix_base_dir/data/iostat_data.tmp

#script_conf=$zabbix_base_dir/conf/iostat_check.conf #iostat_check.conf为自定义的iostat 检测的频率,可自定义,此处可注释。

# -e "$script_conf" && source $script_conf

gather data in temp file first, then move to final location

it avoids zabbix-agent to gather data from a half written source file

iostat -kx 10 2 - will display 2 lines :

- 1st: statistics since boot -- useless

- 2nd: statistics over the last 10 sec

$iostat_bin -dxm $frequency > $tmp_data

mv $tmp_data $dest_data

3、把刚刚创建的脚本加到crontab中。

root@mysql-slave conf# crontab -e

zabbix cronjob for application

*/1 * * * * /bin/bash /opt/zabbix/cron/iostat_cron.sh

4、修改zabbix-agnet的相关配置文件

root@mysql-slave conf# cd /opt/zabbix/etc/

root@mysql-slave etc# egrep -v "^#|^$" zabbix_agentd.conf

PidFile=/opt/zabbix/pid/zabbix_agentd.pid

LogFile=/var/log/zabbix/zabbix_agentd.log

Server=127.0.0.1,192.168.1.142 #被动模式,server为zabbix-server ip

ServerActive=192.168.1.142:10051 #主动模式

Hostname=mysql-slave #使用主动模式收集数据并发送到zabbix-server时开启,被动模式不需要这个参数,注释掉。

Timeout=5

Include=/opt/zabbix/etc/zabbix_agentd.conf.d/ #存放zabbix-server需要使用的配置文件目录

UnsafeUserParameters=1 #开启之后,可以使用自定义的脚本收集zabbix-agent的数据。

Option: UnsafeUserParameters

Allow all characters to be passed in arguments to user-defined parameters.

The following characters are not allowed:

\ ' " ` * ? { } ~ $ ! & ; ( ) < > | # @

Additionally, newline characters are not allowed.

0 - do not allow

1 - allow

Mandatory: no

Range: 0-1

Default:

#UnsafeUserParameters=0

5、新建自定义的配置文件

root@mysql-slave etc# cd /opt/zabbix/etc/zabbix_agentd.conf.d/

下面贴出配置文件内容:

#diskname discovery

UserParameter=disk.name.discovery*,/opt/zabbix/scripts/diskname_discovery.sh $1

#gather iostat value

UserParameter=io.rrqmps*,/usr/bin/tail /opt/zabbix/data/iostat_data |grep "\b$1\b"|tail -1|awk '{print $$3}'

UserParameter=io.wrqmps*,/usr/bin/tail /opt/zabbix/data/iostat_data |grep "\b$1\b"|tail -1|awk '{print $$3}'

UserParameter=io.rps*,/usr/bin/tail /opt/zabbix/data/iostat_data |grep "\b$1\b"|tail -1|awk '{print $$4}'

UserParameter=io.wps*,/usr/bin/tail /opt/zabbix/data/iostat_data |grep "\b$1\b" |tail -1|awk '{print $$5}'

UserParameter=io.rMBps*,/usr/bin/tail /opt/zabbix/data/iostat_data |grep "\b$1\b" |tail -1|awk '{print $$6}'

UserParameter=io.wMBps*,/usr/bin/tail /opt/zabbix/data/iostat_data |grep "\b$1\b" |tail -1|awk '{print $$7}'

UserParameter=io.avgrq-sz*,/usr/bin/tail /opt/zabbix/data/iostat_data |grep "\b$1\b" |tail -1|awk '{print $$8}'

UserParameter=io.avgqu-sz*,/usr/bin/tail /opt/zabbix/data/iostat_data |grep "\b$1\b" |tail -1|awk '{print $$9}'

UserParameter=io.await*,/usr/bin/tail /opt/zabbix/data/iostat_data |grep "\b$1\b" |tail -1|awk '{print $$10}'

UserParameter=io.svctm*,/usr/bin/tail /opt/zabbix/data/iostat_data |grep "\b$1\b" |tail -1|awk '{print $$11}'

UserParameter=io.util*,/usr/bin/tail /opt/zabbix/data/iostat_data |grep "\b$1\b" |tail -1|awk '{print $$12}'

################

#rrqm/S: merge number of read operations per second. Delta(rmerge)/s

#wrqm/S: per second operation number and write merge. Delta(wmerge)/s

#r/Read the I/O device s: completion times per second. Delta(rio)/s

#w/S: finished writing I/O times per second. Delta(wio)/s

#rsec/S: read the number of sectors per second. Delta(rsect)/s

#wsec/S: write the number of sectors per second. Delta(wsect)/s

#rkB/S: read K bytes per second. Is rsect/Half of the s, because each sector size of 512 bytes. (calculated)

#wkB/S: write K bytes per second. Is wsect/Half s. (calculated)

#avgrqAverage -sz: per I/O device data size (sector). delta(rsect+wsect)/delta(rio+wio)

#avgqu-sz: I/O average queue length. Delta(aveq)/s/1000 (because the aveq milliseconds).

#Average await: per device I/The waiting time of O operation (MS). Delta(ruse+wuse)/delta(rio+wio)

#Average svctm: per device I/The O operation business hours (MS). Delta(use)/delta(rio+wio)

6、本地测试相关功能

root@mysql-slave etc# cd /opt/zabbix/bin/

root@mysql-slave bin# ./zabbix_get -s 127.0.0.1 -p 10050 -k disk.name.discovery

下面能看到我们自定义的key已经能够使用

然后根据/opt/zabbix/etc/zabbix_agentd.conf.d目录下面的配置文件测试具体key的使用:

root@mysql-slave bin# ./zabbix_get -s 127.0.0.1 -p 10050 -k io.utilxvda

可以看到,通过自定义的key可以正常取值。

分步取值:

查看脚本收集到的硬盘IO状态详细数据,如下图:

然后通过下面命令获取具体硬盘IO各项参数的数值:

root@mysql-slave ~# /usr/bin/tail /opt/zabbix/data/iostat_data | grep "\bxvda\b" | tail -1 | awk '{print $12}'

这里取得是util的数据,$1代表自动发现的硬盘名称。其他参数取值参考util即可。

Zabbix-server:服务端

/opt/zabbix/bin/zabbix_get -s 192.168.1.156 -p 10050 -k io.utilxvda

能够看出在zabbix-server已经能够通过自定义的key及发现函数,实现zabbix-agent硬盘IO状态的数据采集,

四、zabbix-web前端设置

创建硬盘IO状态检测模板,自定义,不多说

下一步,创建发现规则:

创建完成,然后添加监控项以及触发器,并创建相关图形,便于查看,

添加完成如图:

设置触发器;

添加图形显示;

查看硬盘IO的状态变化图:

下面导出检测模板,可以根据不同的需求自定义相关参数。

由于模板格式问题,所以相关模板及脚本到

https://github.com/wh211212/vdevops-zabbix 下载

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2016年10月04日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • function:monitor diskstatus from zabbix
  • License: GPL
  • author: shaon
  • version:1.0 date:2016-04-01
  • zabbix monitoring script
  • info:
  • - cron job to gather iostat data
  • - can not do real time as iostat data gathering will exceed
  • zabbix agent timeout
  • changelog:
  • 20160519 vv initial creation
  • source data file
  • gather data in temp file first, then move to final location
  • it avoids zabbix-agent to gather data from a half written source file
  • iostat -kx 10 2 - will display 2 lines :
  • - 1st: statistics since boot -- useless
  • - 2nd: statistics over the last 10 sec
  • zabbix cronjob for application
    • Option: UnsafeUserParameters
    • Allow all characters to be passed in arguments to user-defined parameters.
    • The following characters are not allowed:
    • \ ' " ` * ? { } ~ $ ! & ; ( ) < > | # @
    • Additionally, newline characters are not allowed.
    • 0 - do not allow
    • 1 - allow
    • Mandatory: no
    • Range: 0-1
    • Default:
    相关产品与服务
    云数据库 SQL Server
    腾讯云数据库 SQL Server (TencentDB for SQL Server)是业界最常用的商用数据库之一,对基于 Windows 架构的应用程序具有完美的支持。TencentDB for SQL Server 拥有微软正版授权,可持续为用户提供最新的功能,避免未授权使用软件的风险。具有即开即用、稳定可靠、安全运行、弹性扩缩等特点。
    领券
    问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档