Skip to content

Instantly share code, notes, and snippets.

@xkr47
Last active September 7, 2019 15:06
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save xkr47/b92bf1271ed0282ceecd to your computer and use it in GitHub Desktop.
Save xkr47/b92bf1271ed0282ceecd to your computer and use it in GitHub Desktop.
Example logstash configuration for streaming/tailing sysstat "sar" command
input {
pipe {
tags => [ "sar", "loadavg" ]
command => "env LANG=C sar -q 5"
}
pipe {
tags => [ "sar", "cpu" ]
command => "env LANG=C sar -u 5"
}
}
filter {
if "sar" in [tags] {
if "loadavg" in [tags] {
grok {
match => { "message" => "\A(?<timestamp>%{HOUR}:%{MINUTE}:%{SECOND})\s+%{NUMBER:runqueueSize:int}\s+%{NUMBER:processListSize:int}\s+%{NUMBER:loadAvg1:float}\s+%{NUMBER:loadAvg5:float}\s+%{NUMBER:loadAvg15:float}" }
remove_field => [ "message" ]
}
}
if "cpu" in [tags] {
grok {
match => { "message" => "\A(?<timestamp>%{HOUR}:%{MINUTE}:%{SECOND})\s+all\s+%{NUMBER:user:float}\s+%{NUMBER:nice:float}\s+%{NUMBER:system:float}\s+%{NUMBER:iowait:float}\s+%{NUMBER:steal:float}\s+%{NUMBER:idle:float}\z" }
remove_field => [ "message" ]
}
}
if "_grokparsefailure" in [tags] and [message] =~ /\A(?:Linux|$|\d\d:\d\d:\d\d\s++[^0-9.\s])/ {
# drop header lines
drop { }
}
}
}
output {
# your output configuration here
}
@xkr47
Copy link
Author

xkr47 commented Jul 30, 2014

The env LANG=C prefix in sar commands is used to standardize the timestamp output format of sar.

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