Skip to content

Instantly share code, notes, and snippets.

@xizhibei
Created October 26, 2016 11:23
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save xizhibei/081444ea66dbf527624b4d53b635f9bd to your computer and use it in GitHub Desktop.
Save xizhibei/081444ea66dbf527624b4d53b635f9bd to your computer and use it in GitHub Desktop.
mongodb log logstash grok filter
filter {
if [type] == "mongo-log" {
grok {
match => {"message" => "%{TIMESTAMP_ISO8601:timestamp}\s+%{MONGO3_SEVERITY:severity}\s+%{MONGO3_COMPONENT:component}\s+(?:\[%{DATA:context}\])?\s+%{GREEDYDATA:message}"}
overwrite => [ "message" ]
remove_tag => ["beats_input_codec_plain_applied"]
}
if [context] =~ "^conn" {
grok {
match => {"context" => "conn%{NUMBER:connect_id:int}"}
}
}
if [message] =~ "ms$" {
grok {
match => {"message" => "%{WORD:op_type}\s+.*}.*\}(\s+%{NUMBER:spend_time:int}ms$)?"}
}
}
if [message] =~ "^end\s+connection" {
grok {
match => {"message" => "end\s+connection\s+%{IPORHOST:client_ip}:%{NUMBER:client_port:int}.*"}
add_tag => ["end_connection"]
}
}
if [message] =~ "^connection\s+accepted\s+from" { grok {
match => {"message" => "connection\s+accepted\s+from\s+%{IPORHOST:client_ip}:%{NUMBER:client_port:int}\s+#%{NUMBER:connect_id:int}.*"} add_tag => ["start_connection"]
} }
date {
match => [ "timestamp", "UNIX", "YYYY-MM-dd HH:mm:ss", "ISO8601"]
remove_field => [ "timestamp" ]
}
}
}
@aymenoss1
Copy link

Hello Xu, you used which pattern for that, I can't see any?

@zeeshan-siddiquie
Copy link

Hi,

This is not working

@slashlinux
Copy link

For me is working.. good job

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment