1 |
/* Copyright (C) 2003 Stephane Thiell |
2 |
* |
3 |
* This file is part of pxyservd (from pxys) |
4 |
* |
5 |
* This program is free software; you can redistribute it and/or |
6 |
* modify it under the terms of the GNU General Public License |
7 |
* as published by the Free Software Foundation; either version 2 |
8 |
* of the License, or (at your option) any later version. |
9 |
* |
10 |
* This program is distributed in the hope that it will be useful, |
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 |
* GNU General Public License for more details. |
14 |
* |
15 |
* You should have received a copy of the GNU General Public License |
16 |
* along with this program; if not, write to the Free Software |
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
18 |
* |
19 |
*/ |
20 |
#define RCSID "$Id: cmd_pxstats.c,v 1.1.1.1 2003/12/30 17:09:29 mbuna Exp $" |
21 |
|
22 |
#include "irc_cmd.h" |
23 |
#include "irc_send.h" |
24 |
|
25 |
#include "irc_numnicks.h" |
26 |
#include "scan.h" |
27 |
#include "PXServiceMsg.h" |
28 |
|
29 |
#include <peak/peak.h> |
30 |
|
31 |
void |
32 |
cmd_pxstats(struct Client *cptr, toktabptr ttab) |
33 |
{ |
34 |
const char *dst = ttab->tok[0]; |
35 |
|
36 |
send_client_to_one(dst, "\2PXSTATS\2"); |
37 |
|
38 |
if (scan_send_simple_command(cptr, PXYSCAND_SIG, PX_CMD_STATS) == -1) |
39 |
send_client_to_one(dst, "/!\\ Scanner daemon not connected." |
40 |
" Can't retrieve stats data from pxyscand."); |
41 |
} |
42 |
|
43 |
void |
44 |
cmd_pxstats_reply(struct Client *cptr, PXSStats *stats) |
45 |
{ |
46 |
char dst[6]; |
47 |
uint32_t v1, v2; |
48 |
double pt; |
49 |
|
50 |
inttobase64(dst, cptr->nserv, 2); |
51 |
inttobase64(dst + 2, cptr->nnick, 3); |
52 |
dst[5] = '\0'; |
53 |
|
54 |
send_client_to_one(dst, "Received stats from %s", stats->version); |
55 |
send_client_to_one(dst, "--------------------------------"); |
56 |
send_client_to_one(dst, "Global counters: query %lu scanned %lu " |
57 |
"proxy %lu", |
58 |
ntohl(stats->servQueryCount), |
59 |
ntohl(stats->servScannedCount), |
60 |
ntohl(stats->servProxyCount)); |
61 |
send_client_to_one(dst, "Cache hits: IPCache %lu PXCache %lu", |
62 |
ntohl(stats->servIPCacheHits), |
63 |
ntohl(stats->servPXCacheHits)); |
64 |
send_client_to_one(dst, "Scan already in progress counter: %lu", |
65 |
ntohl(stats->servInProgressCount)); |
66 |
send_client_to_one(dst, "Scanner's \"noscan\" list hits: %lu", |
67 |
ntohl(stats->servNoScanHits)); |
68 |
send_client_to_one(dst, "--------------------------------"); |
69 |
send_client_to_one(dst, "IP CACHES:"); |
70 |
v1 = ntohl(stats->servIP4CacheCount); |
71 |
v2 = ntohl(stats->servIP4CacheSize); |
72 |
pt = v2 > 0 ? 100.0 * (double)v1/(double)v2 : 0.; |
73 |
send_client_to_one(dst, "IPv4 \"no proxy\" cache: %lu/%lu IPs (%.1f%%)", |
74 |
v1, v2, pt); |
75 |
send_client_to_one(dst, "IPv4 \"no proxy\" cache expiration delay: %d secs", |
76 |
ntohl(stats->servIP4CacheExpire)); |
77 |
v1 = ntohl(stats->servPX4CacheCount); |
78 |
v2 = ntohl(stats->servPX4CacheSize); |
79 |
pt = v2 > 0 ? 100.0 * (double)v1/(double)v2 : 0.; |
80 |
send_client_to_one(dst, "IPv4 \"proxy\" cache: %lu/%lu IPs (%.1f%%)", |
81 |
v1, v2, pt); |
82 |
send_client_to_one(dst, "IPv4 \"proxy\" cache expiration delay: %d secs", |
83 |
ntohl(stats->servPX4CacheExpire)); |
84 |
send_client_to_one(dst, "--------------------------------"); |
85 |
|
86 |
send_client_to_one(dst, "Current OPAS session:"); |
87 |
|
88 |
send_client_to_one(dst, "Counters: query %lu error %lu", |
89 |
ntohl(stats->sessQueryCount), |
90 |
ntohl(stats->sessErrorCount)); |
91 |
|
92 |
v1 = ntohl(stats->sessScannedCount); |
93 |
v2 = ntohl(stats->sessProxyCount); |
94 |
pt = v1 > 0 ? 100.0 * (double)v2 / (double) v1 : 0.; |
95 |
send_client_to_one(dst, "Counters: scanned %lu proxy %lu (%g%%)", |
96 |
v1, v2, pt); |
97 |
send_client_to_one(dst, "Session traffic: read %lu write %lu (bytes)", |
98 |
ntohl(stats->sessReadBytes), |
99 |
ntohl(stats->sessWriteBytes)); |
100 |
send_client_to_one(dst, "--------------------------------"); |
101 |
|
102 |
send_client_to_one(dst, "OPAS sessions count: current %lu total %lu " |
103 |
"rejected %lu", |
104 |
ntohl(stats->sessCurrent), |
105 |
ntohl(stats->sessCount), |
106 |
ntohl(stats->sessRejectedCount)); |
107 |
} |