Add mod_tile_latency
[chef.git] / cookbooks / munin / files / default / plugins / mod_tile_latency
1 #!/bin/sh
2 #
3 # Plugin to monitor the state / freshness  of the tiles returned by mod_tile
4 #
5 # Parameters: 
6 #
7 #       config   (required)
8 #       autoconf (optional - used by munin-config)
9 #
10
11 if [ "$1" = "config" ]; then
12
13         echo 'graph_title avg latency of tile retrival from disk'
14         echo 'graph_args --base 1000 -l 0'
15         echo 'graph_vlabel latency in s'
16         echo 'graph_category mod_tile'
17         echo 'total.label All served tiles'
18         echo 'total.draw LINE2'
19         echo 'total.type GAUGE'
20         echo 'total.min 0'
21     echo 'z1.label z1-8'
22         echo 'z1.draw LINE1'
23         echo 'z1.type GAUGE'
24         echo 'z1.min 0'
25     echo 'z2.label z9-12'
26         echo 'z2.draw LINE1'
27         echo 'z2.type GAUGE'
28         echo 'z2.min 0'
29     echo 'z3.label z13-14'
30         echo 'z3.draw LINE1'
31         echo 'z3.type GAUGE'
32         echo 'z3.min 0'
33     echo 'z4.label z15-16'
34         echo 'z4.draw LINE1'
35         echo 'z4.type GAUGE'
36         echo 'z4.min 0'
37     echo 'z5.label z17-18'
38         echo 'z5.draw LINE1'
39         echo 'z5.type GAUGE'
40         echo 'z5.min 0'
41         exit 0
42 fi
43
44 MUNIN_STATEFILE=/tmp/munin-mod-tile-latency.state
45
46 data=`wget -q http://localhost/mod_tile -O -`
47
48
49 totalDuration=`expr match "$data" '.*DurationTileBufferReads: \([0-9]*\)'`
50 noTotal=`expr match "$data" '.*NoTileBufferReads: \([0-9]*\)'`
51 totalDurationPrev=`sed -e '/^DurationTileBufferReads/!d' -e 's/.*: //' -e q $MUNIN_STATEFILE`
52 noTotalPrev=`sed -e '/^NoTileBufferReads/!d' -e 's/.*: //' -e q $MUNIN_STATEFILE`
53
54 z0Duration=`expr match "$data" '.*DurationTileBufferReadZoom00: \([0-9]*\)'`
55 z1Duration=`expr match "$data" '.*DurationTileBufferReadZoom01: \([0-9]*\)'`
56 z2Duration=`expr match "$data" '.*DurationTileBufferReadZoom02: \([0-9]*\)'`
57 z3Duration=`expr match "$data" '.*DurationTileBufferReadZoom03: \([0-9]*\)'`
58 z4Duration=`expr match "$data" '.*DurationTileBufferReadZoom04: \([0-9]*\)'`
59 z5Duration=`expr match "$data" '.*DurationTileBufferReadZoom05: \([0-9]*\)'`
60 z6Duration=`expr match "$data" '.*DurationTileBufferReadZoom06: \([0-9]*\)'`
61 z7Duration=`expr match "$data" '.*DurationTileBufferReadZoom07: \([0-9]*\)'`
62 z8Duration=`expr match "$data" '.*DurationTileBufferReadZoom08: \([0-9]*\)'`
63 z9Duration=`expr match "$data" '.*DurationTileBufferReadZoom09: \([0-9]*\)'`
64 z10Duration=`expr match "$data" '.*DurationTileBufferReadZoom10: \([0-9]*\)'`
65 z11Duration=`expr match "$data" '.*DurationTileBufferReadZoom11: \([0-9]*\)'`
66 z12Duration=`expr match "$data" '.*DurationTileBufferReadZoom12: \([0-9]*\)'`
67 z13Duration=`expr match "$data" '.*DurationTileBufferReadZoom13: \([0-9]*\)'`
68 z14Duration=`expr match "$data" '.*DurationTileBufferReadZoom14: \([0-9]*\)'`
69 z15Duration=`expr match "$data" '.*DurationTileBufferReadZoom15: \([0-9]*\)'`
70 z16Duration=`expr match "$data" '.*DurationTileBufferReadZoom16: \([0-9]*\)'`
71 z17Duration=`expr match "$data" '.*DurationTileBufferReadZoom17: \([0-9]*\)'`
72 z18Duration=`expr match "$data" '.*DurationTileBufferReadZoom18: \([0-9]*\)'`
73
74 z0NoServed=`expr match "$data" '.*NoTileBufferReadZoom00: \([0-9]*\)'`
75 z1NoServed=`expr match "$data" '.*NoTileBufferReadZoom01: \([0-9]*\)'`
76 z2NoServed=`expr match "$data" '.*NoTileBufferReadZoom02: \([0-9]*\)'`
77 z3NoServed=`expr match "$data" '.*NoTileBufferReadZoom03: \([0-9]*\)'`
78 z4NoServed=`expr match "$data" '.*NoTileBufferReadZoom04: \([0-9]*\)'`
79 z5NoServed=`expr match "$data" '.*NoTileBufferReadZoom05: \([0-9]*\)'`
80 z6NoServed=`expr match "$data" '.*NoTileBufferReadZoom06: \([0-9]*\)'`
81 z7NoServed=`expr match "$data" '.*NoTileBufferReadZoom07: \([0-9]*\)'`
82 z8NoServed=`expr match "$data" '.*NoTileBufferReadZoom08: \([0-9]*\)'`
83 z9NoServed=`expr match "$data" '.*NoTileBufferReadZoom09: \([0-9]*\)'`
84 z10NoServed=`expr match "$data" '.*NoTileBufferReadZoom10: \([0-9]*\)'`
85 z11NoServed=`expr match "$data" '.*NoTileBufferReadZoom11: \([0-9]*\)'`
86 z12NoServed=`expr match "$data" '.*NoTileBufferReadZoom12: \([0-9]*\)'`
87 z13NoServed=`expr match "$data" '.*NoTileBufferReadZoom13: \([0-9]*\)'`
88 z14NoServed=`expr match "$data" '.*NoTileBufferReadZoom14: \([0-9]*\)'`
89 z15NoServed=`expr match "$data" '.*NoTileBufferReadZoom15: \([0-9]*\)'`
90 z16NoServed=`expr match "$data" '.*NoTileBufferReadZoom16: \([0-9]*\)'`
91 z17NoServed=`expr match "$data" '.*NoTileBufferReadZoom17: \([0-9]*\)'`
92 z18NoServed=`expr match "$data" '.*NoTileBufferReadZoom18: \([0-9]*\)'`
93
94 zl1Duration=`expr $z0Duration + $z1Duration + $z2Duration + $z3Duration + $z4Duration + $z5Duration + $z6Duration + $z7Duration + $z8Duration`
95 zl1NoServed=`expr $z0NoServed + $z1NoServed + $z2NoServed + $z3NoServed + $z4NoServed + $z5NoServed + $z6NoServed + $z7NoServed + $z8NoServed`
96 zl2Duration=`expr $z9Duration + $z10Duration + $z11Duration + $z12Duration`
97 zl2NoServed=`expr $z9NoServed + $z10NoServed + $z11NoServed + $z12NoServed`
98 zl3Duration=`expr $z13Duration + $z14Duration`
99 zl3NoServed=`expr $z13NoServed + $z14NoServed`
100 zl4Duration=`expr $z15Duration + $z16Duration`
101 zl4NoServed=`expr $z15NoServed + $z16NoServed`
102 zl5Duration=`expr $z17Duration + $z18Duration`
103 zl5NoServed=`expr $z17NoServed + $z18NoServed`
104
105 zl1DurationPrev=`sed -e '/^DurationTileBufferReadZoomGroup1/!d' -e 's/.*: //' -e q $MUNIN_STATEFILE`
106 zl1NoServedPrev=`sed -e '/^NoTileBufferReadZoomGroup1/!d' -e 's/.*: //' -e q $MUNIN_STATEFILE`
107 zl2DurationPrev=`sed -e '/^DurationTileBufferReadZoomGroup2/!d' -e 's/.*: //' -e q $MUNIN_STATEFILE`
108 zl2NoServedPrev=`sed -e '/^NoTileBufferReadZoomGroup2/!d' -e 's/.*: //' -e q $MUNIN_STATEFILE`
109 zl3DurationPrev=`sed -e '/^DurationTileBufferReadZoomGroup3/!d' -e 's/.*: //' -e q $MUNIN_STATEFILE`
110 zl3NoServedPrev=`sed -e '/^NoTileBufferReadZoomGroup3/!d' -e 's/.*: //' -e q $MUNIN_STATEFILE`
111 zl4DurationPrev=`sed -e '/^DurationTileBufferReadZoomGroup4/!d' -e 's/.*: //' -e q $MUNIN_STATEFILE`
112 zl4NoServedPrev=`sed -e '/^NoTileBufferReadZoomGroup4/!d' -e 's/.*: //' -e q $MUNIN_STATEFILE`
113 zl5DurationPrev=`sed -e '/^DurationTileBufferReadZoomGroup5/!d' -e 's/.*: //' -e q $MUNIN_STATEFILE`
114 zl5NoServedPrev=`sed -e '/^NoTileBufferReadZoomGroup5/!d' -e 's/.*: //' -e q $MUNIN_STATEFILE`
115
116
117 echo "DurationTileBufferReads: $totalDuration" > $MUNIN_STATEFILE
118 echo "NoTileBufferReads: $noTotal" >> $MUNIN_STATEFILE
119 echo "DurationTileBufferReadZoomGroup1: $zl1Duration" >> $MUNIN_STATEFILE
120 echo "NoTileBufferReadZoomGroup1: $zl1NoServed" >> $MUNIN_STATEFILE
121 echo "DurationTileBufferReadZoomGroup2: $zl2Duration" >> $MUNIN_STATEFILE
122 echo "NoTileBufferReadZoomGroup2: $zl2NoServed" >> $MUNIN_STATEFILE
123 echo "DurationTileBufferReadZoomGroup3: $zl3Duration" >> $MUNIN_STATEFILE
124 echo "NoTileBufferReadZoomGroup3: $zl3NoServed" >> $MUNIN_STATEFILE
125 echo "DurationTileBufferReadZoomGroup4: $zl4Duration" >> $MUNIN_STATEFILE
126 echo "NoTileBufferReadZoomGroup4: $zl4NoServed" >> $MUNIN_STATEFILE
127 echo "DurationTileBufferReadZoomGroup5: $zl5Duration" >> $MUNIN_STATEFILE
128 echo "NoTileBufferReadZoomGroup5: $zl5NoServed" >> $MUNIN_STATEFILE
129
130
131 if [ "$noTotal" = "$noTotalPrev" ];
132 then
133     totalLatency=0
134 else
135     totalLatency=$(echo "$totalDuration $totalDurationPrev $noTotal $noTotalPrev" | awk '{ totalLat = ($1 - $2) / ($3 - $4) / 1000000.0; print totalLat}' )
136 fi
137
138 if [ "$zl1NoServed" = "$zl1NoServedPrev" ];
139 then
140     zl1Latency=0
141 else
142     zl1Latency=$(echo "$zl1Duration $zl1DurationPrev $zl1NoServed $zl1NoServedPrev" | awk '{ zl1Lat = ($1 - $2) / ($3 - $4) / 1000000.0; print zl1Lat}' )
143 fi
144
145 if [ "$zl2NoServed" = "$zl2NoServedPrev" ];
146 then
147     zl2Latency=0
148 else
149     zl2Latency=$(echo "$zl2Duration $zl2DurationPrev $zl2NoServed $zl2NoServedPrev" | awk '{ zl2Lat = ($1 - $2) / ($3 - $4) / 1000000.0; print zl2Lat}' )
150 fi
151
152 if [ "$zl3NoServed" = "$zl3NoServedPrev" ];
153 then
154     zl3Latency=0
155 else
156     zl3Latency=$(echo "$zl3Duration $zl3DurationPrev $zl3NoServed $zl3NoServedPrev" | awk '{ zl3Lat = ($1 - $2) / ($3 - $4) / 1000000.0; print zl3Lat}' )
157 fi
158
159 if [ "$zl4NoServed" = "$zl4NoServedPrev" ];
160 then
161     zl4Latency=0
162 else
163     zl4Latency=$(echo "$zl4Duration $zl4DurationPrev $zl4NoServed $zl4NoServedPrev" | awk '{ zl4Lat = ($1 - $2) / ($3 - $4) / 1000000.0; print zl4Lat}' )
164 fi
165
166 if [ "$zl5NoServed" = "$zl5NoServedPrev" ];
167 then
168     zl5Latency=0
169 else
170     zl5Latency=$(echo "$zl5Duration $zl5DurationPrev $zl5NoServed $zl5NoServedPrev" | awk '{ zl5Lat = ($1 - $2) / ($3 - $4) / 1000000.0; print zl5Lat}' )
171 fi
172
173 echo "total.value " $totalLatency
174 echo "z1.value " $zl1Latency
175 echo "z2.value " $zl2Latency
176 echo "z3.value " $zl3Latency
177 echo "z4.value " $zl4Latency
178 echo "z5.value " $zl5Latency