diff --git a/src/format.c b/src/format.c index fbe53d92..47f04b90 100644 --- a/src/format.c +++ b/src/format.c @@ -208,6 +208,7 @@ int format_check_http_buffer (source_t *source, client_t *client) client->con->error = 1; return -1; } + stats_event_inc (NULL, "listeners"); stats_event_inc (NULL, "listener_connections"); stats_event_inc (source->mount, "listener_connections"); } diff --git a/src/source.c b/src/source.c index 442ee0ab..a522fa9f 100644 --- a/src/source.c +++ b/src/source.c @@ -212,6 +212,9 @@ void source_clear_source (source_t *source) source->dumpfile = NULL; } + if (source->listeners) + stats_event_sub (NULL, "listeners", source->listeners); + /* lets kick off any clients that are left on here */ while (avl_get_first (source->client_tree)) { @@ -716,6 +719,7 @@ void source_main (source_t *source) client_node = avl_get_next(client_node); avl_delete(source->client_tree, (void *)client, _free_client); source->listeners--; + stats_event_dec (NULL, "listeners"); DEBUG0("Client removed"); continue; } diff --git a/src/stats.c b/src/stats.c index 2d88f734..aff0bc1d 100644 --- a/src/stats.c +++ b/src/stats.c @@ -49,8 +49,9 @@ #define STATS_EVENT_INC 1 #define STATS_EVENT_DEC 2 #define STATS_EVENT_ADD 3 -#define STATS_EVENT_REMOVE 4 -#define STATS_EVENT_HIDDEN 5 +#define STATS_EVENT_SUB 4 +#define STATS_EVENT_REMOVE 5 +#define STATS_EVENT_HIDDEN 6 typedef struct _event_queue_tag { @@ -343,6 +344,18 @@ void stats_event_add(const char *source, const char *name, unsigned long value) } } +void stats_event_sub(const char *source, const char *name, unsigned long value) +{ + stats_event_t *event = build_event (source, name, NULL); + if (event) + { + event->value = malloc (16); + snprintf (event->value, 16, "%ld", value); + event->action = STATS_EVENT_SUB; + queue_global_event (event); + } +} + /* decrease the value in the provided stat by 1 */ void stats_event_dec(const char *source, const char *name) { @@ -609,6 +622,7 @@ static void *_stats_thread(void *arg) stats_event (NULL, "connections", "0"); stats_event (NULL, "sources", "0"); stats_event (NULL, "stats", "0"); + stats_event (NULL, "listeners", "0"); /* global accumulating stats */ stats_event (NULL, "client_connections", "0"); diff --git a/src/stats.h b/src/stats.h index 6df316af..ab699864 100644 --- a/src/stats.h +++ b/src/stats.h @@ -85,6 +85,7 @@ void stats_event_conv(const char *mount, const char *name, void stats_event_args(const char *source, char *name, char *format, ...); void stats_event_inc(const char *source, const char *name); void stats_event_add(const char *source, const char *name, unsigned long value); +void stats_event_sub(const char *source, const char *name, unsigned long value); void stats_event_dec(const char *source, const char *name); void stats_event_hidden (const char *source, const char *name, int hidden); void stats_event_time (const char *mount, const char *name);