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 26 2006-09-20 18:02:06Z spb $
30 #include "irc_string.h"
37 #include "s_newconf.h"
46 static struct ServerStatistics ircst
;
47 struct ServerStatistics
*ServerStats
= &ircst
;
52 memset(&ircst
, 0, sizeof(ircst
));
58 * inputs - client to report to
63 tstats(struct Client
*source_p
)
65 struct Client
*target_p
;
66 struct ServerStatistics
*sp
;
67 struct ServerStatistics tmp
;
71 memcpy(sp
, ServerStats
, sizeof(struct ServerStatistics
));
73 DLINK_FOREACH(ptr
, serv_list
.head
)
77 sp
->is_sbs
+= target_p
->localClient
->sendB
;
78 sp
->is_sbr
+= target_p
->localClient
->receiveB
;
79 sp
->is_sks
+= target_p
->localClient
->sendK
;
80 sp
->is_skr
+= target_p
->localClient
->receiveK
;
81 sp
->is_sti
+= CurrentTime
- target_p
->localClient
->firsttime
;
85 sp
->is_sks
+= (sp
->is_sbs
>> 10);
90 sp
->is_skr
+= (sp
->is_sbr
>> 10);
95 DLINK_FOREACH(ptr
, lclient_list
.head
)
99 sp
->is_cbs
+= target_p
->localClient
->sendB
;
100 sp
->is_cbr
+= target_p
->localClient
->receiveB
;
101 sp
->is_cks
+= target_p
->localClient
->sendK
;
102 sp
->is_ckr
+= target_p
->localClient
->receiveK
;
103 sp
->is_cti
+= CurrentTime
- target_p
->localClient
->firsttime
;
105 if(sp
->is_cbs
> 1023)
107 sp
->is_cks
+= (sp
->is_cbs
>> 10);
110 if(sp
->is_cbr
> 1023)
112 sp
->is_ckr
+= (sp
->is_cbr
>> 10);
118 DLINK_FOREACH(ptr
, unknown_list
.head
)
123 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
124 "T :accepts %u refused %u", sp
->is_ac
, sp
->is_ref
);
125 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
126 "T :rejected %u delaying %lu",
127 sp
->is_rej
, dlink_list_length(&delay_exit
));
128 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
129 "T :nicks being delayed %lu",
131 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
132 "T :unknown commands %u prefixes %u",
133 sp
->is_unco
, sp
->is_unpf
);
134 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
135 "T :nick collisions %u saves %u unknown closes %u",
136 sp
->is_kill
, sp
->is_save
, sp
->is_ni
);
137 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
138 "T :wrong direction %u empty %u",
139 sp
->is_wrdi
, sp
->is_empt
);
140 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
141 "T :numerics seen %u", sp
->is_num
);
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
;
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 size_t wwu
= 0; /* whowas users */
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 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(&wwu
, &wwm
);
218 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
+= dlink_list_length(&target_p
->user
->invited
);
230 user_channels
+= 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 DLINK_FOREACH(ptr
, global_channel_list
.head
)
244 channel_memory
+= (strlen(chptr
->chname
) + sizeof(struct Channel
));
246 channel_users
+= dlink_list_length(&chptr
->members
);
247 channel_invites
+= dlink_list_length(&chptr
->invites
);
249 DLINK_FOREACH(dlink
, chptr
->banlist
.head
)
251 actualBan
= dlink
->data
;
254 channel_ban_memory
+= sizeof(dlink_node
) + sizeof(struct Ban
);
257 DLINK_FOREACH(dlink
, chptr
->exceptlist
.head
)
259 actualBan
= dlink
->data
;
262 channel_except_memory
+= (sizeof(dlink_node
) + sizeof(struct Ban
));
265 DLINK_FOREACH(dlink
, chptr
->invexlist
.head
)
267 actualBan
= dlink
->data
;
270 channel_invex_memory
+= (sizeof(dlink_node
) + sizeof(struct Ban
));
273 DLINK_FOREACH(dlink
, chptr
->quietlist
.head
)
275 actualBan
= dlink
->data
;
278 channel_quiet_memory
+= (sizeof(dlink_node
) + sizeof(struct Ban
));
282 /* count up all classes */
284 class_count
= dlink_list_length(&class_list
) + 1;
286 count_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(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(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(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(dlink_node
),
330 (unsigned long) channel_invites
* sizeof(dlink_node
));
332 total_channel_memory
= channel_memory
+
334 channel_users
* sizeof(dlink_node
) + channel_invites
* sizeof(dlink_node
);
336 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
337 "z :Whowas users %ld(%ld)",
338 (long)wwu
, (long) (wwu
* sizeof(struct User
)));
340 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
341 "z :Whowas array %u(%d)",
342 NICKNAMEHISTORYLENGTH
, (int) wwm
);
344 totww
= wwu
* sizeof(struct User
) + wwm
;
346 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
347 "z :Hash: client %u(%ld) chan %u(%ld)",
348 U_MAX
, (long)(U_MAX
* sizeof(dlink_list
)),
349 CH_MAX
, (long)(CH_MAX
* sizeof(dlink_list
)));
351 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
352 "z :linebuf %ld(%ld)",
353 (long)linebuf_count
, (long)linebuf_memory_used
);
355 count_scache(&number_servers_cached
, &mem_servers_cached
);
357 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
358 "z :scache %ld(%ld)",
359 (long)number_servers_cached
, (long)mem_servers_cached
);
361 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
362 "z :hostname hash %d(%ld)",
363 HOST_MAX
, (long)HOST_MAX
* sizeof(dlink_list
));
365 total_memory
= totww
+ total_channel_memory
+ conf_memory
+
366 class_count
* sizeof(struct Class
);
368 total_memory
+= mem_servers_cached
;
369 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
370 "z :Total: whowas %d channel %d conf %d",
371 (int) totww
, (int) total_channel_memory
,
374 count_local_client_memory(&local_client_count
, &local_client_memory_used
);
375 total_memory
+= local_client_memory_used
;
377 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
378 "z :Local client Memory in use: %ld(%ld)",
379 (long)local_client_count
, (long)local_client_memory_used
);
382 count_remote_client_memory(&remote_client_count
, &remote_client_memory_used
);
383 total_memory
+= remote_client_memory_used
;
385 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
386 "z :Remote client Memory in use: %ld(%ld)",
387 (long)remote_client_count
,
388 (long)remote_client_memory_used
);
390 sendto_one_numeric(source_p
, RPL_STATSDEBUG
,
391 "z :TOTAL: %d Available: Current max RSS: %lu",
392 (int) total_memory
, get_maxrss());