1 of 24

Extracting metrics from logs for realtime trending and alerting

​

​

Jamie Wilkinson <jaq@spacepants.org>

2 of 24

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:

​

  • queries
  • errors served
  • backend errors received
  • ...

3 of 24

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.

4 of 24

"Passive" aka whitebox

Need to extract monitoring data from applications.

​

Most apps actually give this away.

​

5 of 24

 

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

6 of 24

 

�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

7 of 24

 

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

​

8 of 24

 

ldapsearch -xLLL ou=monitor

​

:-(

​

​

cat /var/log/ldap/slapd.log

​

:-)

9 of 24

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.

10 of 24

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.

​

11 of 24

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

12 of 24

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.

​

​

13 of 24

An Exported Metric

type Metric struct {

    Name string

    Value float64

    Time time.Time

    Type metricType  // COUNTER, GAUGE

    Unit string

    Tag map[string]string

}

14 of 24

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:

  • saturnalia
  • collectd
  • opentsdb
  • graphite?

15 of 24

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.

16 of 24

Still to come

Not finished yet:

  • read from unix socket
  • more efficient matching
  • named capture groups

​

But it works!

17 of 24

The emtail language

/$/ {

  inc(line-count)

}

​

18 of 24

Labels

/$/ {

  tag(foo, bar)

  inc(line-count)

}

​

->

​

line-count,1.000000,Tue Jan 17 07:55:01 +1100 EST 2012,0,,foo=bar

19 of 24

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...)

20 of 24

Timestamps

/^(?P<date>\d+\/\d+\/\d+ \d+:\d+:\d+) \[(?P<pid>\d+)\] / {

  strptime $date "2006/01/02 15:04:05"

​

  ...

}

21 of 24

Nested Regular Expressions

/foo/ {

    /bar/ {

      inc(bar)

    }

​

    /baz/ {

      inc(baz)

    }

​

    inc(foo)

}

22 of 24

Example time!

 

23 of 24

Under the hood

emtail programs compile to a simple bytecode

​

The vm runs the bytecode each time a line is received

​

vm.go

24 of 24

Question Time!