From: Pekka Riikonen Date: Sat, 15 Jun 2002 16:06:53 +0000 (+0000) Subject: Added statistics updating and statisics dumping with SIGUSR1. X-Git-Tag: silc.toolkit.0.9.2~4 X-Git-Url: http://git.silcnet.org/gitweb/?p=silc.git;a=commitdiff_plain;h=9be2c37303ca7ee9f860e3a3b3d625fae88b0cea Added statistics updating and statisics dumping with SIGUSR1. --- diff --git a/CHANGES b/CHANGES index 78742aa6..715fed19 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,12 @@ +Sat Jun 15 18:23:39 EEST 2002 Pekka Riikonen + + * Added lots of new statistics updating that was missing from + the server and router code. Affected files in silcd/. + + * Sending SIGUSR1 signal to server now dumps the current + server statistics into /tmp directory. Affected file is + silcd/silcd.c. + Sat Jun 15 12:09:14 EEST 2002 Pekka Riikonen * Added some better info printing for client during connecting. diff --git a/TODO b/TODO index 3ab775e2..737c025e 100644 --- a/TODO +++ b/TODO @@ -30,8 +30,6 @@ TODO/bugs In SILC Server each JOIN command will create and distribute the new channel key to everybody on the channel (Fix this to 0.9.x). - o Lots of statistics updating is missing around the server. - o If client's public key is saved in the server (and doing public key authentication) then the hostname and the username information could be taken from the public key. Should be a configuration option! diff --git a/apps/silcd/command.c b/apps/silcd/command.c index 6efee9d0..168f7bb3 100644 --- a/apps/silcd/command.c +++ b/apps/silcd/command.c @@ -3420,6 +3420,13 @@ static void silc_server_command_join_channel(SilcServer server, clidp->data, clidp->len, chidp->data, chidp->len); + /* Update statistics */ + server->stat.my_chanclients++; + if (server->server_type == SILC_ROUTER) { + server->stat.cell_chanclients++; + server->stat.chanclients++; + } + if (!cmd->pending) { /* Send JOIN notify packet to our primary router */ if (!server->standalone) @@ -3859,6 +3866,22 @@ SILC_SERVER_CMD_FUNC(umode) } } + /* Update statistics */ + if (mask & SILC_UMODE_GONE) { + if (!client->mode & SILC_UMODE_GONE) + server->stat.my_aways++; + } else { + if (client->mode & SILC_UMODE_GONE) + server->stat.my_aways--; + } + if (mask & SILC_UMODE_DETACHED) { + if (!client->mode & SILC_UMODE_DETACHED) + server->stat.my_detached++; + } else { + if (client->mode & SILC_UMODE_DETACHED) + server->stat.my_detached--; + } + /* Change the mode */ client->mode = mask; diff --git a/apps/silcd/command_reply.c b/apps/silcd/command_reply.c index 22fe1f1c..a904d3a5 100644 --- a/apps/silcd/command_reply.c +++ b/apps/silcd/command_reply.c @@ -892,6 +892,7 @@ SILC_SERVER_CMD_REPLY_FUNC(join) goto out; } server->stat.my_channels++; + server->stat.channels++; } else { /* The entry exists. */ diff --git a/apps/silcd/packet_receive.c b/apps/silcd/packet_receive.c index 67454f94..a2a756a0 100644 --- a/apps/silcd/packet_receive.c +++ b/apps/silcd/packet_receive.c @@ -233,6 +233,13 @@ void silc_server_notify(SilcServer server, channel->user_count++; channel->disabled = FALSE; + /* Update statistics */ + if (server->server_type == SILC_ROUTER) { + if (sock->type != SILC_SOCKET_TYPE_ROUTER) + server->stat.cell_chanclients++; + server->stat.chanclients++; + } + break; case SILC_NOTIFY_TYPE_LEAVE: @@ -1195,7 +1202,9 @@ void silc_server_notify(SilcServer server, silc_idlist_del_server(local ? server->local_list : server->global_list, server_entry); - /* XXX update statistics */ + /* Update statistics */ + if (server->server_type == SILC_ROUTER) + server->stat.servers--; break; @@ -1430,6 +1439,24 @@ void silc_server_notify(SilcServer server, if (mode & SILC_UMODE_DETACHED) client->data.status &= ~SILC_IDLIST_STATUS_RESUMED; + /* Update statistics */ + if (server->server_type == SILC_ROUTER) { + if (mode & SILC_UMODE_GONE) { + if (!client->mode & SILC_UMODE_GONE) + server->stat.aways++; + } else { + if (client->mode & SILC_UMODE_GONE) + server->stat.aways--; + } + if (mode & SILC_UMODE_DETACHED) { + if (!client->mode & SILC_UMODE_DETACHED) + server->stat.detached++; + } else { + if (client->mode & SILC_UMODE_DETACHED) + server->stat.detached--; + } + } + /* Change the mode */ client->mode = mode; @@ -2754,12 +2781,6 @@ void silc_server_new_channel(SilcServer server, } channel->disabled = TRUE; -#if 0 - /* CMODE change notify is expected */ - /* Get the mode and set it to the channel */ - channel->mode = silc_channel_get_mode(payload); -#endif - /* Send the new channel key to the server */ id = silc_id_id2str(channel->id, SILC_ID_CHANNEL); id_len = silc_id_get_len(channel->id, SILC_ID_CHANNEL); @@ -2772,7 +2793,6 @@ void silc_server_new_channel(SilcServer server, silc_server_packet_send(server, sock, SILC_PACKET_CHANNEL_KEY, 0, chk->data, chk->len, FALSE); silc_buffer_free(chk); - } else { /* The channel exist by that name, check whether the ID's match. If they don't then we'll force the server to use the ID we have. @@ -2827,6 +2847,10 @@ void silc_server_new_channel(SilcServer server, silc_free(channel_id); + /* Update statistics */ + server->stat.channels++; + server->stat.cell_channels++; + /* Since the channel is coming from server and we also know about it then send the JOIN notify to the server so that it see's our users on the channel "joining" the channel. */ diff --git a/apps/silcd/packet_send.c b/apps/silcd/packet_send.c index 40d303e6..512ee423 100644 --- a/apps/silcd/packet_send.c +++ b/apps/silcd/packet_send.c @@ -50,8 +50,10 @@ int silc_server_packet_send_real(SilcServer server, /* Send the packet */ ret = silc_packet_send(sock, force_send); - if (ret != -2) + if (ret != -2) { + server->stat.packets_sent++; return ret; + } /* Mark that there is some outgoing data available for this connection. This call sets the connection both for input and output (the input diff --git a/apps/silcd/server.c b/apps/silcd/server.c index bbc25aa1..5cbe0bbc 100644 --- a/apps/silcd/server.c +++ b/apps/silcd/server.c @@ -115,12 +115,10 @@ void silc_server_free(SilcServer server) } } -/* Opens a listening port. - XXX This function will become more general and will support multiple - listening ports */ +/* Creates a new server listener. */ static bool silc_server_listen(SilcServer server, const char *server_ip, - SilcUInt16 port, int *sock) + SilcUInt16 port, int *sock) { *sock = silc_net_create_server(port, server_ip); if (*sock < 0) { @@ -2876,7 +2874,14 @@ void silc_server_remove_from_channels(SilcServer server, channel->global_users = FALSE; silc_free(chl); - server->stat.my_chanclients--; + + /* Update statistics */ + if (client->connection) + server->stat.my_chanclients--; + if (server->server_type == SILC_ROUTER) { + server->stat.cell_chanclients--; + server->stat.chanclients--; + } /* If there is not at least one local user on the channel then we don't need the channel entry anymore, we can remove it safely, unless the @@ -2966,7 +2971,14 @@ bool silc_server_remove_from_one_channel(SilcServer server, channel->global_users = FALSE; silc_free(chl); - server->stat.my_chanclients--; + + /* Update statistics */ + if (client->connection) + server->stat.my_chanclients--; + if (server->server_type == SILC_ROUTER) { + server->stat.cell_chanclients--; + server->stat.chanclients--; + } clidp = silc_id_payload_encode(client->id, SILC_ID_CLIENT); if (!clidp) @@ -3131,9 +3143,11 @@ SilcChannelEntry silc_server_create_new_channel(SilcServer server, } server->stat.my_channels++; - - if (server->server_type == SILC_ROUTER) + if (server->server_type == SILC_ROUTER) { + server->stat.channels++; + server->stat.cell_channels++; entry->users_resolved = TRUE; + } return entry; } @@ -3214,9 +3228,11 @@ silc_server_create_new_channel_with_id(SilcServer server, } server->stat.my_channels++; - - if (server->server_type == SILC_ROUTER) + if (server->server_type == SILC_ROUTER) { + server->stat.channels++; + server->stat.cell_channels++; entry->users_resolved = TRUE; + } return entry; } diff --git a/apps/silcd/server_internal.h b/apps/silcd/server_internal.h index 7e773c86..c435c776 100644 --- a/apps/silcd/server_internal.h +++ b/apps/silcd/server_internal.h @@ -29,8 +29,9 @@ typedef struct { SilcUInt32 my_servers; /* Locally connected servers */ SilcUInt32 my_routers; /* Locally connected routers */ SilcUInt32 my_channels; /* Locally created channels */ - SilcUInt32 my_chanclients; /* Local clients on local channels */ - SilcUInt32 my_aways; /* Local clients away (XXX) */ + SilcUInt32 my_chanclients; /* Local clients on local channels */ + SilcUInt32 my_aways; /* Local clients away (gone) */ + SilcUInt32 my_detached; /* Local clients detached */ SilcUInt32 my_server_ops; /* Local server operators */ SilcUInt32 my_router_ops; /* Local router operators */ @@ -38,12 +39,14 @@ typedef struct { SilcUInt32 cell_clients; /* All clients in cell */ SilcUInt32 cell_servers; /* All servers in cell */ SilcUInt32 cell_channels; /* All channels in cell */ - SilcUInt32 cell_chanclients; /* All clients on cell's channels */ - SilcUInt32 clients; /* All clients */ - SilcUInt32 servers; /* All servers */ - SilcUInt32 routers; /* All routers */ - SilcUInt32 channels; /* All channels */ + SilcUInt32 cell_chanclients; /* All clients on cell's channels */ + SilcUInt32 clients; /* All clients */ + SilcUInt32 servers; /* All servers */ + SilcUInt32 routers; /* All routers */ + SilcUInt32 channels; /* All channels */ SilcUInt32 chanclients; /* All clients on channels */ + SilcUInt32 aways; /* All clients away (gone) */ + SilcUInt32 detached; /* All clients detached */ SilcUInt32 server_ops; /* All server operators */ SilcUInt32 router_ops; /* All router operators */ @@ -53,7 +56,7 @@ typedef struct { SilcUInt32 auth_attempts; /* Authentication attempts */ SilcUInt32 auth_failures; /* Authentication failures */ SilcUInt32 packets_sent; /* Sent packets */ - SilcUInt32 packets_received; /* Received packets */ + SilcUInt32 packets_received; /* Received packets */ } SilcServerStatistics; /* diff --git a/apps/silcd/server_util.c b/apps/silcd/server_util.c index 2f815d25..e7bff221 100644 --- a/apps/silcd/server_util.c +++ b/apps/silcd/server_util.c @@ -73,7 +73,14 @@ static void silc_server_remove_clients_channels(SilcServer server, channel->global_users = FALSE; silc_free(chl); - server->stat.my_chanclients--; + + /* Update statistics */ + if (client->connection) + server->stat.my_chanclients--; + if (server->server_type == SILC_ROUTER) { + server->stat.cell_chanclients--; + server->stat.chanclients--; + } /* If there is not at least one local user on the channel then we don't need the channel entry anymore, we can remove it safely, unless the @@ -721,13 +728,25 @@ bool silc_server_channel_delete(SilcServer server, if (delchan) { SILC_LOG_DEBUG(("Deleting %s channel", channel->channel_name)); + /* Update statistics */ + if (server->server_type == SILC_ROUTER) + server->stat.chanclients -= channel->user_count; + /* Totally delete the channel and all users on the channel. The users are deleted automatically in silc_idlist_del_channel. */ silc_schedule_task_del_by_context(server->schedule, channel->rekey); - if (silc_idlist_del_channel(server->local_list, channel)) + if (silc_idlist_del_channel(server->local_list, channel)) { server->stat.my_channels--; - else - silc_idlist_del_channel(server->global_list, channel); + if (server->server_type == SILC_ROUTER) { + server->stat.channels--; + server->stat.cell_channels--; + } + } else { + if (silc_idlist_del_channel(server->global_list, channel)) + if (server->server_type == SILC_ROUTER) + server->stat.channels--; + } + return FALSE; } @@ -738,6 +757,15 @@ bool silc_server_channel_delete(SilcServer server, silc_hash_table_del(chl->client->channels, channel); silc_hash_table_del(channel->user_list, chl->client); channel->user_count--; + + /* Update statistics */ + if (chl->client->connection) + server->stat.my_chanclients--; + if (server->server_type == SILC_ROUTER) { + server->stat.cell_chanclients--; + server->stat.chanclients--; + } + silc_free(chl); } silc_hash_table_list_reset(&htl); diff --git a/apps/silcd/serverconfig.c b/apps/silcd/serverconfig.c index 54425dd6..d9fe747a 100644 --- a/apps/silcd/serverconfig.c +++ b/apps/silcd/serverconfig.c @@ -1256,8 +1256,6 @@ SilcServerConfig silc_server_config_alloc(const char *filename) return NULL; } - /* XXX are there any other mandatory sections in the config file? */ - /* Set default to configuration parameters */ silc_server_config_set_defaults(config_new); diff --git a/apps/silcd/silcd.c b/apps/silcd/silcd.c index bb8dc0d4..3386f664 100644 --- a/apps/silcd/silcd.c +++ b/apps/silcd/silcd.c @@ -245,9 +245,8 @@ static void signal_handler(int sig) SILC_TASK_CALLBACK(got_hup) { /* First, reset all log files (they might have been deleted) */ - /* XXX this may be redundant with the silc_server_config_setlogfiles() call. - * merge these two with the appropriate checking. */ silc_log_reset_all(); + /* Rehash the configuration file */ silc_server_rehash(silcd); } @@ -259,6 +258,58 @@ SILC_TASK_CALLBACK(stop_server) silc_schedule_stop(silcd->schedule); } +/* Dump server statistics into a file into /tmp directory */ + +SILC_TASK_CALLBACK(dump_stats) +{ + FILE *fdd; + char filename[256]; + + memset(filename, 0, sizeof(filename)); + snprintf(filename, sizeof(filename) - 1, "/tmp/silcd.%d.stats", getpid()); + fdd = fopen(filename, "w+"); + if (!fdd) + return; + +#define STAT_OUTPUT(fmt, stat) fprintf(fdd, fmt "\n", (int)stat); + + fprintf(fdd, "SILC Server %s Statistics\n\n", silcd->server_name); + fprintf(fdd, "Local Stats:\n"); + STAT_OUTPUT(" My clients : %d", silcd->stat.my_clients); + STAT_OUTPUT(" My servers : %d", silcd->stat.my_servers); + STAT_OUTPUT(" My routers : %d", silcd->stat.my_routers); + STAT_OUTPUT(" My channels : %d", silcd->stat.my_channels); + STAT_OUTPUT(" My joined users : %d", silcd->stat.my_chanclients); + STAT_OUTPUT(" My aways : %d", silcd->stat.my_aways); + STAT_OUTPUT(" My detached clients : %d", silcd->stat.my_detached); + STAT_OUTPUT(" My server operators : %d", silcd->stat.my_server_ops); + STAT_OUTPUT(" My router operators : %d", silcd->stat.my_router_ops); + fprintf(fdd, "\nGlobal Stats:\n"); + STAT_OUTPUT(" Cell clients : %d", silcd->stat.cell_clients); + STAT_OUTPUT(" Cell servers : %d", silcd->stat.cell_servers); + STAT_OUTPUT(" Cell channels : %d", silcd->stat.cell_channels); + STAT_OUTPUT(" Cell joined users : %d", silcd->stat.cell_chanclients); + STAT_OUTPUT(" All clients : %d", silcd->stat.clients); + STAT_OUTPUT(" All servers : %d", silcd->stat.servers); + STAT_OUTPUT(" All routers : %d", silcd->stat.routers); + STAT_OUTPUT(" All channels : %d", silcd->stat.channels); + STAT_OUTPUT(" All joined users : %d", silcd->stat.chanclients); + STAT_OUTPUT(" All aways : %d", silcd->stat.aways); + STAT_OUTPUT(" All detached clients : %d", silcd->stat.detached); + STAT_OUTPUT(" All server operators : %d", silcd->stat.server_ops); + STAT_OUTPUT(" All router operators : %d", silcd->stat.router_ops); + fprintf(fdd, "\nGeneral Stats:\n"); + STAT_OUTPUT(" Connection attempts : %d", silcd->stat.conn_attempts); + STAT_OUTPUT(" Connection failures : %d", silcd->stat.conn_failures); + STAT_OUTPUT(" Authentication attempts : %d", silcd->stat.auth_attempts); + STAT_OUTPUT(" Authentication failures : %d", silcd->stat.auth_failures); + STAT_OUTPUT(" Packets sent : %d", silcd->stat.packets_sent); + STAT_OUTPUT(" Packets received : %d", silcd->stat.packets_received); + + fflush(fdd); + fclose(fdd); +} + /* This function should not be called directly but throught the wrapper macro SILC_SERVER_LOG_STDERR() */ @@ -398,9 +449,11 @@ int main(int argc, char **argv) sigaction(SIGHUP, &sa, NULL); sigaction(SIGTERM, &sa, NULL); sigaction(SIGINT, &sa, NULL); + sigaction(SIGUSR1, &sa, NULL); silc_schedule_signal_register(silcd->schedule, SIGHUP, got_hup, NULL); silc_schedule_signal_register(silcd->schedule, SIGTERM, stop_server, NULL); silc_schedule_signal_register(silcd->schedule, SIGINT, stop_server, NULL); + silc_schedule_signal_register(silcd->schedule, SIGUSR1, dump_stats, NULL); if (!foreground) { /* Before running the server, fork to background. */