logstash轻松过滤海量日志,研究下logstash的其它插件,可以轻松监控日志并报警,爽歪歪了,直接附上脚本
监控说明:
1
2
3
|
1、sonp.php son-server.php 这两个URL小于100字节,状态码非200,报警 2、所有状态码非200,报警 3、所有请求超过10S,报警 |
邮件本机配置postfix或者sendmail,
监控脚本
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
|
input { redis {
host => "127.0.0.1"
port => "6379"
data_type => "list"
key => "logstash"
type => "redis-input"
codec => "json"
}
#我这里直接是从redis取出日志,上篇有介绍,当然也可以直接从日志文件取
} filter{ mutate { convert => [ "[bytes_read]" , "float" ]
#为了输出编码一致,我们这里将字节转成float
}
grok {
match => [ "message" , "sonp\.php|son-server\.php" ]
#日志中匹配的内容,
add_tag => [myurl]
} } output { if [response] != "200" or [request_time] >= 10 {
#监控状态码非200 或者 请求时间大于10s
exec {
command => "echo '%{@timestamp}: %{message}' | mail -s 'Log_error: request time or response' urname@urdomain"
}
}
if [bytes_read] < 100 and [response] != "200" {
#监控字节数小于100和请求非200
exec {
tags => [myurl]
command => "echo '%{@timestamp}: %{message}' | mail -s 'Log_error: bytes and response' urname@urdomain" }
} } |
1
|
#logstash/bin/logstash agent -f log_monitor.conf & |
后台启动脚本,静静等待邮件报警吧~~
本文转自 jackjiaxiong 51CTO博客,原文链接:http://blog.51cto.com/xiangcun168/1652252