Darin Petkov | 65b0146 | 2010-04-14 13:32:20 -0700 | [diff] [blame] | 1 | #! /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 James | 3b3add5 | 2010-06-04 15:01:19 -0700 | [diff] [blame] | 15 | # You will need to emit messages similar to the following in order to add a |
Darin Petkov | 65b0146 | 2010-04-14 13:32:20 -0700 | [diff] [blame] | 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 |
| 26 | METRICS=" |
| 27 | upstart start_x |
| 28 | " |
| 29 | |
| 30 | first=1 |
| 31 | program="" |
| 32 | |
| 33 | # Get the metrics for all things |
| 34 | for m in $METRICS |
| 35 | do |
| 36 | if [ $first -eq 1 ] |
| 37 | then |
| 38 | first=0 |
David James | 3b3add5 | 2010-06-04 15:01:19 -0700 | [diff] [blame] | 39 | program_name=$m |
Darin Petkov | 65b0146 | 2010-04-14 13:32:20 -0700 | [diff] [blame] | 40 | else |
| 41 | first=1 |
David James | 3b3add5 | 2010-06-04 15:01:19 -0700 | [diff] [blame] | 42 | metrics_name=$m |
| 43 | |
Darin Petkov | 65b0146 | 2010-04-14 13:32:20 -0700 | [diff] [blame] | 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; |
David James | 3b3add5 | 2010-06-04 15:01:19 -0700 | [diff] [blame] | 50 | metrics_start[\"${metrics_name}Sectors\"] = \$11; |
Darin Petkov | 65b0146 | 2010-04-14 13:32:20 -0700 | [diff] [blame] | 51 | }" |
| 52 | program="${program}/$program_name([[0-9]+]:|:) stop $metrics_name/\ |
David James | 3b3add5 | 2010-06-04 15:01:19 -0700 | [diff] [blame] | 53 | { |
Darin Petkov | 65b0146 | 2010-04-14 13:32:20 -0700 | [diff] [blame] | 54 | metrics_stop[\"${metrics_name}Time\"] = \$9; |
| 55 | metrics_stop[\"${metrics_name}Sectors\"] = \$11; |
| 56 | }" |
David James | 3b3add5 | 2010-06-04 15:01:19 -0700 | [diff] [blame] | 57 | fi |
Darin Petkov | 65b0146 | 2010-04-14 13:32:20 -0700 | [diff] [blame] | 58 | done |
| 59 | |
| 60 | # Do all the differencing here |
| 61 | program="${program}\ |
| 62 | END{ |
| 63 | for (i in metrics_stop) { |
| 64 | value_time = metrics_stop[i] - metrics_start[i]; |
| 65 | print i \"=\" value_time; |
| 66 | } |
| 67 | }" |
| 68 | |
David James | 3b3add5 | 2010-06-04 15:01:19 -0700 | [diff] [blame] | 69 | exec awk "$program" /var/log/syslog |