2 * ircd-ratbox: A slightly useful ircd.
3 * s_stats.c: Statistics related functions
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
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.
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.
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
24 * $Id: s_stats.c 3249 2007-03-05 18:51:17Z nenolod $
30 #include "irc_string.h"
35 #include "s_newconf.h"
44 struct ServerStatistics ServerStats
;
49 memset(&ircst
, 0, sizeof(ircst
));
55 * inputs - client to report to
60 tstats(struct Client
*source_p
)
62 struct Client
*target_p
;
63 struct ServerStatistics
*sp
;
64 struct ServerStatistics tmp
;
68 memcpy(sp
, ServerStats
, sizeof(struct ServerStatistics
));
70 RB_DLINK_FOREACH(ptr
, serv_list
.head
)
74 sp
->is_sbs
+= target_p
->localClient
->sendB
;
75 sp
->is_sbr
+= target_p
->localClient
->receiveB
;
76 sp
->is_sks
+= target_p
->localClient
->sendK
;
77 sp
->is_skr
+= target_p
->localClient
->receiveK
;
78 sp
->is_sti
+= rb_current_time() - target_p
->localClient
->firsttime
;
82 sp
->is_sks
+= (sp
->is_sbs
>> 10);
87 sp
->is_skr
+= (sp
->is_sbr
>> 10);
92 RB_DLINK_FOREACH(ptr
, lclient_list
.head
)
96 sp
->is_cbs
+= target_p
->localClient
->sendB
;
97 sp
->is_cbr
+= target_p
->localClient
->receiveB
;
98 sp
->is_cks
+= target_p
->localClient
->sendK
;
99 sp
->is_ckr
+= target_p
->localClient
->receiveK
;
100 sp
->is_cti
+= rb_current_time() - target_p
->localClient
->firsttime
;
102 if(sp
->is_cbs
> 1023)
104 sp
->is_cks
+= (sp
->is_cbs
>> 10);
107 if(sp
->is_cbr
> 1023)
109 sp
->is_ckr
+= (sp
->is_cbr
>> 10);
115 RB_DLINK_FOREACH(ptr
, unknown_list
.head
)
120 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
121 "T :accepts %u refused %u", sp
->is_ac
, sp
->is_ref
);
122 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
123 "T :rejected %u delaying %lu",
124 sp
->is_rej
, rb_dlink_list_length(&delay_exit
));
125 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
126 "T :nicks being delayed %lu",
128 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
129 "T :unknown commands %u prefixes %u",
130 sp
->is_unco
, sp
->is_unpf
);
131 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
132 "T :nick collisions %u saves %u unknown closes %u",
133 sp
->is_kill
, sp
->is_save
, sp
->is_ni
);
134 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
135 "T :wrong direction %u empty %u",
136 sp
->is_wrdi
, sp
->is_empt
);
137 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
138 "T :numerics seen %u", sp
->is_num
);
139 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
140 "T :tgchange blocked msgs %u restricted addrs %lu",
141 sp
->is_tgch
, rb_dlink_list_length(&tgchange_list
));
142 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
143 "T :auth successes %u fails %u",
144 sp
->is_asuc
, sp
->is_abad
);
145 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
146 "T :sasl successes %u fails %u",
147 sp
->is_ssuc
, sp
->is_sbad
);
148 sendto_one_numeric(source_p
, RPL_STATSDEBUG
, "T :Client Server");
149 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
150 "T :connected %u %u", sp
->is_cl
, sp
->is_sv
);
151 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
152 "T :bytes sent %d.%uK %d.%uK",
153 (int) sp
->is_cks
, sp
->is_cbs
,
154 (int) sp
->is_sks
, sp
->is_sbs
);
155 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
156 "T :bytes recv %d.%uK %d.%uK",
157 (int) sp
->is_ckr
, sp
->is_cbr
,
158 (int) sp
->is_skr
, sp
->is_sbr
);
159 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
160 "T :time connected %d %d",
161 (int) sp
->is_cti
, (int) sp
->is_sti
);
165 count_memory(struct Client
*source_p
)
167 struct Client
*target_p
;
168 struct Channel
*chptr
;
169 struct Ban
*actualBan
;
170 rb_dlink_node
*rb_dlink
;
172 int channel_count
= 0;
173 int local_client_conf_count
= 0; /* local client conf links */
174 int users_counted
= 0; /* user structs */
176 int channel_users
= 0;
177 int channel_invites
= 0;
178 int channel_bans
= 0;
179 int channel_except
= 0;
180 int channel_invex
= 0;
181 int channel_quiets
= 0;
183 int class_count
= 0; /* classes */
184 int conf_count
= 0; /* conf lines */
185 int users_invited_count
= 0; /* users invited */
186 int user_channels
= 0; /* users in channels */
187 int aways_counted
= 0;
188 size_t number_servers_cached
; /* number of servers cached by scache */
190 size_t channel_memory
= 0;
191 size_t channel_ban_memory
= 0;
192 size_t channel_except_memory
= 0;
193 size_t channel_invex_memory
= 0;
194 size_t channel_quiet_memory
= 0;
196 size_t away_memory
= 0; /* memory used by aways */
197 size_t ww
= 0; /* whowas array count */
198 size_t wwm
= 0; /* whowas array memory used */
199 size_t conf_memory
= 0; /* memory used by conf lines */
200 size_t mem_servers_cached
; /* memory used by scache */
202 size_t linebuf_count
= 0;
203 size_t linebuf_memory_used
= 0;
205 size_t total_channel_memory
= 0;
208 size_t local_client_count
= 0;
209 size_t local_client_memory_used
= 0;
211 size_t remote_client_count
= 0;
212 size_t remote_client_memory_used
= 0;
214 size_t total_memory
= 0;
216 count_whowas_memory(&ww
, &wwm
);
218 RB_DLINK_FOREACH(ptr
, global_client_list
.head
)
220 target_p
= ptr
->data
;
221 if(MyConnect(target_p
))
223 local_client_conf_count
++;
229 users_invited_count
+= rb_dlink_list_length(&target_p
->user
->invited
);
230 user_channels
+= rb_dlink_list_length(&target_p
->user
->channel
);
231 if(target_p
->user
->away
)
234 away_memory
+= (strlen(target_p
->user
->away
) + 1);
239 /* Count up all channels, ban lists, except lists, Invex lists */
240 RB_DLINK_FOREACH(ptr
, global_channel_list
.head
)
244 channel_memory
+= (strlen(chptr
->chname
) + sizeof(struct Channel
));
246 channel_users
+= rb_dlink_list_length(&chptr
->members
);
247 channel_invites
+= rb_dlink_list_length(&chptr
->invites
);
249 RB_DLINK_FOREACH(rb_dlink
, chptr
->banlist
.head
)
251 actualBan
= rb_dlink
->data
;
254 channel_ban_memory
+= sizeof(rb_dlink_node
) + sizeof(struct Ban
);
257 RB_DLINK_FOREACH(rb_dlink
, chptr
->exceptlist
.head
)
259 actualBan
= rb_dlink
->data
;
262 channel_except_memory
+= (sizeof(rb_dlink_node
) + sizeof(struct Ban
));
265 RB_DLINK_FOREACH(rb_dlink
, chptr
->invexlist
.head
)
267 actualBan
= rb_dlink
->data
;
270 channel_invex_memory
+= (sizeof(rb_dlink_node
) + sizeof(struct Ban
));
273 RB_DLINK_FOREACH(rb_dlink
, chptr
->quietlist
.head
)
275 actualBan
= rb_dlink
->data
;
278 channel_quiet_memory
+= (sizeof(rb_dlink_node
) + sizeof(struct Ban
));
282 /* count up all classes */
284 class_count
= rb_dlink_list_length(&class_list
) + 1;
286 rb_count_rb_linebuf_memory(&linebuf_count
, &linebuf_memory_used
);
288 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
289 "z :Users %u(%lu) Invites %u(%lu)",
291 (unsigned long) users_counted
* sizeof(struct User
),
293 (unsigned long) users_invited_count
* sizeof(rb_dlink_node
));
295 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
296 "z :User channels %u(%lu) Aways %u(%d)",
298 (unsigned long) user_channels
* sizeof(rb_dlink_node
),
299 aways_counted
, (int) away_memory
);
301 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
302 "z :Attached confs %u(%lu)",
303 local_client_conf_count
,
304 (unsigned long) local_client_conf_count
* sizeof(rb_dlink_node
));
306 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
307 "z :Conflines %u(%d)", conf_count
, (int) conf_memory
);
309 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
310 "z :Classes %u(%lu)",
312 (unsigned long) class_count
* sizeof(struct Class
));
314 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
315 "z :Channels %u(%d)",
316 channel_count
, (int) channel_memory
);
318 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
319 "z :Bans %u(%d) Exceptions %u(%d) Invex %u(%d) Quiets %u(%d)",
320 channel_bans
, (int) channel_ban_memory
,
321 channel_except
, (int) channel_except_memory
,
322 channel_invex
, (int) channel_invex_memory
,
323 channel_quiets
, (int) channel_quiet_memory
);
325 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
326 "z :Channel members %u(%lu) invite %u(%lu)",
328 (unsigned long) channel_users
* sizeof(rb_dlink_node
),
330 (unsigned long) channel_invites
* sizeof(rb_dlink_node
));
332 total_channel_memory
= channel_memory
+
334 channel_users
* sizeof(rb_dlink_node
) + channel_invites
* sizeof(rb_dlink_node
);
336 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
337 "z :Whowas array %ld(%ld)",
338 (long)ww
, (long)wwm
);
342 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
343 "z :Hash: client %u(%ld) chan %u(%ld)",
344 U_MAX
, (long)(U_MAX
* sizeof(rb_dlink_list
)),
345 CH_MAX
, (long)(CH_MAX
* sizeof(rb_dlink_list
)));
347 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
348 "z :linebuf %ld(%ld)",
349 (long)linebuf_count
, (long)linebuf_memory_used
);
351 count_scache(&number_servers_cached
, &mem_servers_cached
);
353 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
354 "z :scache %ld(%ld)",
355 (long)number_servers_cached
, (long)mem_servers_cached
);
357 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
358 "z :hostname hash %d(%ld)",
359 HOST_MAX
, (long)HOST_MAX
* sizeof(rb_dlink_list
));
361 total_memory
= totww
+ total_channel_memory
+ conf_memory
+
362 class_count
* sizeof(struct Class
);
364 total_memory
+= mem_servers_cached
;
365 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
366 "z :Total: whowas %d channel %d conf %d",
367 (int) totww
, (int) total_channel_memory
,
370 count_local_client_memory(&local_client_count
, &local_client_memory_used
);
371 total_memory
+= local_client_memory_used
;
373 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
374 "z :Local client Memory in use: %ld(%ld)",
375 (long)local_client_count
, (long)local_client_memory_used
);
378 count_remote_client_memory(&remote_client_count
, &remote_client_memory_used
);
379 total_memory
+= remote_client_memory_used
;
381 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
382 "z :Remote client Memory in use: %ld(%ld)",
383 (long)remote_client_count
,
384 (long)remote_client_memory_used
);