add error collector demo using logstash + ElasticSearch + Kibana.
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
input {
|
||||
file { # 这个是因为1.2.1/1.2.2的一个bug, https://logstash.jira.com/browse/LOGSTASH-1310,可忽略此配置
|
||||
path => "/dev/null" # ...
|
||||
} # ...
|
||||
tcp {
|
||||
host => "127.0.0.1"
|
||||
port => 6868
|
||||
mode => "server"
|
||||
type => "showcase"
|
||||
debug => true
|
||||
codec => "plain" # 注意,TCP input的codec和TCP output的codec一定要一致,但现在1.2.2版本里的默认codec是不一致的!所以最好是自己定义.
|
||||
}
|
||||
}
|
||||
|
||||
output {
|
||||
file {
|
||||
path => "showcase_error.log" # 将所有收集到的错误日志统一输出到一个日志文件中
|
||||
message_format => "%{message}"
|
||||
}
|
||||
elasticsearch { embedded => true } # 同时将错误日志输出到ElasticSearch, 方便具体错误查找和统计
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
java -jar ../logstash-1.2.2-flatjar.jar agent -f collector.conf -- web
|
||||
|
||||
pause;
|
||||
@@ -0,0 +1,30 @@
|
||||
input {
|
||||
file {
|
||||
path => "C:\Neway\code\springside4\examples\showcase\logs\showcase.log" # 这里只能是绝对路径,logstash不认相对路径
|
||||
type => "showcase"
|
||||
codec => multiline { # 将Exception打印出来的stacktrace拼接成一条日志记录
|
||||
pattern => "^\s"
|
||||
what => "previous"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
filter {
|
||||
if [type] != "showcase" or [message] !~ /(ERROR)|(^.+Exception: .+)|(^\s+at .+)|(^\?s+... \d+ more)|(^\s*Caused by:.+)/{
|
||||
drop {} # 将非错误日志过滤掉
|
||||
}
|
||||
|
||||
mutate {
|
||||
replace => [ "message", "[%{host}]-%{message}" ] # 将产生日志的host记录在日志记录中
|
||||
}
|
||||
}
|
||||
|
||||
output {
|
||||
tcp {
|
||||
host => "127.0.0.1"
|
||||
port => 6868
|
||||
codec => plain { # 注意,TCP input的codec和TCP output的codec一定要一致,但现在1.2.2版本里的默认codec是不一致的!所以最好是自己定义.
|
||||
format => "[%{host}]-%{message}" # 设置output的格式, 将主机名和日志一起output到TCP, 默认格式会在原日志message的基础上添加logstash处理这条日志的时间戳和主机名
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
java -jar ../logstash-1.2.2-flatjar.jar agent -f shipper.conf
|
||||
|
||||
pause;
|
||||
Reference in New Issue
Block a user