]> jfr.im git - irc/rqf/shadowircd.git/blame - src/s_stats.c
s_stats.c::tstats fixed
[irc/rqf/shadowircd.git] / src / s_stats.c
CommitLineData
212380e3 1/*
2 * ircd-ratbox: A slightly useful ircd.
3 * s_stats.c: Statistics related functions
4 *
5 * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center
6 * Copyright (C) 1996-2002 Hybrid Development Team
7 * Copyright (C) 2002-2005 ircd-ratbox development team
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22 * USA
23 *
68ff929f 24 * $Id: s_stats.c 3249 2007-03-05 18:51:17Z nenolod $
212380e3 25 */
26
27#include "stdinc.h"
28#include "s_stats.h"
29#include "client.h"
30#include "irc_string.h"
31#include "ircd.h"
32#include "numeric.h"
212380e3 33#include "send.h"
212380e3 34#include "s_conf.h"
35#include "s_newconf.h"
36#include "whowas.h"
37#include "hash.h"
38#include "scache.h"
39#include "reject.h"
40
41/*
42 * stats stuff
43 */
0e992f7e 44struct ServerStatistics ServerStats;
212380e3 45
46void
47init_stats()
48{
1ec2ad72 49 /* XXX nothing to do - was ServerStats init -- dwr */
212380e3 50}
51
52/*
53 * tstats
54 *
55 * inputs - client to report to
56 * output - NONE
57 * side effects -
58 */
0328101a
VY
59void\r
60tstats(struct Client *source_p)\r
61{\r
62 struct Client *target_p;\r
63 struct ServerStatistics sp;\r
64 rb_dlink_node *ptr;\r
65\r
66 memcpy(&sp, &ServerStats, sizeof(struct ServerStatistics));\r
67\r
68 RB_DLINK_FOREACH(ptr, serv_list.head)\r
69 {\r
70 target_p = ptr->data;\r
71\r
72 sp.is_sbs += target_p->localClient->sendB;\r
73 sp.is_sbr += target_p->localClient->receiveB;\r
74 sp.is_sti += rb_current_time() - target_p->localClient->firsttime;\r
75 sp.is_sv++;\r
76 }\r
77\r
78 RB_DLINK_FOREACH(ptr, lclient_list.head)\r
79 {\r
80 target_p = ptr->data;\r
81\r
82 sp.is_cbs += target_p->localClient->sendB;\r
83 sp.is_cbr += target_p->localClient->receiveB;\r
84 sp.is_cti += rb_current_time() - target_p->localClient->firsttime;\r
85 sp.is_cl++;\r
86 }\r
87\r
88 sendto_one_numeric(source_p, RPL_STATSDEBUG,\r
89 "T :accepts %u refused %u", \r
90 sp.is_ac, sp.is_ref);\r
91 sendto_one_numeric(source_p, RPL_STATSDEBUG,\r
92 "T :rejected %u delaying %lu", \r
93 sp.is_rej, delay_exit_length());\r
94 sendto_one_numeric(source_p, RPL_STATSDEBUG,\r
95 "T :nicks being delayed %lu", get_nd_count());\r
96 sendto_one_numeric(source_p, RPL_STATSDEBUG,\r
97 "T :unknown commands %u prefixes %u",\r
98 sp.is_unco, sp.is_unpf);\r
99 sendto_one_numeric(source_p, RPL_STATSDEBUG,\r
100 "T :nick collisions %u saves %u unknown closes %u",\r
101 sp.is_kill, sp.is_save, sp.is_ni);\r
102 sendto_one_numeric(source_p, RPL_STATSDEBUG,\r
103 "T :wrong direction %u empty %u", \r
104 sp.is_wrdi, sp.is_empt);\r
105 sendto_one_numeric(source_p, RPL_STATSDEBUG,\r
106 "T :numerics seen %u", \r
107 sp.is_num);\r
108 sendto_one_numeric(source_p, RPL_STATSDEBUG,\r
109 "T :auth successes %u fails %u",\r
110 sp.is_asuc, sp.is_abad);\r
111 sendto_one_numeric(source_p, RPL_STATSDEBUG, "T :Client Server");\r
112 sendto_one_numeric(source_p, RPL_STATSDEBUG,\r
113 "T :connected %u %u",\r
114 sp.is_cl, sp.is_sv);\r
115 sendto_one_numeric(source_p, RPL_STATSDEBUG,\r
116 "T :bytes sent %lluK %lluK",\r
117 sp.is_cbs / 1024, \r
118 sp.is_sbs / 1024);\r
119 sendto_one_numeric(source_p, RPL_STATSDEBUG,\r
120 "T :bytes recv %lluK %lluK",\r
121 sp.is_cbr / 1024, \r
122 sp.is_sbr / 1024);\r
123 sendto_one_numeric(source_p, RPL_STATSDEBUG,\r
124 "T :time connected %lu %lu",\r
125 sp.is_cti, sp.is_sti);\r
212380e3 126}
127
128void
129count_memory(struct Client *source_p)
130{
131 struct Client *target_p;
132 struct Channel *chptr;
133 struct Ban *actualBan;
af81d5a0
WP
134 rb_dlink_node *rb_dlink;
135 rb_dlink_node *ptr;
212380e3 136 int channel_count = 0;
137 int local_client_conf_count = 0; /* local client conf links */
138 int users_counted = 0; /* user structs */
139
140 int channel_users = 0;
141 int channel_invites = 0;
142 int channel_bans = 0;
143 int channel_except = 0;
144 int channel_invex = 0;
145 int channel_quiets = 0;
146
212380e3 147 int class_count = 0; /* classes */
148 int conf_count = 0; /* conf lines */
149 int users_invited_count = 0; /* users invited */
150 int user_channels = 0; /* users in channels */
151 int aways_counted = 0;
152 size_t number_servers_cached; /* number of servers cached by scache */
153
154 size_t channel_memory = 0;
155 size_t channel_ban_memory = 0;
156 size_t channel_except_memory = 0;
157 size_t channel_invex_memory = 0;
158 size_t channel_quiet_memory = 0;
159
160 size_t away_memory = 0; /* memory used by aways */
d8027cae 161 size_t ww = 0; /* whowas array count */
212380e3 162 size_t wwm = 0; /* whowas array memory used */
163 size_t conf_memory = 0; /* memory used by conf lines */
164 size_t mem_servers_cached; /* memory used by scache */
165
166 size_t linebuf_count = 0;
167 size_t linebuf_memory_used = 0;
168
169 size_t total_channel_memory = 0;
170 size_t totww = 0;
171
172 size_t local_client_count = 0;
173 size_t local_client_memory_used = 0;
174
175 size_t remote_client_count = 0;
176 size_t remote_client_memory_used = 0;
177
178 size_t total_memory = 0;
179
d8027cae 180 count_whowas_memory(&ww, &wwm);
212380e3 181
8e69bb4e 182 RB_DLINK_FOREACH(ptr, global_client_list.head)
212380e3 183 {
184 target_p = ptr->data;
185 if(MyConnect(target_p))
186 {
187 local_client_conf_count++;
188 }
189
190 if(target_p->user)
191 {
192 users_counted++;
af81d5a0
WP
193 users_invited_count += rb_dlink_list_length(&target_p->user->invited);
194 user_channels += rb_dlink_list_length(&target_p->user->channel);
212380e3 195 if(target_p->user->away)
196 {
197 aways_counted++;
198 away_memory += (strlen(target_p->user->away) + 1);
199 }
200 }
201 }
202
203 /* Count up all channels, ban lists, except lists, Invex lists */
8e69bb4e 204 RB_DLINK_FOREACH(ptr, global_channel_list.head)
212380e3 205 {
206 chptr = ptr->data;
207 channel_count++;
208 channel_memory += (strlen(chptr->chname) + sizeof(struct Channel));
209
af81d5a0
WP
210 channel_users += rb_dlink_list_length(&chptr->members);
211 channel_invites += rb_dlink_list_length(&chptr->invites);
212380e3 212
8e69bb4e 213 RB_DLINK_FOREACH(rb_dlink, chptr->banlist.head)
212380e3 214 {
af81d5a0 215 actualBan = rb_dlink->data;
212380e3 216 channel_bans++;
217
af81d5a0 218 channel_ban_memory += sizeof(rb_dlink_node) + sizeof(struct Ban);
212380e3 219 }
220
8e69bb4e 221 RB_DLINK_FOREACH(rb_dlink, chptr->exceptlist.head)
212380e3 222 {
af81d5a0 223 actualBan = rb_dlink->data;
212380e3 224 channel_except++;
225
af81d5a0 226 channel_except_memory += (sizeof(rb_dlink_node) + sizeof(struct Ban));
212380e3 227 }
228
8e69bb4e 229 RB_DLINK_FOREACH(rb_dlink, chptr->invexlist.head)
212380e3 230 {
af81d5a0 231 actualBan = rb_dlink->data;
212380e3 232 channel_invex++;
233
af81d5a0 234 channel_invex_memory += (sizeof(rb_dlink_node) + sizeof(struct Ban));
212380e3 235 }
236
8e69bb4e 237 RB_DLINK_FOREACH(rb_dlink, chptr->quietlist.head)
212380e3 238 {
af81d5a0 239 actualBan = rb_dlink->data;
212380e3 240 channel_quiets++;
241
af81d5a0 242 channel_quiet_memory += (sizeof(rb_dlink_node) + sizeof(struct Ban));
212380e3 243 }
244 }
245
246 /* count up all classes */
247
af81d5a0 248 class_count = rb_dlink_list_length(&class_list) + 1;
212380e3 249
411559c8 250 rb_count_rb_linebuf_memory(&linebuf_count, &linebuf_memory_used);
212380e3 251
252 sendto_one_numeric(source_p, RPL_STATSDEBUG,
253 "z :Users %u(%lu) Invites %u(%lu)",
254 users_counted,
255 (unsigned long) users_counted * sizeof(struct User),
256 users_invited_count,
af81d5a0 257 (unsigned long) users_invited_count * sizeof(rb_dlink_node));
212380e3 258
259 sendto_one_numeric(source_p, RPL_STATSDEBUG,
260 "z :User channels %u(%lu) Aways %u(%d)",
261 user_channels,
af81d5a0 262 (unsigned long) user_channels * sizeof(rb_dlink_node),
212380e3 263 aways_counted, (int) away_memory);
264
265 sendto_one_numeric(source_p, RPL_STATSDEBUG,
266 "z :Attached confs %u(%lu)",
267 local_client_conf_count,
af81d5a0 268 (unsigned long) local_client_conf_count * sizeof(rb_dlink_node));
212380e3 269
270 sendto_one_numeric(source_p, RPL_STATSDEBUG,
271 "z :Conflines %u(%d)", conf_count, (int) conf_memory);
272
273 sendto_one_numeric(source_p, RPL_STATSDEBUG,
274 "z :Classes %u(%lu)",
275 class_count,
276 (unsigned long) class_count * sizeof(struct Class));
277
278 sendto_one_numeric(source_p, RPL_STATSDEBUG,
279 "z :Channels %u(%d)",
280 channel_count, (int) channel_memory);
281
282 sendto_one_numeric(source_p, RPL_STATSDEBUG,
283 "z :Bans %u(%d) Exceptions %u(%d) Invex %u(%d) Quiets %u(%d)",
284 channel_bans, (int) channel_ban_memory,
285 channel_except, (int) channel_except_memory,
286 channel_invex, (int) channel_invex_memory,
287 channel_quiets, (int) channel_quiet_memory);
288
289 sendto_one_numeric(source_p, RPL_STATSDEBUG,
290 "z :Channel members %u(%lu) invite %u(%lu)",
291 channel_users,
af81d5a0 292 (unsigned long) channel_users * sizeof(rb_dlink_node),
212380e3 293 channel_invites,
af81d5a0 294 (unsigned long) channel_invites * sizeof(rb_dlink_node));
212380e3 295
296 total_channel_memory = channel_memory +
297 channel_ban_memory +
af81d5a0 298 channel_users * sizeof(rb_dlink_node) + channel_invites * sizeof(rb_dlink_node);
212380e3 299
300 sendto_one_numeric(source_p, RPL_STATSDEBUG,
d8027cae
JT
301 "z :Whowas array %ld(%ld)",
302 (long)ww, (long)wwm);
212380e3 303
d8027cae 304 totww = wwm;
212380e3 305
306 sendto_one_numeric(source_p, RPL_STATSDEBUG,
307 "z :Hash: client %u(%ld) chan %u(%ld)",
af81d5a0
WP
308 U_MAX, (long)(U_MAX * sizeof(rb_dlink_list)),
309 CH_MAX, (long)(CH_MAX * sizeof(rb_dlink_list)));
212380e3 310
311 sendto_one_numeric(source_p, RPL_STATSDEBUG,
312 "z :linebuf %ld(%ld)",
313 (long)linebuf_count, (long)linebuf_memory_used);
314
315 count_scache(&number_servers_cached, &mem_servers_cached);
316
317 sendto_one_numeric(source_p, RPL_STATSDEBUG,
318 "z :scache %ld(%ld)",
319 (long)number_servers_cached, (long)mem_servers_cached);
320
321 sendto_one_numeric(source_p, RPL_STATSDEBUG,
322 "z :hostname hash %d(%ld)",
af81d5a0 323 HOST_MAX, (long)HOST_MAX * sizeof(rb_dlink_list));
212380e3 324
325 total_memory = totww + total_channel_memory + conf_memory +
326 class_count * sizeof(struct Class);
327
328 total_memory += mem_servers_cached;
329 sendto_one_numeric(source_p, RPL_STATSDEBUG,
330 "z :Total: whowas %d channel %d conf %d",
331 (int) totww, (int) total_channel_memory,
332 (int) conf_memory);
333
334 count_local_client_memory(&local_client_count, &local_client_memory_used);
335 total_memory += local_client_memory_used;
336
337 sendto_one_numeric(source_p, RPL_STATSDEBUG,
338 "z :Local client Memory in use: %ld(%ld)",
339 (long)local_client_count, (long)local_client_memory_used);
340
341
342 count_remote_client_memory(&remote_client_count, &remote_client_memory_used);
343 total_memory += remote_client_memory_used;
344
345 sendto_one_numeric(source_p, RPL_STATSDEBUG,
346 "z :Remote client Memory in use: %ld(%ld)",
347 (long)remote_client_count,
348 (long)remote_client_memory_used);
212380e3 349}