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 static struct ServerStatistics ircst
;
45 struct ServerStatistics
*ServerStats
= &ircst
;
50 memset(&ircst
, 0, sizeof(ircst
));
56 * inputs - client to report to
61 tstats(struct Client
*source_p
)
63 struct Client
*target_p
;
64 struct ServerStatistics
*sp
;
65 struct ServerStatistics tmp
;
69 memcpy(sp
, ServerStats
, sizeof(struct ServerStatistics
));
71 RB_DLINK_FOREACH(ptr
, serv_list
.head
)
75 sp
->is_sbs
+= target_p
->localClient
->sendB
;
76 sp
->is_sbr
+= target_p
->localClient
->receiveB
;
77 sp
->is_sks
+= target_p
->localClient
->sendK
;
78 sp
->is_skr
+= target_p
->localClient
->receiveK
;
79 sp
->is_sti
+= rb_current_time() - target_p
->localClient
->firsttime
;
83 sp
->is_sks
+= (sp
->is_sbs
>> 10);
88 sp
->is_skr
+= (sp
->is_sbr
>> 10);
93 RB_DLINK_FOREACH(ptr
, lclient_list
.head
)
97 sp
->is_cbs
+= target_p
->localClient
->sendB
;
98 sp
->is_cbr
+= target_p
->localClient
->receiveB
;
99 sp
->is_cks
+= target_p
->localClient
->sendK
;
100 sp
->is_ckr
+= target_p
->localClient
->receiveK
;
101 sp
->is_cti
+= rb_current_time() - target_p
->localClient
->firsttime
;
103 if(sp
->is_cbs
> 1023)
105 sp
->is_cks
+= (sp
->is_cbs
>> 10);
108 if(sp
->is_cbr
> 1023)
110 sp
->is_ckr
+= (sp
->is_cbr
>> 10);
116 RB_DLINK_FOREACH(ptr
, unknown_list
.head
)
121 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
122 "T :accepts %u refused %u", sp
->is_ac
, sp
->is_ref
);
123 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
124 "T :rejected %u delaying %lu",
125 sp
->is_rej
, rb_dlink_list_length(&delay_exit
));
126 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
127 "T :nicks being delayed %lu",
129 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
130 "T :unknown commands %u prefixes %u",
131 sp
->is_unco
, sp
->is_unpf
);
132 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
133 "T :nick collisions %u saves %u unknown closes %u",
134 sp
->is_kill
, sp
->is_save
, sp
->is_ni
);
135 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
136 "T :wrong direction %u empty %u",
137 sp
->is_wrdi
, sp
->is_empt
);
138 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
139 "T :numerics seen %u", sp
->is_num
);
140 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
141 "T :tgchange blocked msgs %u restricted addrs %lu",
142 sp
->is_tgch
, rb_dlink_list_length(&tgchange_list
));
143 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
144 "T :auth successes %u fails %u",
145 sp
->is_asuc
, sp
->is_abad
);
146 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
147 "T :sasl successes %u fails %u",
148 sp
->is_ssuc
, sp
->is_sbad
);
149 sendto_one_numeric(source_p
, RPL_STATSDEBUG
, "T :Client Server");
150 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
151 "T :connected %u %u", sp
->is_cl
, sp
->is_sv
);
152 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
153 "T :bytes sent %d.%uK %d.%uK",
154 (int) sp
->is_cks
, sp
->is_cbs
,
155 (int) sp
->is_sks
, sp
->is_sbs
);
156 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
157 "T :bytes recv %d.%uK %d.%uK",
158 (int) sp
->is_ckr
, sp
->is_cbr
,
159 (int) sp
->is_skr
, sp
->is_sbr
);
160 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
161 "T :time connected %d %d",
162 (int) sp
->is_cti
, (int) sp
->is_sti
);
166 count_memory(struct Client
*source_p
)
168 struct Client
*target_p
;
169 struct Channel
*chptr
;
170 struct Ban
*actualBan
;
171 rb_dlink_node
*rb_dlink
;
173 int channel_count
= 0;
174 int local_client_conf_count
= 0; /* local client conf links */
175 int users_counted
= 0; /* user structs */
177 int channel_users
= 0;
178 int channel_invites
= 0;
179 int channel_bans
= 0;
180 int channel_except
= 0;
181 int channel_invex
= 0;
182 int channel_quiets
= 0;
184 int class_count
= 0; /* classes */
185 int conf_count
= 0; /* conf lines */
186 int users_invited_count
= 0; /* users invited */
187 int user_channels
= 0; /* users in channels */
188 int aways_counted
= 0;
189 size_t number_servers_cached
; /* number of servers cached by scache */
191 size_t channel_memory
= 0;
192 size_t channel_ban_memory
= 0;
193 size_t channel_except_memory
= 0;
194 size_t channel_invex_memory
= 0;
195 size_t channel_quiet_memory
= 0;
197 size_t away_memory
= 0; /* memory used by aways */
198 size_t ww
= 0; /* whowas array count */
199 size_t wwm
= 0; /* whowas array memory used */
200 size_t conf_memory
= 0; /* memory used by conf lines */
201 size_t mem_servers_cached
; /* memory used by scache */
203 size_t linebuf_count
= 0;
204 size_t linebuf_memory_used
= 0;
206 size_t total_channel_memory
= 0;
209 size_t local_client_count
= 0;
210 size_t local_client_memory_used
= 0;
212 size_t remote_client_count
= 0;
213 size_t remote_client_memory_used
= 0;
215 size_t total_memory
= 0;
217 count_whowas_memory(&ww
, &wwm
);
219 RB_DLINK_FOREACH(ptr
, global_client_list
.head
)
221 target_p
= ptr
->data
;
222 if(MyConnect(target_p
))
224 local_client_conf_count
++;
230 users_invited_count
+= rb_dlink_list_length(&target_p
->user
->invited
);
231 user_channels
+= rb_dlink_list_length(&target_p
->user
->channel
);
232 if(target_p
->user
->away
)
235 away_memory
+= (strlen(target_p
->user
->away
) + 1);
240 /* Count up all channels, ban lists, except lists, Invex lists */
241 RB_DLINK_FOREACH(ptr
, global_channel_list
.head
)
245 channel_memory
+= (strlen(chptr
->chname
) + sizeof(struct Channel
));
247 channel_users
+= rb_dlink_list_length(&chptr
->members
);
248 channel_invites
+= rb_dlink_list_length(&chptr
->invites
);
250 RB_DLINK_FOREACH(rb_dlink
, chptr
->banlist
.head
)
252 actualBan
= rb_dlink
->data
;
255 channel_ban_memory
+= sizeof(rb_dlink_node
) + sizeof(struct Ban
);
258 RB_DLINK_FOREACH(rb_dlink
, chptr
->exceptlist
.head
)
260 actualBan
= rb_dlink
->data
;
263 channel_except_memory
+= (sizeof(rb_dlink_node
) + sizeof(struct Ban
));
266 RB_DLINK_FOREACH(rb_dlink
, chptr
->invexlist
.head
)
268 actualBan
= rb_dlink
->data
;
271 channel_invex_memory
+= (sizeof(rb_dlink_node
) + sizeof(struct Ban
));
274 RB_DLINK_FOREACH(rb_dlink
, chptr
->quietlist
.head
)
276 actualBan
= rb_dlink
->data
;
279 channel_quiet_memory
+= (sizeof(rb_dlink_node
) + sizeof(struct Ban
));
283 /* count up all classes */
285 class_count
= rb_dlink_list_length(&class_list
) + 1;
287 count_linebuf_memory(&linebuf_count
, &linebuf_memory_used
);
289 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
290 "z :Users %u(%lu) Invites %u(%lu)",
292 (unsigned long) users_counted
* sizeof(struct User
),
294 (unsigned long) users_invited_count
* sizeof(rb_dlink_node
));
296 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
297 "z :User channels %u(%lu) Aways %u(%d)",
299 (unsigned long) user_channels
* sizeof(rb_dlink_node
),
300 aways_counted
, (int) away_memory
);
302 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
303 "z :Attached confs %u(%lu)",
304 local_client_conf_count
,
305 (unsigned long) local_client_conf_count
* sizeof(rb_dlink_node
));
307 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
308 "z :Conflines %u(%d)", conf_count
, (int) conf_memory
);
310 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
311 "z :Classes %u(%lu)",
313 (unsigned long) class_count
* sizeof(struct Class
));
315 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
316 "z :Channels %u(%d)",
317 channel_count
, (int) channel_memory
);
319 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
320 "z :Bans %u(%d) Exceptions %u(%d) Invex %u(%d) Quiets %u(%d)",
321 channel_bans
, (int) channel_ban_memory
,
322 channel_except
, (int) channel_except_memory
,
323 channel_invex
, (int) channel_invex_memory
,
324 channel_quiets
, (int) channel_quiet_memory
);
326 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
327 "z :Channel members %u(%lu) invite %u(%lu)",
329 (unsigned long) channel_users
* sizeof(rb_dlink_node
),
331 (unsigned long) channel_invites
* sizeof(rb_dlink_node
));
333 total_channel_memory
= channel_memory
+
335 channel_users
* sizeof(rb_dlink_node
) + channel_invites
* sizeof(rb_dlink_node
);
337 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
338 "z :Whowas array %ld(%ld)",
339 (long)ww
, (long)wwm
);
343 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
344 "z :Hash: client %u(%ld) chan %u(%ld)",
345 U_MAX
, (long)(U_MAX
* sizeof(rb_dlink_list
)),
346 CH_MAX
, (long)(CH_MAX
* sizeof(rb_dlink_list
)));
348 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
349 "z :linebuf %ld(%ld)",
350 (long)linebuf_count
, (long)linebuf_memory_used
);
352 count_scache(&number_servers_cached
, &mem_servers_cached
);
354 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
355 "z :scache %ld(%ld)",
356 (long)number_servers_cached
, (long)mem_servers_cached
);
358 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
359 "z :hostname hash %d(%ld)",
360 HOST_MAX
, (long)HOST_MAX
* sizeof(rb_dlink_list
));
362 total_memory
= totww
+ total_channel_memory
+ conf_memory
+
363 class_count
* sizeof(struct Class
);
365 total_memory
+= mem_servers_cached
;
366 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
367 "z :Total: whowas %d channel %d conf %d",
368 (int) totww
, (int) total_channel_memory
,
371 count_local_client_memory(&local_client_count
, &local_client_memory_used
);
372 total_memory
+= local_client_memory_used
;
374 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
375 "z :Local client Memory in use: %ld(%ld)",
376 (long)local_client_count
, (long)local_client_memory_used
);
379 count_remote_client_memory(&remote_client_count
, &remote_client_memory_used
);
380 total_memory
+= remote_client_memory_used
;
382 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
383 "z :Remote client Memory in use: %ld(%ld)",
384 (long)remote_client_count
,
385 (long)remote_client_memory_used
);