comparison misc/stats-get.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
2
3 # get statistics from a DCC server
4 # [-x] debugging
5 # [-q] quiet
6 # [-S] read `cdcc stats` from stdin
7 # [-s stats-file] save raw `cdcc stats` output in stats-file
8 # [-i client-ID] that DCC server will accept
9 # [-p password] that DCC server will accept
10 # host server to ask for numbers
11
12 # A single line of 5 decimal numbers separated by colons is sent to stdout:
13 # For example,
14 # 115492:71318:44694:2462909:155924
15 # means the DCC server has
16 # 115492 received reports of checksums from DCC clients
17 # 71318 received reports where the target count was >= 10
18 # 44694 received reports where the target count was "many"
19 # 2462909 entries in its hash table
20 # 155924 received reports by flooding
21
22
23 # Copyright (c) 2008 by Rhyolite Software, LLC
24 #
25 # This agreement is not applicable to any entity which sells anti-spam
26 # solutions to others or provides an anti-spam solution as part of a
27 # security solution sold to other entities, or to a private network
28 # which employs the DCC or uses data provided by operation of the DCC
29 # but does not provide corresponding data to other users.
30 #
31 # Permission to use, copy, modify, and distribute this software without
32 # changes for any purpose with or without fee is hereby granted, provided
33 # that the above copyright notice and this permission notice appear in all
34 # copies and any distributed versions or copies are either unchanged
35 # or not called anything similar to "DCC" or "Distributed Checksum
36 # Clearinghouse".
37 #
38 # Parties not eligible to receive a license under this agreement can
39 # obtain a commercial license to use DCC by contacting Rhyolite Software
40 # at sales@rhyolite.com.
41 #
42 # A commercial license would be for Distributed Checksum and Reputation
43 # Clearinghouse software. That software includes additional features. This
44 # free license for Distributed ChecksumClearinghouse Software does not in any
45 # way grant permision to use Distributed Checksum and Reputation Clearinghouse
46 # software
47 #
48 # THE SOFTWARE IS PROVIDED "AS IS" AND RHYOLITE SOFTWARE, LLC DISCLAIMS ALL
49 # WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
50 # OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL RHYOLITE SOFTWARE, LLC
51 # BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES
52 # OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
53 # WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
54 # ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
55 # SOFTWARE.
56 # Rhyolite Software DCC 1.3.103-1.20 $Revision$
57 # @configure_input@
58
59 DEBUG=
60 QUIET=
61 STATSFILE=
62 STATSFILE_NEW=/dev/null
63 CLNT_ID="1"
64 PASSWD=
65 USAGE="`basename $0`: [-xqS] [-s stats-file] [-i client-ID] [-p password] [host]"
66 while getopts "xqSs:i:p:" c; do
67 case $c in
68 x) set -x; DEBUG=-x;;
69 q) QUIET="-q";;
70 S) USE_STDIN=yes;;
71 s) if test $OPTARG != /dev/null; then
72 STATSFILE=$OPTARG
73 STATSFILE_NEW=$STATSFILE.$$
74 trap "/bin/rm -f $STATSFILE_NEW" 0 1 2 15
75 fi
76 ;;
77 i) CLNT_ID="$OPTARG";;
78 p) if test "$OPTARG" != ""; then
79 PASSWD="password $OPTARG;"
80 fi
81 ;;
82 *) echo "$USAGE" 1>&2; exit 1;;
83 esac
84 done
85 shift `expr $OPTIND - 1 || true`
86 if test "$#" -ne 1; then
87 if test "$#" -ne 0 -o -z "$USE_STDIN"; then
88 echo "$USAGE" 1>&2
89 exit 1
90 fi
91 fi
92
93 HOST=$1
94
95 if test "$USE_STDIN" = yes; then
96 cat
97 else
98 exec </dev/null
99 if test -n "$QUIET"; then
100 @bindir@/cdcc "id $CLNT_ID; $PASSWD host $HOST; stats" 2>/dev/null
101 else
102 @bindir@/cdcc "id $CLNT_ID; $PASSWD host $HOST; stats"
103 fi
104 fi \
105 | tee $STATSFILE_NEW \
106 | awk '
107 /hash entries/{
108 hashes = $4;
109 }
110 /query/{
111 queries = $8;
112 if (queries ~ /^-/) {
113 # negative numbers are 32-bit overflows
114 queries = 4294967296 + queries;
115 }
116 }
117 /reports.*many/{
118 reports = $1;
119 if (reports ~ /^-/) {
120 reports = 4294967296 + reports;
121 }
122 }
123 /answers.*>10/{
124 split($2,bulk,">");
125 if (bulk[1] ~ /^-/) {
126 bulk[1] = 4294967296 + bulk[1];
127 }
128 spam=$5;
129 if (spam ~ /^-/) {
130 spam = 4294967296 + spam;
131 }
132 }
133 /accepted/{
134 flooded=$1;
135 if (flooded ~ /^-/) {
136 flooded = 4294967296 + flooded;
137 }
138 }
139 END {
140 printf "%s:%s:%s:%s:%s\n",
141 reports+queries, bulk[1], spam, hashes, flooded;
142 }'
143
144 if test $STATSFILE_NEW != /dev/null -a -s $STATSFILE_NEW; then
145 rm -f $STATSFILE
146 mv $STATSFILE_NEW $STATSFILE
147 fi