Skip to content

Instantly share code, notes, and snippets.

@HaVonTe1
Last active October 9, 2015 12:17
Show Gist options
  • Save HaVonTe1/f3dcbd7ff2386d9b1660 to your computer and use it in GitHub Desktop.
Save HaVonTe1/f3dcbd7ff2386d9b1660 to your computer and use it in GitHub Desktop.
logstash for mongostats
filter {
if [type] == "mongostat" {
grok {
patterns_dir => "/etc/logstash/patterns"
match => ["message","%{HOSTNAME:host}:%{INT:port} %{INSERT}%{QUERY}%{UPDATE}%{DELETE}%{GETMORE}%{SPACE}%{NUMBER:mongoCommand}\|%{NUMBER:mongoReplCommand}%{SPACE}%{NUMBER:mongoDirty}%{SPACE}%{NUMBER:mongoUsed}%{SPACE}%{NUMBER:mongoFlushes}%{SIZE}%{RES}%{SPACE}%{NUMBER:mongoQR}\|%{NUMBER:mongoQW}%{SPACE}%{NUMBER:mongoAR}\|%{NUMBER:mongoAW}%{NETIN}%{NETOUT}%{SPACE}%{NUMBER:mongoConnections}%{SPACE}%{NOTSPACE:mongoReplSet}%{SPACE}%{WORD:mongoReplMember}%{SPACE}%{TIME:mongoTime}"]
}
if [mongoNetInQualifier] == 'b' {
ruby {
code => "event['mongoNetInKB'] = event['mongoNetIn'].to_f / 1024"
}
}
if [mongoNetInQualifier] == 'k' {
ruby {
code => "event['mongoNetInKB'] = event['mongoNetIn'].to_f * 1"
}
}
if [mongoNetInQualifier] == 'm' {
ruby {
code => "event['mongoNetInKB'] = event['mongoNetIn'].to_f * 1024"
}
}
if [mongoNetInQualifier] == 'g' {
ruby {
code => "event['mongoNetInKB'] = event['mongoNetIn'].to_f * 1048576"
}
}
mutate {
convert => { "mongoAW" => "integer" }
convert => { "mongoAR" => "integer" }
convert => { "mongoDirty" => "float" }
convert => { "mongoSize" => "float" }
convert => { "mongoUpdate" => "integer" }
convert => { "mongoInsert" => "integer" }
convert => { "port" => "integer" }
convert => { "mongoNetIn" => "integer" }
convert => { "mongoQR" => "integer" }
convert => { "mongoConnections" => "integer" }
convert => { "mongoRes" => "float" }
convert => { "mongoGetmore" => "integer" }
convert => { "mongoCommand" => "integer" }
convert => { "mongoQuery" => "integer" }
convert => { "mongoDelete" => "integer" }
convert => { "mongoUsed" => "float" }
convert => { "mongoNetOut" => "integer" }
convert => { "mongoFlushes" => "integer" }
}
}
}
input {
file {
path => "/tmp/mongostat.short"
type => "mongostat"
}
}
#!/bin/bash
mongostat --authenticationDatabase admin -u admin -p secret --noheaders --all --discover -n 50 > /tmp/mongostat.short
output {
if [type] == "mongostat" {
elasticsearch {
host => "elastic-host"
protocol => http
index => "logstash-mongostat-%{+YYYY.MM.dd}"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment