Better "!stats"; can display peak and current bandwidth usage.

Network stats are now updated every minute, so that we have them handy for
printing in logs, or by issuing the !stats command.

Note: this checkin disables the once-per-hour stats logging.
I do not know wether or not that is useful functionality.
This commit is contained in:
Jan Vidar Krey 2009-03-04 18:36:45 +01:00
parent 8eb1726abb
commit d4c8b657bf
8 changed files with 52 additions and 32 deletions

View File

@ -1,5 +1,6 @@
0.2.6:
- Better uptime command formatting.
- Better "!uptime" command formatting.
- Better "!stats"; can display peak and current bandwidth usage.
0.2.5-3487:

View File

@ -38,9 +38,17 @@ static int command_stats(struct user* user, const char* message)
if (user->credentials < cred_super)
return command_access_denied(user);
char temp[64];
snprintf(temp, 64, "*** Stats: %u users, peak %u", (unsigned int) user->hub->users->count, (unsigned int) user->hub->users->count_peak);
char temp[128];
snprintf(temp, 128, "*** Stats: %zu users, peak: %zu. Network (up/down): %d/%d KB/s, peak: %d/%d KB/s",
user->hub->users->count,
user->hub->users->count_peak,
(int) user->hub->stats.net_tx / 1024,
(int) user->hub->stats.net_rx / 1024,
(int) user->hub->stats.net_tx_peak / 1024,
(int) user->hub->stats.net_rx_peak / 1024);
char* buffer = adc_msg_escape(temp);
command = adc_msg_construct(ADC_CMD_IMSG, strlen(buffer) + 6);
adc_msg_add_argument(command, buffer);

View File

@ -66,6 +66,19 @@ enum hub_state
hub_status_disabled = 5, /**<<<"Hub is disabled (Running, but not accepting users) */
};
/**
* Always updated each minute.
*/
struct hub_stats
{
size_t net_tx;
size_t net_rx;
size_t net_tx_peak;
size_t net_rx_peak;
size_t net_tx_total;
size_t net_rx_total;
};
struct hub_info
{
int fd_tcp;
@ -77,6 +90,7 @@ struct hub_info
#ifdef ADC_UDP_OPERATION
struct event ev_datagram;
#endif
struct hub_stats stats;
struct event_queue* queue;
struct hub_config* config;
struct user_manager* users;

View File

@ -70,7 +70,7 @@ void hub_handle_signal(int fd, short events, void* arg)
case SIGUSR2:
hub_log(log_trace, "hub_handle_signal(): caught SIGUSR2");
{
user_manager_stats(hub);
user_manager_print_stats(hub);
}
break;

View File

@ -591,19 +591,6 @@ void net_stats_get(struct net_statistics** intermediate, struct net_statistics**
}
void net_stats_report()
{
int factor = (time(NULL) - stats.timestamp);
if (!factor) factor++;
hub_log(log_info, "Statistics NET: tx=%d KB/s, rx=%d KB/s, (acc=%d/cls=%d/err=%d)",
(int) ((stats.tx / factor) / 1024),
(int) ((stats.rx / factor) / 1024),
(int) stats.accept,
(int) stats.closed,
(int) stats.errors);
}
void net_stats_reset()
{
stats_total.tx += stats.tx;
@ -619,8 +606,7 @@ void net_stats_reset()
int net_stats_timeout()
{
/* FIXME: Configurable time for dumping network statistics */
return (time(NULL) - stats.timestamp > 60) ? 1 : 0;
return (difftime(time(NULL), stats.timestamp) > TIMEOUT_STATS) ? 1 : 0;
}

View File

@ -113,7 +113,7 @@
#define TIMEOUT_HANDSHAKE 30
#define TIMEOUT_SENDQ 120
#define TIMEOUT_IDLE 7200
#define TIMEOUT_STATS 3600
#define TIMEOUT_STATS 60
#define MAX_CLIENTS 512
#define MAX_CID_LEN 39

View File

@ -39,30 +39,40 @@ static void clear_user_list_callback(void* ptr)
}
void user_manager_stats(struct hub_info* hub)
void user_manager_update_stats(struct hub_info* hub)
{
int factor = 0;
const int factor = TIMEOUT_STATS;
struct net_statistics* total;
struct net_statistics* intermediate;
net_stats_get(&intermediate, &total);
factor = (time(NULL) - intermediate->timestamp);
if (!factor) factor++;
hub_log(log_info, "Statistics users=%zu, net_tx=%d KB/s, net_rx=%d KB/s",
hub->users->count,
(int) ((intermediate->tx / factor) / 1024),
(int) ((intermediate->rx / factor) / 1024));
hub->stats.net_tx = (intermediate->tx / factor);
hub->stats.net_rx = (intermediate->rx / factor);
hub->stats.net_tx_peak = MAX(hub->stats.net_tx, hub->stats.net_tx_peak);
hub->stats.net_tx_peak = MAX(hub->stats.net_rx, hub->stats.net_rx_peak);
hub->stats.net_tx_total = total->tx;
hub->stats.net_rx_total = total->rx;
net_stats_reset();
}
void user_manager_print_stats(struct hub_info* hub)
{
hub_log(log_info, "Statistics users=%zu (peak_users=%zu), net_tx=%d KB/s, net_rx=%d KB/s (peak_tx=%d KB/s, peak_rx=%d KB/s)",
hub->users->count,
hub->users->count_peak,
(int) hub->stats.net_tx / 1024,
(int) hub->stats.net_rx / 1024,
(int) hub->stats.net_tx_peak / 1024,
(int) hub->stats.net_rx_peak / 1024);
}
static void timer_statistics(int fd, short ev, void *arg)
{
struct hub_info* hub = (struct hub_info*) arg;
struct timeval timeout = { TIMEOUT_STATS, 0 };
user_manager_stats(hub);
user_manager_update_stats(hub);
evtimer_set(&hub->ev_timer, timer_statistics, hub);
evtimer_add(&hub->ev_timer, &timeout);
}

View File

@ -45,7 +45,8 @@ extern void user_manager_shutdown(struct hub_info* hub);
/**
* Generate statistics for logfiles.
*/
extern void user_manager_stats(struct hub_info* hub);
extern void user_manager_update_stats(struct hub_info* hub);
extern void user_manager_print_stats(struct hub_info* hub);
/**
* Add a new user to the user manager.