From 86967b93f3c08c407fdda56583ae52691688dd51 Mon Sep 17 00:00:00 2001 From: "Bradley T. Hughes" Date: Mon, 20 Nov 2017 13:54:43 +0100 Subject: [PATCH] Report total traffic used per allocation via Redis Publish total traffic information when an allocation is deleted. This makes it easier for applications to monitor total usage per session. --- src/apps/relay/ns_ioalib_engine_impl.c | 8 ++++++++ turndb/schema.stats.redis | 6 ++++++ 2 files changed, 14 insertions(+) diff --git a/src/apps/relay/ns_ioalib_engine_impl.c b/src/apps/relay/ns_ioalib_engine_impl.c index 6db5352..825f473 100644 --- a/src/apps/relay/ns_ioalib_engine_impl.c +++ b/src/apps/relay/ns_ioalib_engine_impl.c @@ -3596,6 +3596,14 @@ void turn_report_allocation_delete(void *a) } send_message_to_redis(e->rch, "del", key, ""); send_message_to_redis(e->rch, "publish", key, "deleted"); + + // report total traffic usage for this allocation + if(ss->realm_options.name[0]) { + snprintf(key, sizeof(key), "turn/realm/%s/user/%s/allocation/%018llu/total_traffic", ss->realm_options.name, (char*)ss->username, (unsigned long long)ss->id); + } else { + snprintf(key, sizeof(key), "turn/user/%s/allocation/%018llu/total_traffic", (char*)ss->username, (unsigned long long)ss->id); + } + send_message_to_redis(e->rch, "publish", key, "rcvp=%lu, rcvb=%lu, sentp=%lu, sentb=%lu", (unsigned long)(ss->t_received_packets), (unsigned long)(ss->t_received_bytes), (unsigned long)(ss->t_sent_packets), (unsigned long)(ss->t_sent_bytes)); } #endif } diff --git a/turndb/schema.stats.redis b/turndb/schema.stats.redis index c35fd0e..428074c 100644 --- a/turndb/schema.stats.redis +++ b/turndb/schema.stats.redis @@ -16,6 +16,12 @@ The keys are "turn/user//allocation//traffic". The application tha in the traffic information must subscribe to the events as: psubscribe turn/realm/*/user/*/allocation/*/traffic + +Total traffic information is also reported when the allocation is deleted. The keys are +"turn/user//allocation//total_traffic". Applications interested in the total amount +of traffic per allocation can subscribe to these events as: + + psubscribe turn/realm/*/user/*/allocation/*/total_traffic Or, to receive all allocation events: