Extracting metrics from logs for realtime trending and alerting
Jamie Wilkinson <jaq@spacepants.org>
The Problem!
Running a cluster of slapd* machines.
(*also clusters of bind, rsyncd, dhcpd, ntpd, etc)
How do we monitor these servers?
Want to know more than just up/down:
Assimilate
Google has its own proprietary monitoring system.
Goal: Try to reuse as much existing technology as possible.
Don't need to reimplement collection or timeseries storage tools; just need to get metrics out of the open source apps.
"Passive" aka whitebox
Need to extract monitoring data from applications.
Most apps actually give this away.
ntpq -c pe
+ds001.hostingsh 203.12.160.2 3 u 264 1024 377 37.403 -2.373 3.721
-b.pool.ntp.uq.e 202.147.104.51 3 u 601 1024 377 35.793 0.853 1.374
^[[1;5A time1.google.com
*121.0.0.42 209.81.9.7 2 u 834 1024 377 36.224 -0.016 0.746
+pond.thecave.ws 18.26.4.105 2 u 279 1024 377 76.852 -2.739 3.381
�mysqladmin status
Uptime: 4661 Threads: 1 Questions: 200
Slow queries: 0 Opens: 16 Flush
tables: 1 Open tables: 6
Queries per second avg: 0.043
wget localhost:80/server-status
Apache Server Status for httpd.apache.org
Server Version: Apache/2.2.9 (Unix)
Server Built: Dec 27 2008 22:50:38
Current Time: Thursday, 22-Jan-2009 03:20:06 GMT
Restart Time: Friday, 16-Jan-2009 18:48:18 GMT
Parent Server Generation: 27
Server uptime: 5 days 8 hours 31 minutes 48 seconds
Total accesses: 33814127 - Total Traffic: 16602.3 GB
CPU Usage: u808.66 s358.97 cu0 cs0 - .252% CPU load
73.1 requests/sec - 36.7 MB/second - 0.5 MB/request
161 requests currently being processed, 95 idle workers
ldapsearch -xLLL ou=monitor
:-(
cat /var/log/ldap/slapd.log
:-)
Not generalisable
There's no common structure to these.
Have to write a new piece of code for every application.
Would prefer a single extensible solution.
Get it from the logs
All the data we want, and the time it happened, is in the logs.
Tail the log,
run some regexes,
export the values.
emtail
emtail is an exporting, modular tail.
It reads some logs, and runs some modules, or plugins, over them.
for line in lines:
for regexp in regexps:
if regexp.Match(line):
count things
Exporting metrics
The plugins define some rules for counting things; adding things together.
The metrics are exported over a common protocol that looks reasonable for a timeseries.
An Exported Metric
type Metric struct {
Name string
Value float64
Time time.Time
Type metricType // COUNTER, GAUGE
Unit string
Tag map[string]string
}
But seriously... how?
The data is exported over an HTTP server, using JSON or CSV.
Both formats are easy to parse.
The exported data is the "head" of the timeseries; there's no historical record in this tool.
That's the job of someone else:
Go
The current version is in Python, with lots of Google specific and proprietary code deeply ingrained. Too hard to open source.
The new hotness is in Go, freely available on
http://code.google.com/p/emtail
A reimplementation from scratch of the original design.
Still to come
Not finished yet:
But it works!
The emtail language
/$/ {
inc(line-count)
}
Labels
/$/ {
tag(foo, bar)
inc(line-count)
}
->
line-count,1.000000,Tue Jan 17 07:55:01 +1100 EST 2012,0,,foo=bar
Capture groups
/(?P<operation>\S+) (\S+) \[\S+\] (\S+) \(\S*\) \S+ (?P<bytes>\d+)/ {
tag(operation, $operation)
tag(module, $3)
inc(transfers_total)
}
(named capture groups don't work in Go yet...)
Timestamps
/^(?P<date>\d+\/\d+\/\d+ \d+:\d+:\d+) \[(?P<pid>\d+)\] / {
strptime $date "2006/01/02 15:04:05"
...
}
Nested Regular Expressions
/foo/ {
/bar/ {
inc(bar)
}
/baz/ {
inc(baz)
}
inc(foo)
}
Example time!
Under the hood
emtail programs compile to a simple bytecode
The vm runs the bytecode each time a line is received
Question Time!