blob: 7d064be967db041c379d2236d2723b130ccf34f5 [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
David James3b3add52010-06-04 15:01:19 -070015# You will need to emit messages similar to the following in order to add a
Darin Petkov65b01462010-04-14 13:32:20 -070016# 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
David James3b3add52010-06-04 15:01:19 -070039 program_name=$m
Darin Petkov65b01462010-04-14 13:32:20 -070040 else
41 first=1
David James3b3add52010-06-04 15:01:19 -070042 metrics_name=$m
43
Darin Petkov65b01462010-04-14 13:32:20 -070044 # 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;
David James3b3add52010-06-04 15:01:19 -070050 metrics_start[\"${metrics_name}Sectors\"] = \$11;
Darin Petkov65b01462010-04-14 13:32:20 -070051 }"
52 program="${program}/$program_name([[0-9]+]:|:) stop $metrics_name/\
David James3b3add52010-06-04 15:01:19 -070053 {
Darin Petkov65b01462010-04-14 13:32:20 -070054 metrics_stop[\"${metrics_name}Time\"] = \$9;
55 metrics_stop[\"${metrics_name}Sectors\"] = \$11;
56 }"
David James3b3add52010-06-04 15:01:19 -070057 fi
Darin Petkov65b01462010-04-14 13:32:20 -070058done
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
David James3b3add52010-06-04 15:01:19 -070069exec awk "$program" /var/log/syslog