Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
100644 123 lines (96 sloc) 5.445 kb
a68bed0 Vladimir Vuksan Import Ganglia Logtailer from Bitbucket
vvuksan authored
1 Imported from
5 ##################
6 ##
7 ## ganglia-logtailer
8 ##
9 ## ganglia-logtailer is a python script that will tail any log file,
10 ## crunch the data collected, and report summary data to ganglia.
11 ##
12 ## This directory contains the script ganglia-logtailer, its required
13 ## helper classes, and two example classes, one generic and one for
14 ## parsing Apache logs.
15 ##
16 ## Copyright Linden Lab, 2008
17 ## License to modify and redistribute granted under the GPL v2 or later
18 ##
19 ##################
22 0. Table of Contents
23 1. Overview
24 2. Installation
25 3. License
27 1. Overview
29 Many metrics associated with ganglia and gmetric plugins are rather easy to
30 collect; you poll the relevant application for a value and report it. Examples
31 are asking MySQL for the number of questions and calculating queries per
32 second, or asking iostat for the percentage disk I/O currently being used.
33 However, there are a large number of applications out there that don't support
34 being queried for interesting data, but do provide a log file which, when
35 properly parsed, yields the interesting data we desire. An example of the
36 latter category is Apache, which does not furnish any interface for measuring
37 queries per second, yet has a log file allowing you to count how many queries
38 come in over a specific time period.
40 ganglia-logtailer is designed to make it easy to parse any log file, pull out
41 the information you desire, and plug it into ganglia to make pretty graphs.
43 ganglia-logtailer is comprised of three parts:
44 * ganglia-logtailer - the python script doing the real work
45 * and - supporting python classes
46 *,, etc. - user modifiable, log-file specific classes
48 You must modify or write new classes for
49 each of the log files you wish to parse. As every log file has a specific
50 format, you must write the regular expression to properly pick out interesting
51 information for your specific application. As each application has different
52 ways of expressing what might be interesting metrics to graph, you must write
53 the functions to collect the information present in each line of the log file.
55 is an example file; it does nothing other than count the
56 number of lines present in the log file and report lines per second. However,
57 it does have extensive comments explaining the purpose of each of the functions
58 present in the file. I would recommend reading that file and modifying it to
59 do more interesting things.
61 is a fully functional class parsing an Apache log. At
62 Linden Lab, we use a custom log format (and include the very interesting %D -
63 time to execute the query in microseconds), so the regular expression included
64 there will probably have to be changed for your environment.
65 defines and returns the number of Apache requests per
66 second, also broken out by return code (200, 300, 400, 500), and the average,
67 maximum, and 90th percentile run time of all queries caught during the sample
68 period.
70 The rest of the * classes present are customized for different
71 types of logs (postfix, bind, etc.)
73 ganglia-logtailer can be invoked in two different modes, either as a daemon
74 (which tells it to run as a persistent process) or invoked from cron on a
75 regular basis. I recommend using daemon mode for testing, but invoking it from
76 cron every 1-5 minutes for deploy. I make this recommendation because (aside
77 from minimizing the number of running daemons), there are no start scripts to
78 invoke daemon mode on system boot, and there is no facility to relaunch the
79 process if it were to crash or raise an exception.
81 ganglia-logtailer will log certain bits of information to
82 /var/log/ganglia/ganglia_logtailer in case of error. Log level is variable by
83 modfying ganglia-logtailer and editing the following line:
84 logger.setLevel(logging.INFO) Look up the 'logging' python module for valid
85 values. (logging.DEBUG is a good bet)
87 2. Installation
89 ganglia-logtailer depends on the 'logtail' package
90 ( when run in cron mode.
92 i. Copy ganglia-logtailer to /usr/local/bin/ (or wherever you store
93 unpackaged binaries)
94 ii. Copy and to
95 /usr/local/share/ganglia-logtailer (or somewhere in your python search
96 path)
97 iii. Copy and to /usr/local/share/ganglia-logtailer
98 (or somewhere in your python search path)
100 Create the directory ganglia-logtailer uses to store state:
101 /var/lib/ganglia-logtailer/
103 Test the installation by invoking ganglia-logtailer with the DummyLogtailer
104 class on a log file:
105 # ganglia-logtailer --classname DummyLogtailer --log_file /var/log/daemon.log --mode daemon
106 wait 30s to 1m, then check and see whether your new metric is present in
107 ganglia.
109 If all goes well, try out one of the real modules:
1d9efff Ben Hartshorne importing changes from bitbucket:
maplebed authored
110 # ganglia-logtailer --classname PostfixLogtailer --log_file /var/log/mail.log --mode daemon
a68bed0 Vladimir Vuksan Import Ganglia Logtailer from Bitbucket
vvuksan authored
112 If that works as well, deploy! Add the following to
113 /etc/cron.d/ganglia-logtailer
1d9efff Ben Hartshorne importing changes from bitbucket:
maplebed authored
114 * * * * * root /usr/local/bin/ganglia-logtailer --classname PostfixLogtailer --log_file /var/log/mail.log --mode cron
a68bed0 Vladimir Vuksan Import Ganglia Logtailer from Bitbucket
vvuksan authored
116 3. License
118 These scripts are all released under the GPL v2 or later. For a full
119 description of the licence, please visit
Something went wrong with that request. Please try again.