0
|
1 #! /bin/sh |
|
2 |
|
3 # initialize an RRD file to collect DCC statistics |
|
4 # [-x] debugging |
|
5 # [-q] quiet |
|
6 # [-h dcc_homedir] |
|
7 # [-D data-dir] where to put the rrdtool file |
|
8 # [-T @RRDTOOL@] |
|
9 # see http://people.ee.ethz.ch/~oetiker/webtools/rrdtool/ |
|
10 # or the FreeBSD package. |
|
11 # [-O rrdopts] "--heartbeat X" or "--step Y" |
|
12 # file RRD database that receives the collected data |
|
13 |
|
14 |
|
15 # Copyright (c) 2008 by Rhyolite Software, LLC |
|
16 # |
|
17 # This agreement is not applicable to any entity which sells anti-spam |
|
18 # solutions to others or provides an anti-spam solution as part of a |
|
19 # security solution sold to other entities, or to a private network |
|
20 # which employs the DCC or uses data provided by operation of the DCC |
|
21 # but does not provide corresponding data to other users. |
|
22 # |
|
23 # Permission to use, copy, modify, and distribute this software without |
|
24 # changes for any purpose with or without fee is hereby granted, provided |
|
25 # that the above copyright notice and this permission notice appear in all |
|
26 # copies and any distributed versions or copies are either unchanged |
|
27 # or not called anything similar to "DCC" or "Distributed Checksum |
|
28 # Clearinghouse". |
|
29 # |
|
30 # Parties not eligible to receive a license under this agreement can |
|
31 # obtain a commercial license to use DCC by contacting Rhyolite Software |
|
32 # at sales@rhyolite.com. |
|
33 # |
|
34 # A commercial license would be for Distributed Checksum and Reputation |
|
35 # Clearinghouse software. That software includes additional features. This |
|
36 # free license for Distributed ChecksumClearinghouse Software does not in any |
|
37 # way grant permision to use Distributed Checksum and Reputation Clearinghouse |
|
38 # software |
|
39 # |
|
40 # THE SOFTWARE IS PROVIDED "AS IS" AND RHYOLITE SOFTWARE, LLC DISCLAIMS ALL |
|
41 # WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES |
|
42 # OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL RHYOLITE SOFTWARE, LLC |
|
43 # BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES |
|
44 # OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, |
|
45 # WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, |
|
46 # ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS |
|
47 # SOFTWARE. |
|
48 # Rhyolite Software DCC 1.3.103-1.25 $Revision$ |
|
49 # @configure_input@ |
|
50 |
|
51 exec 1>&2 </dev/null |
|
52 |
|
53 DCC_HOMEDIR=@prefix@ |
|
54 DEBUG= |
|
55 # check the args once to get the home directory |
|
56 while getopts "xqRh:D:T:O:" c; do |
|
57 case $c in |
|
58 x) set -x; DEBUG=-x=;; |
|
59 h) DCC_HOMEDIR="$OPTARG";; |
|
60 *) ;; |
|
61 esac |
|
62 done |
|
63 . $DCC_HOMEDIR/dcc_conf |
|
64 |
|
65 REPS= |
|
66 DATADIR=$DCC_HOMEDIR/stats |
|
67 RRDTOOL=@RRDTOOL@ |
|
68 RRDOPTS= |
|
69 USAGE="`basename $0`: [-xqR] [-h homedir] [-D data-dir] [-T rrdtool] |
|
70 [-O rrdopts] file.rrd" |
|
71 OPTIND=1 |
|
72 while getopts "xqRh:D:T:O:" c; do |
|
73 case $c in |
|
74 x) ;; # handled above |
|
75 q) QUIET=quiet;; |
|
76 R) REPS=yes;; |
|
77 h) ;; # handled above |
|
78 D) DATADIR="$OPTARG";; |
|
79 T) RRDTOOL="$OPTARG";; |
|
80 O) RRDOPTS="$RRDOPTS $OPTARG";; |
|
81 *) echo "$USAGE" 1>&2; exit 1;; |
|
82 esac |
|
83 done |
|
84 shift `expr $OPTIND - 1 || true` |
|
85 if test "$#" -ne 1; then |
|
86 echo "$USAGE" 1>&2 |
|
87 exit 1 |
|
88 fi |
|
89 FILE=$1 |
|
90 |
|
91 if test ! -d $DATADIR; then |
|
92 mkdir $DATADIR |
|
93 fi |
|
94 cd $DATADIR |
|
95 |
|
96 if test "$FILE" = "`basename $FILE .rrd`"; then |
|
97 FILE=$FILE.rrd |
|
98 fi |
|
99 if test -s "$FILE"; then |
|
100 echo "$FILE already exists" 1>&2 |
|
101 exit 1 |
|
102 fi |
|
103 |
|
104 |
|
105 # assume no server will handle more than 1000 operations/second |
|
106 OPSPS=1000 |
|
107 |
|
108 # default sample every 10 minutes. |
|
109 STEP=600 |
|
110 |
|
111 # be willing to get STEP and heartbeat from the -O arg(s) |
|
112 HBEAT= |
|
113 while test -n "$RRDOPTS"; do |
|
114 RRDOPTS=`expr "X$RRDOPTS" : 'X *\(.*\)'` |
|
115 if test -z "$RRDOPTS"; then |
|
116 break; |
|
117 fi |
|
118 X=`expr "X$RRDOPTS" : 'X--heartbeat[ ][ ]*\([0-9][0-9]*\)'` |
|
119 if test -n "$X"; then |
|
120 HBEAT=$X |
|
121 RRDOPTS=`expr "X$RRDOPTS" : "X--heartbeat[ ]$X *\(.\)"` |
|
122 continue |
|
123 fi |
|
124 X=`expr "X$RRDOPTS" : 'X--step[ ][ ]*\([0-9][0-9]*\)'` |
|
125 if test -n "$X"; then |
|
126 STEP=$X |
|
127 RRDOPTS=`expr "X$RRDOPTS" : "X--step[ ]$X *\(.\)"` |
|
128 continue |
|
129 fi |
|
130 echo 'unrecognized RRD option "'"$RRDOPTS"'"' 1>&2 |
|
131 exit 1 |
|
132 done |
|
133 |
|
134 # Use a heartbeat of 31 minutes or 1860 seconds to allow a missed sample as |
|
135 # well as jitter by cron. If you use a heartbeat equal to the cron |
|
136 # repetition rate, then a single second delay by cron will make the previous |
|
137 # period have no samples and be undefined. |
|
138 if test -z "$HBEAT"; then |
|
139 HBEAT=`expr $STEP \* 3 + 60` |
|
140 fi |
|
141 |
|
142 # Keep hourly (or 6-step) average data for 5 years |
|
143 HOUR_STEPS=`expr 3600 / $STEP` |
|
144 HOUR_ROWS=`expr \( 5 \* 366 \* 24 \* 3600 \) / \( $STEP \* 6 \)` |
|
145 |
|
146 # Keep 10-minute (or single-step) average data for a month |
|
147 FAST_ROWS=`expr 31 \* 24 \* $HOUR_STEPS` |
|
148 |
|
149 # Keep daily database size data for 5 years |
|
150 DB_STEPS=`expr \( 3600 \* 24 \) / $STEP` |
|
151 DB_ROWS=`expr 5 \* 366` |
|
152 |
|
153 $RRDTOOL create $FILE --step $STEP --start -61month \ |
|
154 DS:reports:DERIVE:$HBEAT:0:$OPSPS \ |
|
155 DS:bulk:DERIVE:$HBEAT:0:$OPSPS \ |
|
156 DS:spam:DERIVE:$HBEAT:0:$OPSPS \ |
|
157 DS:hashes:GAUGE:$HBEAT:U:U \ |
|
158 RRA:AVERAGE:0.5:$HOUR_STEPS:$HOUR_ROWS \ |
|
159 RRA:AVERAGE:0.04:1:$FAST_ROWS \ |
|
160 RRA:MIN:0.9:$DB_STEPS:$DB_ROWS \ |
|
161 RRA:MAX:0.9:$DB_STEPS:$DB_ROWS |