一、需求
日志服务器两台,每台有两块磁盘,分别/data1,/data2
日志文件格式如下:/data2/logserver/logs/Online-2015-10-07*
规则:
1、每小时日志与前一小时上下波动在50%~200%范围,比如2015-10-07号,7点日志为120M,如果8点日志低于60M,或者高于240M,就可能异常了
2、有可能连续几个小时的日志都骤降,比如7点为120M,8点为10M,9点为11M,如果只对比9点和8点的,看不出异常,这时有必要检查前一天的9点日志大小
二、部署
1、写脚本
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
|
#!/bin/bash #####################main######################### Data1() { #Assignment time var iable
a=/data1/logserver/logs
logfile= "$a/UserInfo-$(date +%Y-%m-%d)"
now_time=`date +%H`
last_time=`date +%H -d "1 hours ago" `
now_logfile_size=`du -lb ${logfile}-${now_time}.log | awk '{print $1}' `
last_logfile_size=`du -lb ${logfile}-${last_time}.log| awk '{print $1}' `
if [ $last_logfile_size -ge `echo $last_logfile_size* 2 |bc` ] || [ $now_logfile_size -le `echo now_logfile_size/ 2 |bc` ]
then
echo 1
else
echo 0
fi
} Data2() { #Assignment time var iable
a=/data2/logserver/logs
logfile= "$a/UserInfo-$(date +%Y-%m-%d)"
now_time=`date +%H`
last_time=`date +%H -d "1 hours ago" `
now_logfile_size=`du -lb ${logfile}-${now_time}.log | awk '{print $1}' `
last_logfile_size=`du -lb ${logfile}-${last_time}.log| awk '{print $1}' `
if [ $last_logfile_size -ge `echo $last_logfile_size* 2 |bc` ] || [ $now_logfile_size -le `echo now_logfile_size/ 2 |bc` ]
then
echo 1
else
echo 0
fi
} $ 1
|
2、定义key值
1
2
3
4
|
[root@logserver1 script]# vim /etc/zabbix/zabbix_agentd.conf ########Log file monitoring UserParameter=log_file_data1,echo "`/usr/local/zabbix/script/logfile.sh Data1`"
UserParameter=log_file_data2,echo "`/usr/local/zabbix/script/logfile.sh Data2`"
|
3、回到zabbix登录界面定义item,然后定义报警阀值
本文转自 zouqingyun 51CTO博客,原文链接:http://blog.51cto.com/zouqingyun/1701485,如需转载请自行联系原作者