From 29c83ae4eb3b694fd656dff6f07ff390e7834d12 Mon Sep 17 00:00:00 2001 From: Karl Heyes Date: Sat, 11 Jun 2005 01:24:58 +0000 Subject: [PATCH] update a few stats svn path=/icecast/trunk/icecast/; revision=9437 --- src/connection.c | 1 + src/source.c | 15 +++++++++++++-- src/source.h | 1 + src/stats.c | 13 +++++++++++++ src/stats.h | 1 + 5 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/connection.c b/src/connection.c index 61375d67..ee3a8653 100644 --- a/src/connection.c +++ b/src/connection.c @@ -487,6 +487,7 @@ int connection_complete_source (source_t *source) } global.sources++; + stats_event_args (NULL, "sources", "%d", global.sources); global_unlock(); /* for relays, we don't yet have a client, however we do require one diff --git a/src/source.c b/src/source.c index 8ebbfb15..71bd6e84 100644 --- a/src/source.c +++ b/src/source.c @@ -546,6 +546,9 @@ static void send_to_listener (source_t *source, client_t *client, int deletion_e } +/* Perform any initialisation just before the stream data is processed, the header + * info is processed by now and the format details are setup + */ static void source_init (source_t *source) { ice_config_t *config = config_get_config(); @@ -577,6 +580,8 @@ static void source_init (source_t *source) free(listenurl); } + stats_event_args (source->mount, "listener_peak", "0"); + if (source->dumpfilename != NULL) { source->dumpfile = fopen (source->dumpfilename, "ab"); @@ -592,9 +597,10 @@ static void source_init (source_t *source) /* start off the statistics */ source->listeners = 0; - stats_event_inc (NULL, "sources"); stats_event_inc (NULL, "source_total_connections"); stats_event (source->mount, "slow_listeners", "0"); + stats_event (source->mount, "listener_peak", "0"); + stats_event_time (source->mount, "stream_start"); if (source->client->con) sock_set_blocking (source->con->sock, SOCK_NONBLOCK); @@ -754,6 +760,11 @@ void source_main (source_t *source) if (source->listeners != listeners) { INFO2("listener count on %s now %lu", source->mount, source->listeners); + if (source->listeners > source->peak_listeners) + { + source->peak_listeners = source->listeners; + stats_event_args (source->mount, "listener_peak", "%lu", source->peak_listeners); + } stats_event_args (source->mount, "listeners", "%lu", source->listeners); if (source->listeners == 0 && source->on_demand) source->running = 0; @@ -820,7 +831,6 @@ static void source_shutdown (source_t *source) } /* delete this sources stats */ - stats_event_dec(NULL, "sources"); stats_event(source->mount, NULL, NULL); /* we don't remove the source from the tree here, it may be a relay and @@ -829,6 +839,7 @@ static void source_shutdown (source_t *source) global_lock(); global.sources--; + stats_event_args (NULL, "sources", "%d", global.sources); global_unlock(); /* release our hold on the lock so the main thread can continue cleaning up */ diff --git a/src/source.h b/src/source.h index f03f84e7..825d2e0e 100644 --- a/src/source.h +++ b/src/source.h @@ -51,6 +51,7 @@ typedef struct source_tag char *dumpfilename; /* Name of a file to dump incoming stream to */ FILE *dumpfile; + unsigned long peak_listeners; unsigned long listeners; long max_listeners; int yp_public; diff --git a/src/stats.c b/src/stats.c index 616204fe..a37afcff 100644 --- a/src/stats.c +++ b/src/stats.c @@ -533,6 +533,18 @@ static void process_source_event (stats_event_t *event) } +void stats_event_time (const char *mount, const char *name) +{ + time_t now = time(NULL); + struct tm local; + char buffer[100]; + + localtime_r (&now, &local); + strftime (buffer, sizeof (buffer), "%a, %d %b %Y %H:%M:%S %z", &local); + stats_event (mount, name, buffer); +} + + static void *_stats_thread(void *arg) { stats_event_t *event; @@ -540,6 +552,7 @@ static void *_stats_thread(void *arg) event_listener_t *listener; stats_event (NULL, "server", ICECAST_VERSION_STRING); + stats_event_time (NULL, "server_start"); /* global currently active stats */ stats_event (NULL, "clients", "0"); diff --git a/src/stats.h b/src/stats.h index e3102bd5..484962e4 100644 --- a/src/stats.h +++ b/src/stats.h @@ -81,6 +81,7 @@ 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_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); void *stats_connection(void *arg); void *stats_callback(void *arg); -- GitLab