blob: 7f3003ff4601a68c30d4fecfed77579ede199f84 [file] [log] [blame]
Darin Petkov65b01462010-04-14 13:32:20 -07001#! /bin/sh
2
3# This script parses /var/log/syslog for messages from programs that log
4# uptime and disk stats (number of sectors read). It then outputs
5# these stats in a format usable by the metrics collector, which forwards
6# them to autotest and UMA.
7
8# To add a new metric add a line below, as PROGRAM_NAME METRIC_NAME.
9# PROGRAM_NAME is the name of the job whose start time we
10# are interested in. METRIC_NAME is the prefix we want to use for
11# reporting to UMA and autotest. The script prepends "Time" and
12# "Sectors" to METRIC_NAME for the two available measurements, uptime
13# and number of sectors read thus far.
14
15# You will need to emit messages similar to the following in order to add a
16# a metric using this process. You will need to emit both a start and stop
17# time and the metric reported will be the difference in values
18
19# Nov 15 08:05 localhost PROGRAM_NAME[822]: start METRIC_NAME time 12 sectors 56
20# Nov 15 08:05 localhost PROGRAM_NAME[822]: stop METRIC_NAME time 24 sectors 68
21
22# If you add metrics without a start, it is assumed you are requesting the
23# time differece from system start
24
25# Metrics we are interested in measuring
26METRICS="
27upstart start_x
28"
29
30first=1
31program=""
32
33# Get the metrics for all things
34for m in $METRICS
35do
36 if [ $first -eq 1 ]
37 then
38 first=0
39 program_name=$m
40 else
41 first=1
42 metrics_name=$m
43
44 # Example of line from /var/log/messages:
45 # Nov 15 08:05:42 localhost connmand[822]: start metric time 12 sectors 56
46 # "upstart:" is $5, 1234 is $9, etc.
47 program="${program}/$program_name([[0-9]+]:|:) start $metrics_name/\
48 {
49 metrics_start[\"${metrics_name}Time\"] = \$9;
50 metrics_start[\"${metrics_name}Sectors\"] = \$11;
51 }"
52 program="${program}/$program_name([[0-9]+]:|:) stop $metrics_name/\
53 {
54 metrics_stop[\"${metrics_name}Time\"] = \$9;
55 metrics_stop[\"${metrics_name}Sectors\"] = \$11;
56 }"
57 fi
58done
59
60# Do all the differencing here
61program="${program}\
62END{
63 for (i in metrics_stop) {
64 value_time = metrics_stop[i] - metrics_start[i];
65 print i \"=\" value_time;
66 }
67}"
68
69exec awk "$program" /var/log/syslog