码迷,mamicode.com
首页 > 其他好文 > 详细

logstash2.2.0过滤tomcat日志

时间:2016-04-14 18:09:14      阅读:526      评论:0      收藏:0      [点我收藏+]

标签:file   error   filter   previous   

input {
   file {
	type => "java-err"
	path => "/fsmeeting/tomcat-service/logs/catalina.out"
	tags => "java-err"
	codec => multiline {
	   pattern => "^%{TIMESTAMP_ISO8601}"
	   negate => true
	   what => "previous"
	}
   }
}

filter {
   if [type] == "java-err" {
	grok {
	   match => { "message" => "%{TIMESTAMP_ISO8601:date} \[(?<thread_name>.+?)\]-\[(?<log_level>\w+)\]\s*(?<content>.*)"}
	}
	mutate {
	   remove_field => "content"
	}
	if [log_level] != "ERROR" {
	  	drop {}
	}
   }
}

output {
   elasticsearch {
	host => "192.168.5.231"
	protocol => "http"
	index => "java-err-%{+YYYY.MM.dd}"
   }
   email {
        body => "%{message}"
        from => "xxxxxxx"
        contenttype => "text/plain; charset=UTF-8"
        options => [
                "smtpIporHost", "smtp.sina.com",
                "userName", "xxxxxxx",
                "password", "*********",
                "authenticationType", "login"
        ]
        subject => "服务器%{host} %{type}日志异常"
        to => "xxxxxxxx"
   }
}




去重发日志:

input {
   file {
	type => "java-err"
	path => "/fsmeeting/tomcat-service/logs/catalina.out"
	tags => "java-err"
	codec => multiline {
	   pattern => "^%{TIMESTAMP_ISO8601}"
	   negate => true
	   what => "previous"
	}
   }
}

filter {
   if [type] == "java-err" {
	grok {
	   match => { "message" => "%{TIMESTAMP_ISO8601:date} \[(?<thread_name>.+?)\]-\[(?<log_level>\w+)\]\s*(?<content>.*)"}
	}
	mutate {
	   remove_field => "content"
	}
	if [log_level] == "ERROR" {
           throttle {
                after_count => 2
                key => "%{content}"
                add_tag => "throttled"
           }
	}
	if [log_level] != "ERROR" {
	  	drop {}
	}
   }
}

output {
   elasticsearch {
	host => "192.168.5.231"
	protocol => "http"
	index => "java-err-%{+YYYY.MM.dd}"
   }
   if "throttled" not in [tags] and [type] == "java-err" and [log_level] == "ERROR" 
   email {
        body => "%{message}"
        from => "xxxxxxx"
        contenttype => "text/plain; charset=UTF-8"
        options => [
                "smtpIporHost", "smtp.sina.com",
                "userName", "xxxxxxx",
                "password", "*********",
                "authenticationType", "login"
        ]
        subject => "服务器%{host} %{type}日志异常"
        to => "xxxxxxxx"
   }
   }
}


本文出自 “清晰明了” 博客,请务必保留此出处http://duanyexuanmu.blog.51cto.com/1010786/1763840

logstash2.2.0过滤tomcat日志

标签:file   error   filter   previous   

原文地址:http://duanyexuanmu.blog.51cto.com/1010786/1763840

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!