天天看点

zabbix 系统IO监控

#  软件介绍 iostat

# 使用iostat 需先安装sysstat软件包, 系统包中有带

# 系统: centos,rh 6-7都可以

   zabbix版本: 3.0 3.2 可以 其它版本没有试过

# iostat用于输出CPU和磁盘I/O相关统计信息

# iostat可以显示CPU和I/O系统的负载情况及分区状态信息. 

直接执行iostat可以显示下面内容:

[wmt@template ~]$ iostat 

Linux 2.6.32-358.el6.x86_64 (template.xx.xx) 07/14/2017 _x86_64_(32 CPU)

avg-cpu:  %user   %nice %system %iowait  %steal   %idle

           2.93    0.00    0.20    0.04    0.00   96.83

Device:            tps   Blk_read/s   Blk_wrtn/s   Blk_read   Blk_wrtn

sda               0.66         6.60        14.79  462593198 1036802588

sdc               0.20         1.60         0.00  112173840          0

sdb              25.46       453.65       582.45 31805540026 40835922808

scd0              0.00         0.00         0.00       5012          0

dm-0             25.21       453.64       582.45 31805251514 40835922808

dm-1              1.89         6.35        14.55  445409130 1020026016

dm-2              0.06         0.24         0.24   17154880   16776296

# cpu段配置说明

avg-cpu 

%user: 用户空间使用CPU百分比

%nice : nice使用

%system : 系统(kernel)使用cpu百分比

%iowait : cpu等待硬盘I/O时,所占用的百分比

%steal  : 系统偷出CPU的百分比 (不知道什么鬼,求解释)

%idle: 系统空闲百分比

# Device磁盘段配置说明 

tps: 每秒钟发送到I/O请求数

Blk_read/s: 每秒从磁盘读出的的数据量,单位B

Blk_wrtn/s: 每秒从磁盘写入的的数据量,单位B

Blk_read: 开机始从磁盘读出的数据总量

Blk_wrtn: 开机始从磁盘写入的数据总量

# 命令使用

  iostat 1   # 每秒刷新一次

  iostat -k  # 以KB为单位 默认B

  iostat -m  # 以MB为单位

  iostat -v  # 显示版本号

  iostat -c  # 仅显示CPU

  iostat -d  # 仅显示磁盘

##################  dm设备监控大概思路    ##################################

#查看dm对应设备号是哪一个

[root@template ~]# dmsetup ls

mpathb(253:0)

vg_sys-LogVol01(253:1)

vg_sys-LogVol00(253:2)

# 找到设备号对应信息

[root@template ~]# ll /dev/mapper/

total 0

crw-rw----. 1 root root 10, 58 Apr 25  2015 control

lrwxrwxrwx. 1 root root      7 Apr 25  2015 mpathb -> ../dm-0

lrwxrwxrwx. 1 root root      7 Apr 25  2015 vg_sys-LogVol00 -> ../dm-2

lrwxrwxrwx. 1 root root      7 Apr 25  2015 vg_sys-LogVol01 -> ../dm-1

# 再检查设备挂载目录,比如swap就可不用监控,一般也不会往里写入数据

[root@template ~]# cat /etc/fstab 

#

# /etc/fstab

# Created by anaconda on Sat Apr 25 01:09:22 2015

/dev/mapper/vg_sys-LogVol01 /                       ext4    defaults        1 1

/dev/mapper/vg_sys-LogVol00 swap                    swap    defaults        0 0

/dev/mapper/mpathb/homeext4defaults1 0

##################### zabbix 配置   ##################### 

###############  在需要监控的机器中增加这个脚本 #########################

# 计划脚本文件

<code>&lt;br data-filtered=</code><code>"filtered"</code><code>&gt;</code>

################ 配置配合 计划任务每20秒更新一次 ###################

#!/bin/bash

#   Name:iostat 只升不降,取出iostst最新io写入写出 

#   Version Number:1.01

#   Type:服务启动脚本 

#   Language:bash shell  

#   Date:2017-07-17

#   Author:xiong

# 每隔多少秒刷新一次iostat,默认的那个值只降不升  

iostat -xdtk 5 3 &gt; /tmp/iostst_temp.txt

# 取出现在时间

times=`date  "+%Y"年0"%h%d"日" %H"时"%M"分"%S"秒""`

# 取出最后一次iostat更新的数据,为最新数据,将最新的数据更新至/tmp/2.txt 不输出

grep "$times" -A 100 /tmp/iostst_temp.txt  &gt; /tmp/iostst_temp2.txt

# 时间格式: 07/17/2017 03:03:06 PM

# times=`date "+%D %r"`   

# 时间格式: 2017年07月17日 15时01分03秒

# times=`date  "+%Y"年0"%h%d"日" %H"时"%M"分"%S"秒""`

# 计划任务:每一分钟执行一次

*/1 * * * * /bin/bash /usr/local/zabbix/script/iostate.sh

# 内容导出如下 

Device:         rrqm/s   wrqm/s     r/s     w/s    rkB/s    wkB/s avgrq-sz avgqu-sz   await r_await w_await  svctm  %util

sda               0.00     0.00    0.00    0.00     0.00     0.00     0.00     0.00    0.00    0.00    0.00   0.00   0.00

#  配置介绍 

rrqm/s: 每秒进行 merge 的读操作数目。即 rmerge/s

wrqm/s: 每秒进行 merge 的写操作数目。即 wmerge/s

r/s: 每秒完成的读 I/O 设备次数。即 rio/s

w/s: 每秒完成的写 I/O 设备次数。即 wio/s

rsec/s: 每秒读扇区数。即 rsect/s

wsec/s: 每秒写扇区数。即 wsect/s

rkB/s: 每秒读K字节数。是 rsect/s 的一半,因为每扇区大小为512字节。

wkB/s: 每秒写K字节数。是 wsect/s 的一半。

avgrq-sz: 平均每次设备I/O操作的数据大小 (扇区)。

avgqu-sz: 平均I/O队列长度。

await: 平均每次设备I/O操作的等待时间 (毫秒)。

svctm: 平均每次设备I/O操作的服务时间 (毫秒)。

%util: 一秒中有百分之多少的时间用于 I/O 操作,即被io消耗的cpu百分比

# 在zabbix_agent中增加一个脚本 

<code>#############################  zabbix脚本 ###########################</code>

<code>#!/bin/bash</code>

<code>#</code>

<code>disk=$1</code>

<code>case</code> <code>$2 </code><code>in</code>

<code>rrqm)</code>

<code>        </code><code>grep</code> <code>"$disk"</code> <code>/tmp/iostst_temp2</code><code>.txt | </code><code>awk</code> <code>'{print $2}'</code> <code>;;</code>

<code>wrqm)</code>

<code>        </code><code>grep</code> <code>"$disk"</code> <code>/tmp/iostst_temp2</code><code>.txt | </code><code>awk</code> <code>'{print $3}'</code> <code>;;</code>

<code>read</code><code>)</code>

<code>        </code><code>grep</code> <code>"$disk"</code> <code>/tmp/iostst_temp2</code><code>.txt | </code><code>awk</code> <code>'{print $4}'</code> <code>;;</code>

<code>wirte)</code>

<code>        </code><code>grep</code> <code>"$disk"</code> <code>/tmp/iostst_temp2</code><code>.txt | </code><code>awk</code> <code>'{print $5}'</code> <code>;;</code>

<code>readin)</code>

<code>        </code><code>grep</code> <code>"$disk"</code> <code>/tmp/iostst_temp2</code><code>.txt | </code><code>awk</code> <code>'{print $6}'</code> <code>;;</code>

<code>wirtein)</code>

<code>        </code><code>grep</code> <code>"$disk"</code> <code>/tmp/iostst_temp2</code><code>.txt | </code><code>awk</code> <code>'{print $7}'</code> <code>;;</code>

<code>avgrqsz)</code>

<code>        </code><code>grep</code> <code>"$disk"</code> <code>/tmp/iostst_temp2</code><code>.txt | </code><code>awk</code> <code>'{print $8}'</code> <code>;;</code>

<code>avgqusz)</code>

<code>        </code><code>grep</code> <code>"$disk"</code> <code>/tmp/iostst_temp2</code><code>.txt | </code><code>awk</code> <code>'{print $9}'</code> <code>;;</code>

<code>await)</code>

<code>        </code><code>grep</code> <code>"$disk"</code> <code>/tmp/iostst_temp2</code><code>.txt | </code><code>awk</code> <code>'{print $10}'</code> <code>;;</code>

<code>rawait)</code>

<code>        </code><code>grep</code> <code>"$disk"</code> <code>/tmp/iostst_temp2</code><code>.txt | </code><code>awk</code> <code>'{print $11}'</code> <code>;;</code>

<code>wawait)</code>

<code>        </code><code>grep</code> <code>"$disk"</code> <code>/tmp/iostst_temp2</code><code>.txt | </code><code>awk</code> <code>'{print $12}'</code> <code>;;</code>

<code>svctm)</code>

<code>        </code><code>grep</code> <code>"$disk"</code> <code>/tmp/iostst_temp2</code><code>.txt | </code><code>awk</code> <code>'{print $13}'</code> <code>;;</code>

<code>util)</code>

<code>        </code><code>grep</code> <code>"$disk"</code> <code>/tmp/iostst_temp2</code><code>.txt | </code><code>awk</code> <code>'{print $14}'</code> <code>;;</code>

<code>*)</code>

<code>        </code><code>echo</code> <code>"使用方法  /bash disk_name $2"</code> 

<code>        </code><code>exit</code> <code>5 ;;</code>

<code>esac</code>

# 最后需要配置文件中在zabbix_agentd.conf中增加这行

UserParameter=sys.io[*],/usr/local/zabbix/script/system_io.sh $1 $2

# 在服务器端测试是脚本是否可以

[root@zabbixd bin]# zabbix_get -s ipaddress -p port -k sys.io[sdb,wawait]

0.0

[root@zabbixd bin]# zabbix_get -s ipaddress -p port -k sys.io[sdb,wrtn]

# 可能会报权限错误,需要增加权限 chmod +x /bin/bash /usr/local/zabbix/script/iostate.sh

#    以及在增加属主属组权限  chown zabbix.zabbix !$

扩展:dm设备详解  http://blog.chinaunix.net/uid-26230811-id-3265484.html

#     另一种监控方式,文本没看太明白,另一种思路

                    http://blog.csdn.net/tenfyguo/article/details/7477526

#  模板如下,自动发现需要定义API,不太熟,练习中,有多个磁盘需要监控的话,直接将模板导出,然后将模板名称更换一下需要的,然后在导入就行了,模板如下:

#   模板请直接下载附件

#最后在加上一个效果图

<a href="https://s1.51cto.com/wyfs02/M01/9C/21/wKiom1lseLySzK_BAAD-vES0PDk516.png" target="_blank"></a>

# 最后有问题的话,底下留言

<a href="http://down.51cto.com/data/2366859" target="_blank">附件:http://down.51cto.com/data/2366859</a>

     本文转自812374156 51CTO博客,原文链接:http://blog.51cto.com/xiong51/1947663,如需转载请自行联系原作者