Mercurial > notdcc
comparison misc/dcc-stats-graph.in @ 0:c7f6b056b673
First import of vendor version
author | Peter Gervai <grin@grin.hu> |
---|---|
date | Tue, 10 Mar 2009 13:49:58 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:c7f6b056b673 |
---|---|
1 #! /bin/sh -e | |
2 | |
3 # graph collected DCC statistics in .png files. | |
4 # [-x] debugging | |
5 # [-q] quiet | |
6 # [-B] make big graphs | |
7 # [-G db] make graph of database size | |
8 # [-G db-min] make graph of database size without maximum size | |
9 # [-G traffic-noratio] database size without spam ratios | |
10 # [-G traffic] mail message rates and spam ratios | |
11 # [-G ratio] spam ratios | |
12 # [-h dcc_homedir] | |
13 # [-T @RRDTOOL@] see http://people.ee.ethz.ch/~oetiker/webtools/rrdtool/ | |
14 # or the FreeBSD package. | |
15 # [-O rrdopts] additional rrdtool options for all graphs | |
16 # [-t title] for graphs; '%1' is replaced with the type of graph | |
17 # [-s span] time covered by graphs. | |
18 # The default is "1day,1week,1month,1year" | |
19 # [-S stop-epoch] end of the graph | |
20 # [-y vresol] day, minute, ... vertical access for messages | |
21 # gname basic file name for graphs, - for stdout | |
22 # rrd1,... RRD databases that will be combined to produce the graphs | |
23 | |
24 # The rrd files must be initialzed with dcc-stats-init, which is called | |
25 # automatically by dcc-stats-collect. Data must be collected every | |
26 # 10 minutes with dcc-stats-collect. The rrd files should be in | |
27 # @prefix@/stats | |
28 | |
29 | |
30 # Copyright (c) 2008 by Rhyolite Software, LLC | |
31 # | |
32 # This agreement is not applicable to any entity which sells anti-spam | |
33 # solutions to others or provides an anti-spam solution as part of a | |
34 # security solution sold to other entities, or to a private network | |
35 # which employs the DCC or uses data provided by operation of the DCC | |
36 # but does not provide corresponding data to other users. | |
37 # | |
38 # Permission to use, copy, modify, and distribute this software without | |
39 # changes for any purpose with or without fee is hereby granted, provided | |
40 # that the above copyright notice and this permission notice appear in all | |
41 # copies and any distributed versions or copies are either unchanged | |
42 # or not called anything similar to "DCC" or "Distributed Checksum | |
43 # Clearinghouse". | |
44 # | |
45 # Parties not eligible to receive a license under this agreement can | |
46 # obtain a commercial license to use DCC by contacting Rhyolite Software | |
47 # at sales@rhyolite.com. | |
48 # | |
49 # A commercial license would be for Distributed Checksum and Reputation | |
50 # Clearinghouse software. That software includes additional features. This | |
51 # free license for Distributed ChecksumClearinghouse Software does not in any | |
52 # way grant permision to use Distributed Checksum and Reputation Clearinghouse | |
53 # software | |
54 # | |
55 # THE SOFTWARE IS PROVIDED "AS IS" AND RHYOLITE SOFTWARE, LLC DISCLAIMS ALL | |
56 # WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES | |
57 # OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL RHYOLITE SOFTWARE, LLC | |
58 # BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES | |
59 # OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, | |
60 # WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, | |
61 # ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS | |
62 # SOFTWARE. | |
63 # Rhyolite Software DCC 1.3.103-1.71 $Revision$ | |
64 # @configure_input@ | |
65 | |
66 DCC_HOMEDIR=@prefix@ | |
67 DEBUG= | |
68 RRDTOOL=@RRDTOOL@ | |
69 # check the args once to get the home directory | |
70 while getopts "xqBdRmh:G:T:O:t:s:S:y:" c; do | |
71 case $c in | |
72 x) set -x; DEBUG=-x=;; | |
73 h) DCC_HOMEDIR="$OPTARG";; | |
74 *) ;; | |
75 esac | |
76 done | |
77 . $DCC_HOMEDIR/dcc_conf | |
78 | |
79 BIG= | |
80 GRAPH_DB= | |
81 GRAPH_TRAFFIC= | |
82 GRAPH_RATIO= | |
83 GRAPH_SET= | |
84 RRDOPTS= | |
85 TITLE_SET= | |
86 SPANS_SET= | |
87 SPANS="1day,1week,1month,1year" | |
88 STOP= | |
89 YRESOL=86400 | |
90 YLABEL=day | |
91 USAGE="`basename $0`: [-xqB] [-h homedir] [-T rrdtool] [-O rrdopts] [-G type] | |
92 [t title] [-s spans] [-S stop-epoch] [-y day|hour|min|sec] gname rrd" | |
93 OPTIND=1 | |
94 while getopts "xqBdRmh:G:T:O:t:s:S:y:" c; do | |
95 case $c in | |
96 x) ;; # handled above | |
97 q) exec 1>/dev/null;; | |
98 h) ;; # handled above | |
99 B) BIG=yes;; | |
100 d) GRAPH_SET=yes; GRAPH_DB=yes;; # obsolete | |
101 R) GRAPH_RATIO=;; # obsolete | |
102 m) GRAPH_SET=yes; GRAPH_TRAFFIC=yes; GRAPH_RATIO=yes;; # obsolete | |
103 G) GRAPH_SET=yes | |
104 case "$OPTARG" in | |
105 db) GRAPH_DB=db;; | |
106 db-min) GRAPH_DB=db-min;; | |
107 traffic-noratio) GRAPH_TRAFFIC=yes;; | |
108 traffic) GRAPH_TRAFFIC=yes; GRAPH_RATIO=yes;; | |
109 ratio) GRAPH_RATIO=yes;; | |
110 *) echo "$USAGE" 1>&2; exit 1;; | |
111 esac | |
112 ;; | |
113 T) RRDTOOL="$OPTARG";; | |
114 O) RRDOPTS="$RRDOPTS $OPTARG";; | |
115 t) TITLE_SET=yes; TITLE_PAT="$OPTARG";; | |
116 s) SPANS_SET=yes; SPANS="$OPTARG";; | |
117 S) if expr "$OPTARG" : '[0-9]*$' >/dev/null \ | |
118 && test "$OPTARG" -gt 1033870038 \ | |
119 -a "$OPTARG" -lt 2000000000; then | |
120 STOP=$OPTARG | |
121 else | |
122 echo "$OPTARG is a bad number of seconds since the Epoch" 1>&2 | |
123 exit 1; | |
124 fi | |
125 ;; | |
126 y) | |
127 case "$OPTARG" in | |
128 day) YRESOL=86400; YLABEL=day;; | |
129 hour) YRESOL=3600; YLABEL=hour;; | |
130 min) YRESOL=60; YLABEL=min;; | |
131 sec) YRESOL=1; YLABEL=sec;; | |
132 esac | |
133 ;; | |
134 *) echo "$USAGE" 1>&2; exit 1;; | |
135 esac | |
136 done | |
137 shift `expr $OPTIND - 1 || true` | |
138 if test "$#" -lt 1; then | |
139 echo "$USAGE" 1>&2 | |
140 exit 1 | |
141 fi | |
142 | |
143 if test -z "$GRAPH_SET"; then | |
144 GRAPH_RATIO=yes # bug compatible with old versions | |
145 fi | |
146 | |
147 BASE_DIR="$DCC_HOMEDIR/stats" | |
148 cd "$BASE_DIR" | |
149 | |
150 GNAME=$1 | |
151 if test "$#" -ge 2; then | |
152 # assume .rrd file is same as the graph name if the .rrd file is absent | |
153 shift | |
154 fi | |
155 FILE=$1 | |
156 # trim unneeded directory names | |
157 FILE=`echo "$FILE" | sed -e "s@$BASE_DIR/*@@"` | |
158 if test ! -s "$FILE"; then | |
159 echo "$FILE is not a good rrd file" 1>&2 | |
160 exit 1 | |
161 fi | |
162 | |
163 if test "$TITLE_SET" != yes; then | |
164 if test "X$GNAME" != X-; then | |
165 TITLE_PAT="%1 at $GNAME" | |
166 else | |
167 TITLE_PAT="%1" | |
168 fi | |
169 fi | |
170 | |
171 if test -n "`$RRDTOOL version | grep '^RRDtool 1\.0'`"; then | |
172 RRDVERSION=1.0 | |
173 else | |
174 RRDVERSION= | |
175 fi | |
176 | |
177 if test -n "$BIG"; then | |
178 XYEAR_MONTHS=1 | |
179 GSIZE="--width 600 --height 240" | |
180 P_YGRID= # % or spam ratio vertical grid | |
181 M_YGRID= # messages vertical grid | |
182 H_YGRID="--alt-autoscale-max" # database vertical grid | |
183 M_YLABEL="message/$YLABEL" | |
184 AVGFMT="%.0lf/$YLABEL" | |
185 LABEL_REPORTS="total mail" | |
186 LABEL_BULK="likely spam" | |
187 LABEL_SPAM="trapped spam" | |
188 else | |
189 XYEAR_MONTHS=2 | |
190 GSIZE="--width 200 --height 40" | |
191 P_YGRID="--y-grid 25:2" | |
192 if test "$RRDVERSION" = 1.0; then | |
193 M_YGRID="--alt-y-mrtg" | |
194 H_YGRID="--alt-y-mrtg" | |
195 else | |
196 M_YGRID= | |
197 H_YGRID= | |
198 fi | |
199 M_YLABEL=msgs/$YLABEL | |
200 AVGFMT="%.1lf %S/$YLABEL" | |
201 LABEL_REPORTS="total" | |
202 LABEL_BULK="likely spam" | |
203 LABEL_SPAM="trapped" | |
204 fi | |
205 | |
206 # use only a few colors to try to be portable | |
207 C_GREEN='#00ff7f' | |
208 C_YELLOW='#ffff00' | |
209 C_PINK='#ffb6c1' | |
210 C_INDIANRED='#ff6a6a' | |
211 C_RED2='#ee0000' | |
212 C_BLUE='#0000ff' | |
213 C_SKY_BLUE='#87cefa' | |
214 C_ORANGE='#ffa500' | |
215 C_DARK_ORANGE='#ff8c00' | |
216 C_BLACK='#000000' | |
217 | |
218 | |
219 FTYPE=png | |
220 ATTRIBS="$GSIZE --imgformat PNG --lower-limit 0" | |
221 | |
222 | |
223 | |
224 # find good ending dates | |
225 date2ts () { | |
226 if test "$3" -eq 0; then | |
227 eval $1=new $2="' '" | |
228 return | |
229 fi | |
230 | |
231 NEW_END=$3 | |
232 if test -n "$4"; then | |
233 NEW_END=`expr $NEW_END - $NEW_END % $4 || true` | |
234 fi | |
235 eval $1=$NEW_END | |
236 | |
237 if NEW_TS=`date -r $NEW_END '+%x %R %Z' 2>/dev/null`; then : ; | |
238 else | |
239 # deal with systems that do not have `date -r` | |
240 NEW_TS=`@PERL@ -e "use POSIX qw(strftime); \ | |
241 print strftime '%x %R %Z', localtime($LAST);"` | |
242 fi | |
243 if test "$RRDVERSION" != 1.0; then | |
244 NEW_TS=`echo "$NEW_TS" | sed -e 's/:/\\\:/g'` | |
245 fi | |
246 eval $2="'COMMENT:$NEW_TS'" | |
247 } | |
248 | |
249 STEP=`$RRDTOOL info $FILE | sed -n -e 's/^step = \([0-9][0-9]*\)/\1/p'` | |
250 LAST=`$RRDTOOL last $FILE` | |
251 if test -n "$STOP" -a "$LAST" -gt 0"$STOP"; then | |
252 LAST="$STOP" | |
253 fi | |
254 # avoid odd times when individual servers were polled | |
255 LAST=`expr $LAST - $LAST % $STEP || true` | |
256 | |
257 date2ts END END_COMMENT $LAST | |
258 date2ts END_DAY END_DAY_COMMENT $LAST 86400 | |
259 | |
260 | |
261 for DUR in `echo $SPANS | tr ',' ' '`; do | |
262 case $DUR in | |
263 1d*) | |
264 DUR=1day | |
265 SPAN=24h | |
266 XGRID="--x-grid HOUR:1:HOUR:2:HOUR:2:0:%k" | |
267 # as the "rdtool graph" man page suggests, don't be fooled | |
268 # by daylight savings time | |
269 ;; | |
270 1w*) | |
271 DUR=1week | |
272 SPAN=168h | |
273 # 24*3600 = 86400 | |
274 if test -n "$BIG"; then | |
275 XGRID="--x-grid HOUR:6:DAY:1:DAY:1:86400:%a\ %m/%d" | |
276 else | |
277 XGRID="--x-grid HOUR:6:DAY:1:DAY:1:86400:%a" | |
278 fi | |
279 # as the "rdtool graph" man page suggests, don't be fooled | |
280 # by daylight savings time | |
281 ;; | |
282 1m*) | |
283 DUR=1month | |
284 SPAN=$DUR | |
285 XGRID="--x-grid WEEK:1:WEEK:1:WEEK:1:0:%b/%d" | |
286 ;; | |
287 1y*) | |
288 DUR=1year | |
289 SPAN=$DUR | |
290 # label every month on big graphs and every other on small | |
291 # 28*24*60*60 = 2419200 | |
292 XGRID="--x-grid MONTH:1:YEAR:1:MONTH:$XYEAR_MONTHS:2419200:%b" | |
293 ;; | |
294 2y*) | |
295 DUR=2years | |
296 SPAN=$DUR | |
297 if test "$XYEAR_MONTHS" = 2; then | |
298 # small graph with 1 label/year | |
299 # 365*24*60*60 = 31536000 = year | |
300 XGRID="--x-grid YEAR:1:YEAR:1:YEAR:1:31536000:%Y" | |
301 else | |
302 # label every other month on big graphs | |
303 # 28*24*60*60 = 2419200 | |
304 XYEAR_MONTHS=2 | |
305 XGRID="--x-grid MONTH:1:YEAR:1:MONTH:2:2419200:%b" | |
306 fi | |
307 ;; | |
308 *) | |
309 case $DUR in | |
310 3y*) DUR=3years;; | |
311 4y*) DUR=4years;; | |
312 # assume everything else is the 5 year maximum in the RRD files | |
313 *) DUR=5years;; | |
314 esac | |
315 SPAN=$DUR | |
316 if test "$XYEAR_MONTHS" = 2; then | |
317 # small graph with 1 label/year | |
318 # 365*24*60*60 = 31536000 = year | |
319 XGRID="--x-grid YEAR:1:YEAR:1:YEAR:1:31536000:%Y" | |
320 else | |
321 # big graph with 1 label/year | |
322 XGRID="--x-grid MONTH:1:MONTH:12:MONTH:12:0:%b/%y" | |
323 fi | |
324 ;; | |
325 esac | |
326 | |
327 ONAME=- | |
328 | |
329 PERCENT='reports,/,100,*,0,100,LIMIT' | |
330 if test $YRESOL -eq 1; then | |
331 YUNIT="0,1e12,LIMIT" | |
332 else | |
333 YUNIT="$YRESOL,*,0,1e12,LIMIT" | |
334 fi | |
335 | |
336 if test "$GRAPH_RATIO" = yes; then | |
337 if test "X$GNAME" != X-; then | |
338 ONAME=$GNAME-spam-ratio.$DUR.$FTYPE | |
339 echo "$ONAME: " | tr -d '\012' | |
340 fi | |
341 TITLE=`echo "$TITLE_PAT" | sed -e 's/%1/Spam Ratio/g'` | |
342 RATIOS="'CDEF:percentbulk=bulk,$PERCENT' \ | |
343 'CDEF:percentspam=spam,$PERCENT' \ | |
344 'AREA:percentbulk$C_INDIANRED:$LABEL_BULK' \ | |
345 'AREA:percentspam$C_PINK:$LABEL_SPAM'" | |
346 RATIOS="$RATIOS'\j' 'GPRINT:percentbulk:AVERAGE:%.0lf%%'" | |
347 if test -n "$BIG"; then | |
348 RATIOS="$RATIOS \ | |
349 '$END_COMMENT' \ | |
350 'GPRINT:percentspam:AVERAGE:%.0lf%%\j'" | |
351 else | |
352 RATIOS="$RATIOS '$END_COMMENT\j'" | |
353 fi | |
354 eval $RRDTOOL graph $ONAME "$RRDOPTS" \ | |
355 --end $END --start end-$SPAN \ | |
356 $ATTRIBS "--title '$TITLE'" \ | |
357 $XGRID $P_YGRID --upper-limit 100 \ | |
358 DEF:reports=$FILE:reports:AVERAGE \ | |
359 DEF:bulk=$FILE:bulk:AVERAGE \ | |
360 DEF:spam=$FILE:spam:AVERAGE \ | |
361 $RATIOS | |
362 if test "X$GNAME" = X-; then | |
363 exit | |
364 fi | |
365 fi | |
366 | |
367 if test "$GRAPH_TRAFFIC" = yes; then | |
368 if test "X$GNAME" != X-; then | |
369 ONAME=$GNAME-spam.$DUR.$FTYPE | |
370 echo "$ONAME: " | tr -d '\012' | |
371 fi | |
372 TITLE=`echo "$TITLE_PAT" | sed -e 's/%1/Mail Checked/g'` | |
373 if test -n "$BIG"; then | |
374 LEGEND="'GPRINT:greports:AVERAGE:$AVGFMT' \ | |
375 'GPRINT:gbulk:AVERAGE:$AVGFMT' \ | |
376 'GPRINT:gspam:AVERAGE:$AVGFMT'" | |
377 LEGEND="$LEGEND'\j' '$END_COMMENT\c'" | |
378 else | |
379 LEGEND="'GPRINT:greports:AVERAGE:$AVGFMT' '$END_COMMENT\j'" | |
380 fi | |
381 TRAFFIC="'DEF:reports=$FILE:reports:AVERAGE' \ | |
382 'CDEF:greports=reports,$YUNIT' \ | |
383 'DEF:bulk=$FILE:bulk:AVERAGE' \ | |
384 'CDEF:gbulk=bulk,$YUNIT' \ | |
385 'DEF:spam=$FILE:spam:AVERAGE' \ | |
386 'CDEF:gspam=spam,$YUNIT' \ | |
387 'AREA:greports$C_SKY_BLUE:$LABEL_REPORTS' \ | |
388 'AREA:gbulk$C_INDIANRED:$LABEL_BULK' \ | |
389 'AREA:gspam$C_PINK:$LABEL_SPAM'" | |
390 eval $RRDTOOL graph $ONAME "$RRDOPTS" \ | |
391 --end $END --start end-$SPAN \ | |
392 $ATTRIBS "--title '$TITLE'" \ | |
393 $XGRID $M_YGRID --vertical-label $M_YLABEL \ | |
394 $TRAFFIC"'\j'" $LEGEND | |
395 if test "X$GNAME" = X-; then | |
396 exit | |
397 fi | |
398 fi | |
399 | |
400 # database size graph | |
401 if test -n "$GRAPH_DB" -a \( -n "$SPANS_SET" -o $SPAN != 24h \); then | |
402 if test "X$GNAME" != X-; then | |
403 ONAME=$GNAME-hashes.$DUR.$FTYPE | |
404 echo "$ONAME: " | tr -d '\012' | |
405 fi | |
406 TITLE=`echo "$TITLE_PAT" | sed -e 's/%1/Checksums/g'` | |
407 # show only the minimum values for old RRD files | |
408 if test "$GRAPH_DB" = yes; then | |
409 if test -z "`$RRDTOOL info $FILE \ | |
410 | grep '^rra.*cf = .MAX.'`"; then | |
411 GRAPH_DB=db-min | |
412 fi | |
413 fi | |
414 if test "$GRAPH_DB" = db-min; then | |
415 DISPLAY="DEF:minhash=$FILE:hashes:MIN \ | |
416 AREA:minhash$C_PINK" | |
417 else | |
418 DISPLAY="DEF:minhash=$FILE:hashes:MIN \ | |
419 DEF:maxhash=$FILE:hashes:MAX \ | |
420 AREA:maxhash$C_INDIANRED:max \ | |
421 AREA:minhash$C_PINK:min" | |
422 fi | |
423 # take the database values from the last server | |
424 eval $RRDTOOL graph $ONAME $RRDOPTS \ | |
425 --end $END_DAY --start end-$SPAN \ | |
426 $ATTRIBS --step 86400 "--title '$TITLE'" \ | |
427 $XGRID $H_YGRID $DISPLAY "'$END_DAY_COMMENT\c'" | |
428 fi | |
429 done |