From ec5a543f0f9803c94433bf79cfe1ad6a54eb5b78 Mon Sep 17 00:00:00 2001 From: Frederic-Philippe Metz Date: Wed, 18 Feb 2015 07:36:25 +0100 Subject: [PATCH] Added prefix config parameter to graphite acc. to OPS --- README.md | 5 +++++ daemon/graphite.c | 17 +++++++++++++++++ daemon/graphite.h | 1 + daemon/main.c | 19 ++++++++++++------- debian/ngcp-rtpengine-daemon.default | 3 ++- debian/ngcp-rtpengine-daemon.init | 1 + el/rtpengine.init | 5 +++++ 7 files changed, 43 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 9727cef63..b878745d7 100644 --- a/README.md +++ b/README.md @@ -186,6 +186,7 @@ option and which are reproduced below: --dtls-passive Always prefer DTLS passive role -g, --graphite=[IP46:]PORT TCP address of graphite statistics server -w, --graphite-interval=INT Graphite data statistics send interval + --graphite-prefix=STRING Graphite prefix for every line Most of these options are indeed optional, with two exceptions. It's mandatory to specify at least one local IP address through `--interface`, and at least one of the `--listen-...` options must be given. @@ -364,6 +365,10 @@ The options are described in more detail below. Interval of the time when information is sent to the graphite server. +* --graphite-prefix + + Add a prefix for every graphite line. + A typical command line (enabling both UDP and NG protocols) thus may look like: /usr/sbin/rtpengine --table=0 --interface=10.64.73.31 --interface=2001:db8::4f3:3d \ diff --git a/daemon/graphite.c b/daemon/graphite.c index f886584af..8a3ebd088 100644 --- a/daemon/graphite.c +++ b/daemon/graphite.c @@ -12,6 +12,7 @@ #include "log.h" #include "call.h" +#include "graphite.h" static int graphite_sock=-1; static u_int32_t graphite_ipaddress; @@ -19,6 +20,11 @@ static int graphite_port=0; static struct callmaster* cm=0; //struct totalstats totalstats_prev; static time_t g_now, next_run; +static char* graphite_prefix = NULL; + +void set_prefix(char* prefix) { + graphite_prefix = prefix; +} int connect_to_graphite_server(u_int32_t ipaddress, int port) { @@ -89,16 +95,27 @@ int send_graphite_data() { mutex_lock(&cm->totalstats_lock); + if (graphite_prefix!=NULL) { rc = sprintf(ptr,"%s.",graphite_prefix); ptr += rc; } rc = sprintf(ptr,"%s.totals.average_call_dur.tv_sec %llu %llu\n",hostname, (unsigned long long) cm->totalstats_interval.total_average_call_dur.tv_sec,(unsigned long long)g_now); ptr += rc; + if (graphite_prefix!=NULL) { rc = sprintf(ptr,"%s.",graphite_prefix); ptr += rc; } rc = sprintf(ptr,"%s.totals.average_call_dur.tv_usec %llu %llu\n",hostname, (unsigned long long) cm->totalstats_interval.total_average_call_dur.tv_usec,(unsigned long long)g_now); ptr += rc; + if (graphite_prefix!=NULL) { rc = sprintf(ptr,"%s.",graphite_prefix); ptr += rc; } rc = sprintf(ptr,"%s.totals.forced_term_sess %llu %llu\n",hostname, (unsigned long long) cm->totalstats_interval.total_forced_term_sess,(unsigned long long)g_now); ptr += rc; + if (graphite_prefix!=NULL) { rc = sprintf(ptr,"%s.",graphite_prefix); ptr += rc; } rc = sprintf(ptr,"%s.totals.managed_sess %llu %llu\n",hostname, (unsigned long long) cm->totalstats_interval.total_managed_sess,(unsigned long long)g_now); ptr += rc; + if (graphite_prefix!=NULL) { rc = sprintf(ptr,"%s.",graphite_prefix); ptr += rc; } rc = sprintf(ptr,"%s.totals.nopacket_relayed_sess %llu %llu\n",hostname, (unsigned long long) cm->totalstats_interval.total_nopacket_relayed_sess,(unsigned long long)g_now); ptr += rc; + if (graphite_prefix!=NULL) { rc = sprintf(ptr,"%s.",graphite_prefix); ptr += rc; } rc = sprintf(ptr,"%s.totals.oneway_stream_sess %llu %llu\n",hostname, (unsigned long long) cm->totalstats_interval.total_oneway_stream_sess,(unsigned long long)g_now); ptr += rc; + if (graphite_prefix!=NULL) { rc = sprintf(ptr,"%s.",graphite_prefix); ptr += rc; } rc = sprintf(ptr,"%s.totals.regular_term_sess %llu %llu\n",hostname, (unsigned long long) cm->totalstats_interval.total_regular_term_sess,(unsigned long long)g_now); ptr += rc; + if (graphite_prefix!=NULL) { rc = sprintf(ptr,"%s.",graphite_prefix); ptr += rc; } rc = sprintf(ptr,"%s.totals.relayed_errors %llu %llu\n",hostname, (unsigned long long) cm->totalstats_interval.total_relayed_errors,(unsigned long long)g_now); ptr += rc; + if (graphite_prefix!=NULL) { rc = sprintf(ptr,"%s.",graphite_prefix); ptr += rc; } rc = sprintf(ptr,"%s.totals.relayed_packets %llu %llu\n",hostname, (unsigned long long) cm->totalstats_interval.total_relayed_packets,(unsigned long long)g_now); ptr += rc; + if (graphite_prefix!=NULL) { rc = sprintf(ptr,"%s.",graphite_prefix); ptr += rc; } rc = sprintf(ptr,"%s.totals.silent_timeout_sess %llu %llu\n",hostname, (unsigned long long) cm->totalstats_interval.total_silent_timeout_sess,(unsigned long long)g_now); ptr += rc; + if (graphite_prefix!=NULL) { rc = sprintf(ptr,"%s.",graphite_prefix); ptr += rc; } rc = sprintf(ptr,"%s.totals.timeout_sess %llu %llu\n",hostname, (unsigned long long) cm->totalstats_interval.total_timeout_sess,(unsigned long long)g_now); ptr += rc; ZERO(cm->totalstats_interval); diff --git a/daemon/graphite.h b/daemon/graphite.h index 0b51e7b9a..a1a89267f 100644 --- a/daemon/graphite.h +++ b/daemon/graphite.h @@ -13,5 +13,6 @@ int connect_to_graphite_server(u_int32_t ipaddress, int port); int send_graphite_data(); void graphite_loop_run(struct callmaster* cm, int seconds); +void set_prefix(char* prefix); #endif /* GRAPHITE_H_ */ diff --git a/daemon/main.c b/daemon/main.c index 50da00044..4f0c29aa7 100644 --- a/daemon/main.c +++ b/daemon/main.c @@ -257,9 +257,10 @@ static void options(int *argc, char ***argv) { char *listenngs = NULL; char *listencli = NULL; char *graphitep = NULL; + char *graphite_prefix_s = NULL; char *redisps = NULL; char *log_facility_s = NULL; - char *log_facility_cdr_s = NULL; + char *log_facility_cdr_s = NULL; int version = 0; int sip_source = 0; @@ -274,6 +275,7 @@ static void options(int *argc, char ***argv) { { "listen-cli", 'c', 0, G_OPTION_ARG_STRING, &listencli, "UDP port to listen on, CLI", "[IP46:]PORT" }, { "graphite", 'g', 0, G_OPTION_ARG_STRING, &graphitep, "Address of the graphite server", "[IP46:]PORT" }, { "graphite-interval", 'w', 0, G_OPTION_ARG_INT, &graphite_interval, "Graphite send interval in seconds", "INT" }, + { "graphite-prefix",0, 0, G_OPTION_ARG_STRING, &graphite_prefix_s, "Prefix for graphite line", "STRING"}, { "tos", 'T', 0, G_OPTION_ARG_INT, &tos, "Default TOS value to set on streams", "INT" }, { "timeout", 'o', 0, G_OPTION_ARG_INT, &timeout, "RTP timeout", "SECS" }, { "silent-timeout",'s',0,G_OPTION_ARG_INT, &silent_timeout,"RTP timeout for muted", "SECS" }, @@ -340,6 +342,9 @@ static void options(int *argc, char ***argv) { die("Invalid IP or port (--graphite)"); } + if (graphite_prefix_s) + set_prefix(graphite_prefix_s); + if (tos < 0 || tos > 255) die("Invalid TOS value"); @@ -369,12 +374,12 @@ static void options(int *argc, char ***argv) { } } - if (log_facility_cdr_s) { - if (!parse_log_facility(log_facility_cdr_s, &_log_facility_cdr)) { - print_available_log_facilities(); - die ("Invalid log facility for CDR '%s' (--log-facility-cdr)\n", log_facility_cdr_s); - } - } + if (log_facility_cdr_s) { + if (!parse_log_facility(log_facility_cdr_s, &_log_facility_cdr)) { + print_available_log_facilities(); + die ("Invalid log facility for CDR '%s' (--log-facility-cdr)\n", log_facility_cdr_s); + } + } if (_log_stderr) { write_log = log_to_stderr; diff --git a/debian/ngcp-rtpengine-daemon.default b/debian/ngcp-rtpengine-daemon.default index 20b10c3d5..3f259c0c6 100644 --- a/debian/ngcp-rtpengine-daemon.default +++ b/debian/ngcp-rtpengine-daemon.default @@ -24,4 +24,5 @@ TABLE=0 # NUM_THREADS=5 # DELETE_DELAY=30 # GRAPHITE=9006 -# GRAPHITE_INTERVAL=60 \ No newline at end of file +# GRAPHITE_INTERVAL=60 +# GRAPHITE_PREFIX=myownprefix diff --git a/debian/ngcp-rtpengine-daemon.init b/debian/ngcp-rtpengine-daemon.init index 1c7e96f5c..64ce42902 100755 --- a/debian/ngcp-rtpengine-daemon.init +++ b/debian/ngcp-rtpengine-daemon.init @@ -74,6 +74,7 @@ OPTIONS="$OPTIONS --table=$TABLE" [ -z "$DELETE_DELAY" ] || OPTIONS="$OPTIONS --delete-delay=$DELETE_DELAY" [ -z "$GRAPHITE" ] || OPTIONS="$OPTIONS --graphite=$GRAPHITE" [ -z "$GRAPHITE_INTERVAL" ] || OPTIONS="$OPTIONS --graphite-interval=$GRAPHITE_INTERVAL" +[ -z "$GRAPHITE_PREFIX" ] || OPTIONS="$OPTIONS --graphite-prefix=$GRAPHITE_PREFIX" if test "$FORK" = "no" ; then OPTIONS="$OPTIONS --foreground" fi diff --git a/el/rtpengine.init b/el/rtpengine.init index 1fb33ce62..48b2c215c 100644 --- a/el/rtpengine.init +++ b/el/rtpengine.init @@ -153,6 +153,11 @@ build_opts() { OPTS+=" --graphite-interval=$GRAPHITE_INTERVAL" fi + if [[ -n "$GRAPHITE_PREFIX" ]] + then + OPTS+=" --graphite-prefix=$GRAPHITE_PREFIX" + fi + if [[ -n "$LOG_FACILITY_CDR" ]] then OPTS+=" --log-facility-cdr=$LOG_FACILITY_CDR"