结合zabbix监控系统io相关性能服务

简介:

一、环境及说明

      本次实验基于CentOS6.x_x64  zabbix2.4.5(其实可以是其他版本的zabbix服务端),i测试的客户端机器:10.168.118.61(安装zabbix-agent的机器)上,所使用到的工具如下:

iostat来源于syssat软件包

#rpm -qa |grep sysstat

如果没有安装 请执行

#yum install sysstat -y


iostat 工具常用说明:

常用 $iostat -dxkt 1 输出选项说明:
rrqm/s 每秒进行merge的读操作数目。即delta(rmerge)/s
wrqm/s 每秒进行merge的写操作数目。即delta(wmerge)/s
r/s 每秒完成的读I/O设备次数。即delta(rio)/s
w/s 每秒完成的写I/O设备次数。即delta(wio)/s
rsec/s 每秒读扇区数。即delta(rsect)/s
wsec/s 每秒写扇区数。即delta(wsect)/s
rkB/s 每秒读K字节数。是rsect/s的一半,因为每扇区大小为512字节。(需要计算)
wkB/s 每秒写K字节数。是wsect/s的一半。(需要计算)
avgrq-sz 平均每次设备I/O操作的数据大小(扇区)。delta(rsect+wsect)/delta(rio+wio)
avgqu-sz 平均I/O队列长度。即delta(aveq)/s/1000(因为aveq的单位为毫秒)。
await 平均每次设备I/O操作的等待时间(毫秒)。即delta(ruse+wuse)/delta(rio+wio)
svctm 平均每次设备I/O操作的服务时间(毫秒)。即delta(use)/delta(rio+wio)
%util
一秒中有百分之多少的时间用于I/O操作,或者说一秒中有多少时间I/O队列是非空的。即delta(use)/s/10
00(因为use的单位为毫秒)


二、利用iostat -dxkt 1 手动监控disk io

1、编写发现磁盘的脚本 (shell):
$cd /etc/zabbix/bin
$cat disk_discovery.sh

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/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}\":\"${diskarray[$i]}\"}"
if  [ $i -lt $[$length-1] ]; then
printf  ','
fi
done
printf  "\n\t]\n"
printf  "}\n"
$ sh disk_discovery.sh
{
"data" :[
{ "{#DISK_NAME}" : "xvda" },
{ "{#DISK_NAME}" : "xvdb" }
]
}

2、编写获取磁盘I/O信息的脚本
nohup /usr/bin/iostat -dxkt 1 > /tmp/iostat_output 2>/dev/null &
运行并放入/etc/rc.local 临时解决方案,看后面添加 iostat sysv服务开机启动并定期清除
iostat_output文件大小
3、编写disk_status.sh脚本用于实时检测磁盘io
$cd /etc/zabbix/bin
$vim disk_status.sh

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#/bin/sh
device=$1
item=$2
case  $item  in
rrqm)
/usr/bin/tail  -n20  /tmp/iostat_output  | grep  "\b$device\b" | tail  -1| awk  '{print $2}'
;;
wrqm)
/usr/bin/tail  -n20  /tmp/iostat_output  | grep  "\b$device\b" | tail  -1| awk  '{print $3}'
;;
rps)
/usr/bin/tail  -n20  /tmp/iostat_output  | grep  "\b$device\b" | tail  -1| awk  '{print $4}'
;;
wps)
/usr/bin/tail  -n20  /tmp/iostat_output  | grep  "\b$device\b"  | tail  -1| awk  '{print
$5}'
;;
rKBps)
/usr/bin/tail  -n20  /tmp/iostat_output  | grep  "\b$device\b"  | tail  -1| awk  '{print
$6}'
;;
wKBps)
/usr/bin/tail  -n20  /tmp/iostat_output  | grep  "\b$device\b"  | tail  -1| awk  '{print
$7}'
;;
avgrq-sz)
/usr/bin/tail  -n20  /tmp/iostat_output  | grep  "\b$device\b"  | tail  -1| awk  '{print
$8}'
;;
avgqu-sz)
/usr/bin/tail  -n20  /tmp/iostat_output  | grep  "\b$device\b"  | tail  -1| awk  '{print
$9}'
;;
await)
/usr/bin/tail  -n20  /tmp/iostat_output  | grep  "\b$device\b"  | tail  -1| awk  '{print
$10}'
;;
svctm)
/usr/bin/tail  -n20  /tmp/iostat_output  | grep  "\b$device\b"  | tail  -1| awk  '{print
$11}'
;;
util)
/usr/bin/tail  -n20  /tmp/iostat_output  | grep  "\b$device\b"  | tail  -1| awk  '{print
$12}'
;;
esac

4、修改zabbix agent配置文件
cd /etc/zabbix/zabbix_agentd.d/
vim disk_status.conf

1
2
UserParameter=disk.discovery, /bin/bash  /etc/zabbix/bin/disk_discovery .sh
UserParameter=disk.status[*], /bin/bash  /ect/zabbix/bin/disk_status .sh $1 $2


重启zabbix agent

#service zabbix-agent restart

5、测试(zabbix server上):
$sudo zabbix_get -s 10.168.118.61 -k "disk.discovery"
{
"data":[
{
"{#DISK_NAME}":"xvda"
},
{
"{#DISK_NAME}":"xvdb"
}
]
}
如果能获得10.168.118.61上磁盘信息说明disk_discovery.sh脚本正确
$sudo zabbix_get -s 10.168.118.61 -k disk.status[xvda,wps]
10.00
如上能获取xvda盘的wps值说明disk_status.sh脚本正常

三、到zabbix server前端web上添加磁盘IO监控模板
configuration(中文叫组态) --Templates(模板)--选择一个你常用的模板(或先创建一个模块) Applications(应用集) --Create application(创建应用)输入名为 DISK_IO


Discovery -- Create discovery rule
Name:Disk_Discovery
Key:disk.discovery
Update interval(in sec):3600
Filters:{#DISK_NAME}
Name Key Interval
Item prototypes--Create item prototypes -- Write
requests merqed per second on {#DISK_NAME}
disk.status[{#DISK_NAME},wrqm] 60 90 120 Zabbix
agent DISK_IO Enabled
Write
requests issued per second to {#DISK_NAME} disk.status[{#DISK_NAME},wps] 60 90 120
Zabbix agent DISK_IO Enabled
Requests
average size(sectors) issued to {#DISK_NAME} disk.status[{#DISK_NAME},avgrq-sz] 60 90
120 Zabbix agent DISK_IO Enabled
Requests
average queue length issued to {#DISK_NAME} disk.status[{#DISK_NAME},avgqu-sz] 60 90
120 Zabbix agent DISK_IO Enabled
Read
requests merqed per second on{#DISK_NAME} disk.status[{#DISK_NAME},rrqm] 60 90 120
Zabbix agent DISK_IO Enabled
Read
requests issued per second to {#DISK_NAME} disk.status[{#DISK_NAME},rps] 60 90 120
Zabbix agent DISK_IO Enabled
I/O
requests average time(Miliseconds) issued to {#DISK_NAME} disk.status[{#DISK_NAME},await]
60 90 120 Zabbix agent DISK_IO Enabled
Bytes
written per second on {#DISK_NAME} disk.status[{#DISK_NAME},wKBps] 60 90 120 Zabbix
agent DISK_IO Enabled
Bytes
read per second on {#DISK_NAME} disk.status[{#DISK_NAME},rKBps] 60 90 120 Zabbix
agent DISK_IO Enabled
Bandwidth utilization for {#DISK_NAME} disk.status[{#DISK_NAME},util] 60 90 120 Zabbix
agent DISK_IO Enabled
在添加item的时候注意,由于使用的是iostat -k
获取每秒的读写大小,所以iostat显示的是以KB为单位,在zabbix上以B为基本单位,需要用到Use
custom multiplier 这个选项将zabbix agent返回的KB值乘以1024变成B,然后zabbix
agent再以B为单位显示成B或KB或MB便于查看。
以上的监控不能算完美,缺陷在于iostat_output文件大小会不断增长一般一个月差不多到1G,所以为了让
它开机能自动启动并能重置iostat_output文件大小大小,做成系统服务并添加到计划任务中,指定时间重
启,这样就会自动重置iostat_output文件大小

四、添加iostate系统服务并添加到计划任务
cat iostat

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/bin/sh
# chkconfig: - 99 11
# description: iostat
# processname: iostatus
# Author: san 2015-12-29
/etc/init .d /functions
iostat=${IOSTAT- /usr/bin/iostat }
prog=iostat
iostat_tmp= /tmp/iostat_output
pidfile=${PIDFILE- /var/run/iostat .pid}
lockfile=${LOCKFILE- /var/lock/subsys/iostat }
RETVAL=0
if  [ ! -f  "$iostat"  ]
then
echo  "iostat startup: command cannot found.cannot start."
exit  2
fi
start(){
if  [ ! -f ${pidfile} ];  then
echo  -n $ "Starting $prog:"
$iostat -dxkt 1 > $iostat_tmp 2> /dev/null  &
"$?"  - eq  0 ] && success $ "$base startup"  || failure $ "$base startup"
iostat_pid=$( ps  aux | grep  iostat| grep  dxkt | grep  - v  grep | awk  '{print $2}' )
echo  $iostat_pid >$pidfile
RETVAL=$?
echo
[ $RETVAL = 0 ] &&  touch  ${lockfile}
return  $RETVAL
else
status -p ${pidfile}
exit  0
fi
}
stop(){
echo  -n $ "Stoping $prog: "
killproc -p ${pidfile} iostat
RETVAL=$?
echo
[ $RETVAL = 0 ] &&  rm  -f ${lockfile} ${pidfile}
rm  -rf $iostat_tmp
}
case  "$1"  in
start)
start
;;
stop)
stop
;;
status)
status -p ${pidfile} $iostat
RETVAL=$?
;;
restart)
$0 stop
$0 start
;;
*)
echo  "Usage: iostat { start | stop | restart | status } "
exit  1
esac

添加到系统服务和开机自启

#chkconfig --add iostat

#chkconfig iostat on


#service iostat start
Starting iostat: [确定]
#service iostat status
iostat (pid 2810) 正在运行...
cat /tmp/iostat_output
-rw-r--r-- 1 root root 443M 1月 13 10:48 iostat_output
###运行13天 iostat_output文件大小
添加到计划任务中 每月1号1时1分重启iostat
$crontab -l
1 1 1 1 * service iostat restart
到此完美自动监控系统io










本文转自 dyc2005 51CTO博客,原文链接:http://blog.51cto.com/dyc2005/1943394,如需转载请自行联系原作者
目录
相关文章
|
5天前
|
监控 Linux
Zabbix 5.0 LTS的agent服务部署实战篇
文章介绍了如何在CentOS 7.6操作系统上部署Zabbix 5.0 LTS版本的agent服务,包括配置软件源、安装agent、修改配置文件、启动服务,并在Zabbix web界面添加监控。
20 4
Zabbix 5.0 LTS的agent服务部署实战篇
|
13天前
|
存储 Java 数据库连接
BIO阻塞IO流与数据存储大揭秘:性能与资源消耗,一文让你彻底解锁!
【8月更文挑战第25天】本文探讨了Java中BIO阻塞IO流与数据存储的概念及其实现。BIO作为一种传统IO模型,在处理每个客户端请求时需创建新线程并等待响应,这在并发量大时会导致性能下降和高资源消耗。示例代码展示了如何利用`ServerSocket`实现基于BIO的简单服务器。此外,文章还介绍了数据存储的基本方法,例如通过`BufferedWriter`向文件写入数据。两者对比显示,BIO适合连接数稳定的场景,而数据存储则适用于需要持久化保存信息的情况。通过这些分析和实例,希望能帮助读者更好地掌握这两种技术的应用场景及其优缺点。
25 0
|
6天前
crash —— 获取系统的磁盘IO统计数据
crash —— 获取系统的磁盘IO统计数据
|
2月前
|
Linux 数据处理 C语言
【Linux】基础IO----系统文件IO & 文件描述符fd & 重定向(下)
【Linux】基础IO----系统文件IO & 文件描述符fd & 重定向(下)
46 0
|
2月前
|
缓存 网络协议 算法
【Linux系统编程】深入剖析:四大IO模型机制与应用(阻塞、非阻塞、多路复用、信号驱动IO 全解读)
在Linux环境下,主要存在四种IO模型,它们分别是阻塞IO(Blocking IO)、非阻塞IO(Non-blocking IO)、IO多路复用(I/O Multiplexing)和异步IO(Asynchronous IO)。下面我将逐一介绍这些模型的定义:
105 1
|
2月前
|
Linux C语言 C++
【Linux】基础IO----系统文件IO & 文件描述符fd & 重定向(上)
【Linux】基础IO----系统文件IO & 文件描述符fd & 重定向(上)
33 0
|
3月前
|
Java 测试技术
Java IO流深度剖析:字节流和字符流的性能对比!
【6月更文挑战第26天】Java IO流分字节流和字符流,字节流处理所有类型数据(如图片),字符流处理文本(基于Unicode)。字节流直接处理,性能高,适合非文本文件;字符流处理文本时考虑编码,适合文本文件。性能测试显示,字节流在读写非文本文件时更快,而字符流在处理文本时更方便。选择流类型应依据数据类型和需求。
30 0
|
3月前
使用字节输入流报错 java.io.FileNotFoundException: srcdruid.properties (系统找不到指定的文件。)
使用字节输入流报错 java.io.FileNotFoundException: srcdruid.properties (系统找不到指定的文件。)
27 0
|
4月前
|
存储 SQL 监控
修改Zabbix源码实现监控数据双写,满足业务需求!
虽然对接Elasticsearch后有诸多好处,但是它不往数据库写历史数据了,同时还不再计算趋势数据了。有这么一个场景...
修改Zabbix源码实现监控数据双写,满足业务需求!
|
4月前
|
数据采集 监控 数据库
OceanBase社区版可以通过Zabbix监控
OceanBase社区版可以通过Zabbix监控
210 4