Made the network statistics work again.
This commit is contained in:
parent
8086d89e23
commit
e4fc91dde1
@ -600,6 +600,31 @@ static void hub_event_dispatcher(void* callback_data, struct event_data* message
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void hub_update_stats(struct hub_info* hub)
|
||||||
|
{
|
||||||
|
const int factor = TIMEOUT_STATS;
|
||||||
|
struct net_statistics* total;
|
||||||
|
struct net_statistics* intermediate;
|
||||||
|
net_stats_get(&intermediate, &total);
|
||||||
|
|
||||||
|
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_rx_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();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void hub_timer_statistics(struct timeout_evt* t)
|
||||||
|
{
|
||||||
|
struct hub_info* hub = (struct hub_info*) t->ptr;
|
||||||
|
hub_update_stats(hub);
|
||||||
|
timeout_queue_reschedule(net_backend_get_timeout_queue(), hub->stats.timeout, TIMEOUT_STATS);
|
||||||
|
}
|
||||||
|
|
||||||
static struct net_connection* start_listening_socket(const char* bind_addr, uint16_t port, int backlog, struct hub_info* hub)
|
static struct net_connection* start_listening_socket(const char* bind_addr, uint16_t port, int backlog, struct hub_info* hub)
|
||||||
{
|
{
|
||||||
struct net_connection* server;
|
struct net_connection* server;
|
||||||
@ -816,6 +841,13 @@ struct hub_info* hub_start_service(struct hub_config* config)
|
|||||||
|
|
||||||
g_hub = hub;
|
g_hub = hub;
|
||||||
|
|
||||||
|
if (net_backend_get_timeout_queue())
|
||||||
|
{
|
||||||
|
hub->stats.timeout = hub_malloc_zero(sizeof(struct timeout_evt));
|
||||||
|
timeout_evt_initialize(hub->stats.timeout, hub_timer_statistics, hub);
|
||||||
|
timeout_queue_insert(net_backend_get_timeout_queue(), hub->stats.timeout, TIMEOUT_STATS);
|
||||||
|
}
|
||||||
|
|
||||||
// Start the hub command sub-system
|
// Start the hub command sub-system
|
||||||
hub->commands = command_initialize(hub);
|
hub->commands = command_initialize(hub);
|
||||||
return hub;
|
return hub;
|
||||||
@ -826,6 +858,12 @@ void hub_shutdown_service(struct hub_info* hub)
|
|||||||
{
|
{
|
||||||
LOG_DEBUG("hub_shutdown_service()");
|
LOG_DEBUG("hub_shutdown_service()");
|
||||||
|
|
||||||
|
if (net_backend_get_timeout_queue())
|
||||||
|
{
|
||||||
|
timeout_queue_remove(net_backend_get_timeout_queue(), hub->stats.timeout);
|
||||||
|
hub_free(hub->stats.timeout);
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef SSL_SUPPORT
|
#ifdef SSL_SUPPORT
|
||||||
unload_ssl_certificates(hub);
|
unload_ssl_certificates(hub);
|
||||||
#endif
|
#endif
|
||||||
|
@ -81,6 +81,7 @@ struct hub_stats
|
|||||||
size_t net_rx_peak;
|
size_t net_rx_peak;
|
||||||
size_t net_tx_total;
|
size_t net_tx_total;
|
||||||
size_t net_rx_total;
|
size_t net_rx_total;
|
||||||
|
struct timeout_evt* timeout; /**<< "Timeout handler for statistics" */
|
||||||
};
|
};
|
||||||
|
|
||||||
struct hub_logout_info
|
struct hub_logout_info
|
||||||
|
@ -38,42 +38,6 @@ static void clear_user_list_callback(void* ptr)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef STATS_SUPPORT
|
|
||||||
void uman_update_stats(struct hub_user_manager* users)
|
|
||||||
{
|
|
||||||
const int factor = TIMEOUT_STATS;
|
|
||||||
struct net_statistics* total;
|
|
||||||
struct net_statistics* intermediate;
|
|
||||||
net_stats_get(&intermediate, &total);
|
|
||||||
|
|
||||||
users->stats.net_tx = (intermediate->tx / factor);
|
|
||||||
users->stats.net_rx = (intermediate->rx / factor);
|
|
||||||
users->stats.net_tx_peak = MAX(users->stats.net_tx, users->stats.net_tx_peak);
|
|
||||||
users->stats.net_rx_peak = MAX(users->stats.net_rx, users->stats.net_rx_peak);
|
|
||||||
users->stats.net_tx_total = total->tx;
|
|
||||||
users->stats.net_rx_total = total->rx;
|
|
||||||
|
|
||||||
net_stats_reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
void uman_print_stats(struct hub_user_manager* users)
|
|
||||||
{
|
|
||||||
LOG_INFO("Statistics users=" PRINTF_SIZE_T " (peak_users=" PRINTF_SIZE_T "), net_tx=%d KB/s, net_rx=%d KB/s (peak_tx=%d KB/s, peak_rx=%d KB/s)",
|
|
||||||
users->users->count,
|
|
||||||
users->users->count_peak,
|
|
||||||
(int) users->stats.net_tx / 1024,
|
|
||||||
(int) users->stats.net_rx / 1024,
|
|
||||||
(int) users->stats.net_tx_peak / 1024,
|
|
||||||
(int) users->stats.net_rx_peak / 1024);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void timer_statistics(struct timeout_evt* t)
|
|
||||||
{
|
|
||||||
struct hub_user_manager* users = (struct hub_user_manager*) t->ptr;
|
|
||||||
uman_update_stats(users);
|
|
||||||
timeout_queue_reschedule(net_backend_get_timeout_queue(), users->timeout, TIMEOUT_STATS);
|
|
||||||
}
|
|
||||||
#endif // STATS_SUPPORT
|
|
||||||
|
|
||||||
struct hub_user_manager* uman_init()
|
struct hub_user_manager* uman_init()
|
||||||
{
|
{
|
||||||
@ -91,15 +55,6 @@ struct hub_user_manager* uman_init()
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef STATS_SUPPORT
|
|
||||||
if (net_backend_get_timeout_queue())
|
|
||||||
{
|
|
||||||
users->timeout = hub_malloc_zero(sizeof(struct timeout_evt));
|
|
||||||
timeout_evt_initialize(users->timeout, timer_statistics, hub);
|
|
||||||
timeout_queue_insert(net_backend_get_timeout_queue(), users->timeout, TIMEOUT_STATS);
|
|
||||||
}
|
|
||||||
#endif // STATS_SUPPORT
|
|
||||||
|
|
||||||
return users;
|
return users;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -109,14 +64,6 @@ int uman_shutdown(struct hub_user_manager* users)
|
|||||||
if (!users)
|
if (!users)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
#ifdef STATS_SUPPORT
|
|
||||||
if (net_backend_get_timeout_queue())
|
|
||||||
{
|
|
||||||
timeout_queue_remove(net_backend_get_timeout_queue(), users->timeout);
|
|
||||||
hub_free(users->timeout);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (users->list)
|
if (users->list)
|
||||||
{
|
{
|
||||||
list_clear(users->list, &clear_user_list_callback);
|
list_clear(users->list, &clear_user_list_callback);
|
||||||
|
@ -28,9 +28,6 @@ struct hub_user_manager
|
|||||||
uint64_t shared_size; /**<< "The total number of shared bytes among fully connected users." */
|
uint64_t shared_size; /**<< "The total number of shared bytes among fully connected users." */
|
||||||
uint64_t shared_files; /**<< "The total number of shared files among fully connected users." */
|
uint64_t shared_files; /**<< "The total number of shared files among fully connected users." */
|
||||||
struct linked_list* list; /**<< "Contains all logged in users" */
|
struct linked_list* list; /**<< "Contains all logged in users" */
|
||||||
#ifdef STATS_SUPPORT
|
|
||||||
struct timeout_evt* timeout; /**<< "Timeout handler for statistics" */
|
|
||||||
#endif
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user