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 /* XXX nothing to do - was ServerStats init -- dwr */
55 * inputs - client to report to
60 tstats(struct Client
*source_p
)
62 struct Client
*target_p
;
63 struct ServerStatistics sp
;
66 memcpy(&sp
, &ServerStats
, sizeof(struct ServerStatistics
));
68 RB_DLINK_FOREACH(ptr
, serv_list
.head
)
72 sp
.is_sbs
+= target_p
->localClient
->sendB
;
73 sp
.is_sbr
+= target_p
->localClient
->receiveB
;
74 sp
.is_sti
+= rb_current_time() - target_p
->localClient
->firsttime
;
78 RB_DLINK_FOREACH(ptr
, lclient_list
.head
)
82 sp
.is_cbs
+= target_p
->localClient
->sendB
;
83 sp
.is_cbr
+= target_p
->localClient
->receiveB
;
84 sp
.is_cti
+= rb_current_time() - target_p
->localClient
->firsttime
;
88 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
89 "T :accepts %u refused %u",
91 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
92 "T :rejected %u delaying %lu",
93 sp
.is_rej
, delay_exit_length());
94 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
95 "T :nicks being delayed %lu", get_nd_count());
96 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
97 "T :unknown commands %u prefixes %u",
98 sp
.is_unco
, sp
.is_unpf
);
99 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
100 "T :nick collisions %u saves %u unknown closes %u",
101 sp
.is_kill
, sp
.is_save
, sp
.is_ni
);
102 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
103 "T :wrong direction %u empty %u",
104 sp
.is_wrdi
, sp
.is_empt
);
105 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
106 "T :numerics seen %u",
108 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
109 "T :auth successes %u fails %u",
110 sp
.is_asuc
, sp
.is_abad
);
111 sendto_one_numeric(source_p
, RPL_STATSDEBUG
, "T :Client Server");
112 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
113 "T :connected %u %u",
115 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
116 "T :bytes sent %lluK %lluK",
119 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
120 "T :bytes recv %lluK %lluK",
123 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
124 "T :time connected %lu %lu",
125 sp
.is_cti
, sp
.is_sti
);
129 count_memory(struct Client
*source_p
)
131 struct Client
*target_p
;
132 struct Channel
*chptr
;
133 struct Ban
*actualBan
;
134 rb_dlink_node
*rb_dlink
;
136 int channel_count
= 0;
137 int local_client_conf_count
= 0; /* local client conf links */
138 int users_counted
= 0; /* user structs */
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;
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 */
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;
160 size_t away_memory
= 0; /* memory used by aways */
161 size_t ww
= 0; /* whowas array count */
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 */
166 size_t linebuf_count
= 0;
167 size_t linebuf_memory_used
= 0;
169 size_t total_channel_memory
= 0;
172 size_t local_client_count
= 0;
173 size_t local_client_memory_used
= 0;
175 size_t remote_client_count
= 0;
176 size_t remote_client_memory_used
= 0;
178 size_t total_memory
= 0;
180 count_whowas_memory(&ww
, &wwm
);
182 RB_DLINK_FOREACH(ptr
, global_client_list
.head
)
184 target_p
= ptr
->data
;
185 if(MyConnect(target_p
))
187 local_client_conf_count
++;
193 users_invited_count
+= rb_dlink_list_length(&target_p
->user
->invited
);
194 user_channels
+= rb_dlink_list_length(&target_p
->user
->channel
);
195 if(target_p
->user
->away
)
198 away_memory
+= (strlen(target_p
->user
->away
) + 1);
203 /* Count up all channels, ban lists, except lists, Invex lists */
204 RB_DLINK_FOREACH(ptr
, global_channel_list
.head
)
208 channel_memory
+= (strlen(chptr
->chname
) + sizeof(struct Channel
));
210 channel_users
+= rb_dlink_list_length(&chptr
->members
);
211 channel_invites
+= rb_dlink_list_length(&chptr
->invites
);
213 RB_DLINK_FOREACH(rb_dlink
, chptr
->banlist
.head
)
215 actualBan
= rb_dlink
->data
;
218 channel_ban_memory
+= sizeof(rb_dlink_node
) + sizeof(struct Ban
);
221 RB_DLINK_FOREACH(rb_dlink
, chptr
->exceptlist
.head
)
223 actualBan
= rb_dlink
->data
;
226 channel_except_memory
+= (sizeof(rb_dlink_node
) + sizeof(struct Ban
));
229 RB_DLINK_FOREACH(rb_dlink
, chptr
->invexlist
.head
)
231 actualBan
= rb_dlink
->data
;
234 channel_invex_memory
+= (sizeof(rb_dlink_node
) + sizeof(struct Ban
));
237 RB_DLINK_FOREACH(rb_dlink
, chptr
->quietlist
.head
)
239 actualBan
= rb_dlink
->data
;
242 channel_quiet_memory
+= (sizeof(rb_dlink_node
) + sizeof(struct Ban
));
246 /* count up all classes */
248 class_count
= rb_dlink_list_length(&class_list
) + 1;
250 rb_count_rb_linebuf_memory(&linebuf_count
, &linebuf_memory_used
);
252 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
253 "z :Users %u(%lu) Invites %u(%lu)",
255 (unsigned long) users_counted
* sizeof(struct User
),
257 (unsigned long) users_invited_count
* sizeof(rb_dlink_node
));
259 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
260 "z :User channels %u(%lu) Aways %u(%d)",
262 (unsigned long) user_channels
* sizeof(rb_dlink_node
),
263 aways_counted
, (int) away_memory
);
265 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
266 "z :Attached confs %u(%lu)",
267 local_client_conf_count
,
268 (unsigned long) local_client_conf_count
* sizeof(rb_dlink_node
));
270 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
271 "z :Conflines %u(%d)", conf_count
, (int) conf_memory
);
273 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
274 "z :Classes %u(%lu)",
276 (unsigned long) class_count
* sizeof(struct Class
));
278 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
279 "z :Channels %u(%d)",
280 channel_count
, (int) channel_memory
);
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
);
289 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
290 "z :Channel members %u(%lu) invite %u(%lu)",
292 (unsigned long) channel_users
* sizeof(rb_dlink_node
),
294 (unsigned long) channel_invites
* sizeof(rb_dlink_node
));
296 total_channel_memory
= channel_memory
+
298 channel_users
* sizeof(rb_dlink_node
) + channel_invites
* sizeof(rb_dlink_node
);
300 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
301 "z :Whowas array %ld(%ld)",
302 (long)ww
, (long)wwm
);
306 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
307 "z :Hash: client %u(%ld) chan %u(%ld)",
308 U_MAX
, (long)(U_MAX
* sizeof(rb_dlink_list
)),
309 CH_MAX
, (long)(CH_MAX
* sizeof(rb_dlink_list
)));
311 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
312 "z :linebuf %ld(%ld)",
313 (long)linebuf_count
, (long)linebuf_memory_used
);
315 count_scache(&number_servers_cached
, &mem_servers_cached
);
317 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
318 "z :scache %ld(%ld)",
319 (long)number_servers_cached
, (long)mem_servers_cached
);
321 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
322 "z :hostname hash %d(%ld)",
323 HOST_MAX
, (long)HOST_MAX
* sizeof(rb_dlink_list
));
325 total_memory
= totww
+ total_channel_memory
+ conf_memory
+
326 class_count
* sizeof(struct Class
);
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
,
334 count_local_client_memory(&local_client_count
, &local_client_memory_used
);
335 total_memory
+= local_client_memory_used
;
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
);
342 count_remote_client_memory(&remote_client_count
, &remote_client_memory_used
);
343 total_memory
+= remote_client_memory_used
;
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
);