Debian Codegraph @

utils/munin/mod_tile_latency

raw
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 # Copyright (c) 2007 - 2023 by mod_tile contributors (see AUTHORS file)
11 #
12 # This program is free software; you can redistribute it and/or
13 # modify it under the terms of the GNU General Public License
14 # as published by the Free Software Foundation; either version 2
15 # of the License, or (at your option) any later version.
16 #
17 # This program is distributed in the hope that it will be useful,
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 # GNU General Public License for more details.
21 #
22 # You should have received a copy of the GNU General Public License
23 # along with this program; If not, see http://www.gnu.org/licenses/.
24
25 if [ "$1" = "config" ]; then
26
27 echo 'graph_title avg latency of tile retrieval from disk'
28 echo 'graph_args --base 1000 -l 0'
29 echo 'graph_vlabel latency in s'
30 echo 'graph_category mod_tile'
31 echo 'total.label All served tiles'
32 echo 'total.draw LINE2'
33 echo 'total.type GAUGE'
34 echo 'total.min 0'
35 echo 'z1.label z1-8'
36 echo 'z1.draw LINE1'
37 echo 'z1.type GAUGE'
38 echo 'z1.min 0'
39 echo 'z2.label z9-12'
40 echo 'z2.draw LINE1'
41 echo 'z2.type GAUGE'
42 echo 'z2.min 0'
43 echo 'z3.label z13-14'
44 echo 'z3.draw LINE1'
45 echo 'z3.type GAUGE'
46 echo 'z3.min 0'
47 echo 'z4.label z15-16'
48 echo 'z4.draw LINE1'
49 echo 'z4.type GAUGE'
50 echo 'z4.min 0'
51 echo 'z5.label z17-18'
52 echo 'z5.draw LINE1'
53 echo 'z5.type GAUGE'
54 echo 'z5.min 0'
55 echo 'z6.label z19-20'
56 echo 'z6.draw LINE1'
57 echo 'z6.type GAUGE'
58 echo 'z6.min 0'
59
60 exit 0
61 fi
62
63 #MUNIN_STATEFILE=latency.state
64
65 data=$(wget -q ${MOD_TILE_URL:-http://localhost/mod_tile} -O -)
66
67 totalDuration=$(expr match "$data" '.*DurationTileBufferReads: \([0-9]*\)')
68 noTotal=$(expr match "$data" '.*NoTileBufferReads: \([0-9]*\)')
69 totalDurationPrev=$(sed -e '/^DurationTileBufferReads/!d' -e 's/.*: //' -e q $MUNIN_STATEFILE)
70 noTotalPrev=$(sed -e '/^NoTileBufferReads/!d' -e 's/.*: //' -e q $MUNIN_STATEFILE)
71
72 z0Duration=$(expr match "$data" '.*DurationTileBufferReadZoom00: \([0-9]*\)')
73 z1Duration=$(expr match "$data" '.*DurationTileBufferReadZoom01: \([0-9]*\)')
74 z2Duration=$(expr match "$data" '.*DurationTileBufferReadZoom02: \([0-9]*\)')
75 z3Duration=$(expr match "$data" '.*DurationTileBufferReadZoom03: \([0-9]*\)')
76 z4Duration=$(expr match "$data" '.*DurationTileBufferReadZoom04: \([0-9]*\)')
77 z5Duration=$(expr match "$data" '.*DurationTileBufferReadZoom05: \([0-9]*\)')
78 z6Duration=$(expr match "$data" '.*DurationTileBufferReadZoom06: \([0-9]*\)')
79 z7Duration=$(expr match "$data" '.*DurationTileBufferReadZoom07: \([0-9]*\)')
80 z8Duration=$(expr match "$data" '.*DurationTileBufferReadZoom08: \([0-9]*\)')
81 z9Duration=$(expr match "$data" '.*DurationTileBufferReadZoom09: \([0-9]*\)')
82 z10Duration=$(expr match "$data" '.*DurationTileBufferReadZoom10: \([0-9]*\)')
83 z11Duration=$(expr match "$data" '.*DurationTileBufferReadZoom11: \([0-9]*\)')
84 z12Duration=$(expr match "$data" '.*DurationTileBufferReadZoom12: \([0-9]*\)')
85 z13Duration=$(expr match "$data" '.*DurationTileBufferReadZoom13: \([0-9]*\)')
86 z14Duration=$(expr match "$data" '.*DurationTileBufferReadZoom14: \([0-9]*\)')
87 z15Duration=$(expr match "$data" '.*DurationTileBufferReadZoom15: \([0-9]*\)')
88 z16Duration=$(expr match "$data" '.*DurationTileBufferReadZoom16: \([0-9]*\)')
89 z17Duration=$(expr match "$data" '.*DurationTileBufferReadZoom17: \([0-9]*\)')
90 z18Duration=$(expr match "$data" '.*DurationTileBufferReadZoom18: \([0-9]*\)')
91 z19Duration=$(expr match "$data" '.*DurationTileBufferReadZoom19: \([0-9]*\)')
92 z20Duration=$(expr match "$data" '.*DurationTileBufferReadZoom20: \([0-9]*\)')
93
94 if [ -z "$z19Duration" ]; then z19Duration=0; fi
95 if [ -z "$z20Duration" ]; then z20Duration=0; fi
96
97 z0NoServed=$(expr match "$data" '.*NoTileBufferReadZoom00: \([0-9]*\)')
98 z1NoServed=$(expr match "$data" '.*NoTileBufferReadZoom01: \([0-9]*\)')
99 z2NoServed=$(expr match "$data" '.*NoTileBufferReadZoom02: \([0-9]*\)')
100 z3NoServed=$(expr match "$data" '.*NoTileBufferReadZoom03: \([0-9]*\)')
101 z4NoServed=$(expr match "$data" '.*NoTileBufferReadZoom04: \([0-9]*\)')
102 z5NoServed=$(expr match "$data" '.*NoTileBufferReadZoom05: \([0-9]*\)')
103 z6NoServed=$(expr match "$data" '.*NoTileBufferReadZoom06: \([0-9]*\)')
104 z7NoServed=$(expr match "$data" '.*NoTileBufferReadZoom07: \([0-9]*\)')
105 z8NoServed=$(expr match "$data" '.*NoTileBufferReadZoom08: \([0-9]*\)')
106 z9NoServed=$(expr match "$data" '.*NoTileBufferReadZoom09: \([0-9]*\)')
107 z10NoServed=$(expr match "$data" '.*NoTileBufferReadZoom10: \([0-9]*\)')
108 z11NoServed=$(expr match "$data" '.*NoTileBufferReadZoom11: \([0-9]*\)')
109 z12NoServed=$(expr match "$data" '.*NoTileBufferReadZoom12: \([0-9]*\)')
110 z13NoServed=$(expr match "$data" '.*NoTileBufferReadZoom13: \([0-9]*\)')
111 z14NoServed=$(expr match "$data" '.*NoTileBufferReadZoom14: \([0-9]*\)')
112 z15NoServed=$(expr match "$data" '.*NoTileBufferReadZoom15: \([0-9]*\)')
113 z16NoServed=$(expr match "$data" '.*NoTileBufferReadZoom16: \([0-9]*\)')
114 z17NoServed=$(expr match "$data" '.*NoTileBufferReadZoom17: \([0-9]*\)')
115 z18NoServed=$(expr match "$data" '.*NoTileBufferReadZoom18: \([0-9]*\)')
116 z19NoServed=$(expr match "$data" '.*NoTileBufferReadZoom19: \([0-9]*\)')
117 z20NoServed=$(expr match "$data" '.*NoTileBufferReadZoom20: \([0-9]*\)')
118
119 if [ -z "$z19NoServed" ]; then z19NoServed=0; fi
120 if [ -z "$z20NoServed" ]; then z20NoServed=0; fi
121
122 zl1Duration=$(expr $z0Duration + $z1Duration + $z2Duration + $z3Duration + $z4Duration + $z5Duration + $z6Duration + $z7Duration + $z8Duration)
123 zl1NoServed=$(expr $z0NoServed + $z1NoServed + $z2NoServed + $z3NoServed + $z4NoServed + $z5NoServed + $z6NoServed + $z7NoServed + $z8NoServed)
124 zl2Duration=$(expr $z9Duration + $z10Duration + $z11Duration + $z12Duration)
125 zl2NoServed=$(expr $z9NoServed + $z10NoServed + $z11NoServed + $z12NoServed)
126 zl3Duration=$(expr $z13Duration + $z14Duration)
127 zl3NoServed=$(expr $z13NoServed + $z14NoServed)
128 zl4Duration=$(expr $z15Duration + $z16Duration)
129 zl4NoServed=$(expr $z15NoServed + $z16NoServed)
130 zl5Duration=$(expr $z17Duration + $z18Duration)
131 zl5NoServed=$(expr $z17NoServed + $z18NoServed)
132 zl6Duration=$(expr $z19Duration + $z20Duration)
133 zl6NoServed=$(expr $z19NoServed + $z20NoServed)
134
135 zl1DurationPrev=$(sed -e '/^DurationTileBufferReadZoomGroup1/!d' -e 's/.*: //' -e q $MUNIN_STATEFILE)
136 zl1NoServedPrev=$(sed -e '/^NoTileBufferReadZoomGroup1/!d' -e 's/.*: //' -e q $MUNIN_STATEFILE)
137 zl2DurationPrev=$(sed -e '/^DurationTileBufferReadZoomGroup2/!d' -e 's/.*: //' -e q $MUNIN_STATEFILE)
138 zl2NoServedPrev=$(sed -e '/^NoTileBufferReadZoomGroup2/!d' -e 's/.*: //' -e q $MUNIN_STATEFILE)
139 zl3DurationPrev=$(sed -e '/^DurationTileBufferReadZoomGroup3/!d' -e 's/.*: //' -e q $MUNIN_STATEFILE)
140 zl3NoServedPrev=$(sed -e '/^NoTileBufferReadZoomGroup3/!d' -e 's/.*: //' -e q $MUNIN_STATEFILE)
141 zl4DurationPrev=$(sed -e '/^DurationTileBufferReadZoomGroup4/!d' -e 's/.*: //' -e q $MUNIN_STATEFILE)
142 zl4NoServedPrev=$(sed -e '/^NoTileBufferReadZoomGroup4/!d' -e 's/.*: //' -e q $MUNIN_STATEFILE)
143 zl5DurationPrev=$(sed -e '/^DurationTileBufferReadZoomGroup5/!d' -e 's/.*: //' -e q $MUNIN_STATEFILE)
144 zl5NoServedPrev=$(sed -e '/^NoTileBufferReadZoomGroup5/!d' -e 's/.*: //' -e q $MUNIN_STATEFILE)
145 zl6DurationPrev=$(sed -e '/^DurationTileBufferReadZoomGroup6/!d' -e 's/.*: //' -e q $MUNIN_STATEFILE)
146 zl6NoServedPrev=$(sed -e '/^NoTileBufferReadZoomGroup6/!d' -e 's/.*: //' -e q $MUNIN_STATEFILE)
147
148 echo "DurationTileBufferReads: $totalDuration" >$MUNIN_STATEFILE
149 echo "NoTileBufferReads: $noTotal" >>$MUNIN_STATEFILE
150 echo "DurationTileBufferReadZoomGroup1: $zl1Duration" >>$MUNIN_STATEFILE
151 echo "NoTileBufferReadZoomGroup1: $zl1NoServed" >>$MUNIN_STATEFILE
152 echo "DurationTileBufferReadZoomGroup2: $zl2Duration" >>$MUNIN_STATEFILE
153 echo "NoTileBufferReadZoomGroup2: $zl2NoServed" >>$MUNIN_STATEFILE
154 echo "DurationTileBufferReadZoomGroup3: $zl3Duration" >>$MUNIN_STATEFILE
155 echo "NoTileBufferReadZoomGroup3: $zl3NoServed" >>$MUNIN_STATEFILE
156 echo "DurationTileBufferReadZoomGroup4: $zl4Duration" >>$MUNIN_STATEFILE
157 echo "NoTileBufferReadZoomGroup4: $zl4NoServed" >>$MUNIN_STATEFILE
158 echo "DurationTileBufferReadZoomGroup5: $zl5Duration" >>$MUNIN_STATEFILE
159 echo "NoTileBufferReadZoomGroup5: $zl5NoServed" >>$MUNIN_STATEFILE
160 echo "DurationTileBufferReadZoomGroup6: $zl6Duration" >>$MUNIN_STATEFILE
161 echo "NoTileBufferReadZoomGroup6: $zl6NoServed" >>$MUNIN_STATEFILE
162
163 if [ "$noTotal" = "$noTotalPrev" ]; then
164 totalLatency=0
165 else
166 totalLatency=$(echo "$totalDuration $totalDurationPrev $noTotal $noTotalPrev" | awk '{ totalLat = ($1 - $2) / ($3 - $4) / 1000000.0; print totalLat}')
167 fi
168
169 if [ "$zl1NoServed" = "$zl1NoServedPrev" ]; then
170 zl1Latency=0
171 else
172 zl1Latency=$(echo "$zl1Duration $zl1DurationPrev $zl1NoServed $zl1NoServedPrev" | awk '{ zl1Lat = ($1 - $2) / ($3 - $4) / 1000000.0; print zl1Lat}')
173 fi
174
175 if [ "$zl2NoServed" = "$zl2NoServedPrev" ]; then
176 zl2Latency=0
177 else
178 zl2Latency=$(echo "$zl2Duration $zl2DurationPrev $zl2NoServed $zl2NoServedPrev" | awk '{ zl2Lat = ($1 - $2) / ($3 - $4) / 1000000.0; print zl2Lat}')
179 fi
180
181 if [ "$zl3NoServed" = "$zl3NoServedPrev" ]; then
182 zl3Latency=0
183 else
184 zl3Latency=$(echo "$zl3Duration $zl3DurationPrev $zl3NoServed $zl3NoServedPrev" | awk '{ zl3Lat = ($1 - $2) / ($3 - $4) / 1000000.0; print zl3Lat}')
185 fi
186
187 if [ "$zl4NoServed" = "$zl4NoServedPrev" ]; then
188 zl4Latency=0
189 else
190 zl4Latency=$(echo "$zl4Duration $zl4DurationPrev $zl4NoServed $zl4NoServedPrev" | awk '{ zl4Lat = ($1 - $2) / ($3 - $4) / 1000000.0; print zl4Lat}')
191 fi
192
193 if [ "$zl5NoServed" = "$zl5NoServedPrev" ]; then
194 zl5Latency=0
195 else
196 zl5Latency=$(echo "$zl5Duration $zl5DurationPrev $zl5NoServed $zl5NoServedPrev" | awk '{ zl5Lat = ($1 - $2) / ($3 - $4) / 1000000.0; print zl5Lat}')
197 fi
198
199 if [ "$zl6NoServed" = "$zl6NoServedPrev" ]; then
200 zl6Latency=0
201 else
202 zl6Latency=$(echo "$zl6Duration $zl6DurationPrev $zl6NoServed $zl6NoServedPrev" | awk '{ zl6Lat = ($1 - $2) / ($3 - $4) / 1000000.0; print zl6Lat}')
203 fi
204
205 echo "total.value " $totalLatency
206 echo "z1.value " $zl1Latency
207 echo "z2.value " $zl2Latency
208 echo "z3.value " $zl3Latency
209 echo "z4.value " $zl4Latency
210 echo "z5.value " $zl5Latency
211 echo "z6.value " $zl6Latency