diff --git a/daemon/call.c b/daemon/call.c index d104c2ecf..e876e316a 100644 --- a/daemon/call.c +++ b/daemon/call.c @@ -528,7 +528,7 @@ static void update_requests_per_second_stats(struct requests_ps *request, uint64 mutex_unlock(&request->lock); } -static void call_timer(void *ptr) { +void call_timer(void *ptr) { struct iterator_helper hlp; GList *i, *l; struct rtpengine_list_entry *ke; diff --git a/daemon/control_ng.c b/daemon/control_ng.c index e1772ac00..c21c252da 100644 --- a/daemon/control_ng.c +++ b/daemon/control_ng.c @@ -50,7 +50,7 @@ const char *ng_command_strings_short[NGC_COUNT] = { "Pub", "SubReq", "SubAns", "Unsub", }; -static void timeval_update_request_time(struct request_time *request, const struct timeval *offer_diff) { +void timeval_update_request_time(struct request_time *request, const struct timeval *offer_diff) { // lock offers mutex_lock(&request->lock); diff --git a/daemon/graphite.c b/daemon/graphite.c index a68406387..5a9188601 100644 --- a/daemon/graphite.c +++ b/daemon/graphite.c @@ -101,13 +101,7 @@ static int connect_to_graphite_server(const endpoint_t *graphite_ep) { return 0; } -static int send_graphite_data(struct totalstats *sent_data) { - - if (graphite_sock.fd < 0) { - ilog(LOG_ERROR,"Graphite socket is not connected."); - return -1; - } - +GString *print_graphite_data(struct totalstats *sent_data) { struct totalstats *ts = sent_data; /* atomically copy values to stack and reset to zero */ @@ -280,6 +274,18 @@ static int send_graphite_data(struct totalstats *sent_data) { (unsigned long long)ts->delete.time_max.tv_sec,(unsigned long long)ts->delete.time_max.tv_usec, (unsigned long long)ts->delete.time_avg.tv_sec,(unsigned long long)ts->delete.time_avg.tv_usec); + return graph_str; +} + +static int send_graphite_data(struct totalstats *sent_data) { + + if (graphite_sock.fd < 0) { + ilog(LOG_ERROR,"Graphite socket is not connected."); + return -1; + } + + GString *graph_str = print_graphite_data(sent_data); + size_t sent = 0; int blockings = 10; // let it block that many times while (sent < graph_str->len) { diff --git a/include/call.h b/include/call.h index 5a28b81ca..eb3790fe9 100644 --- a/include/call.h +++ b/include/call.h @@ -595,6 +595,7 @@ int call_stream_address46(char *o, struct packet_stream *ps, enum stream_address int *len, const struct local_intf *ifa, int keep_unspec); void add_total_calls_duration_in_interval(struct timeval *interval_tv); +void call_timer(void *ptr); void __rtp_stats_update(GHashTable *dst, struct codec_store *); int __init_stream(struct packet_stream *ps); diff --git a/include/control_ng.h b/include/control_ng.h index de3c1ed63..79743202e 100644 --- a/include/control_ng.h +++ b/include/control_ng.h @@ -75,6 +75,7 @@ void control_ng_init(void); void control_ng_cleanup(void); int control_ng_process(str *buf, const endpoint_t *sin, char *addr, void (*cb)(str *, str *, const endpoint_t *, void *), void *p1, struct obj *); +void timeval_update_request_time(struct request_time *request, const struct timeval *offer_diff); INLINE void ng_buffer_release(struct ng_buffer *ngbuf) { mutex_unlock(&ngbuf->lock); diff --git a/include/graphite.h b/include/graphite.h index 4620c1872..00a7e7153 100644 --- a/include/graphite.h +++ b/include/graphite.h @@ -23,4 +23,7 @@ void free_prefix(void); void graphite_loop(void *d); void set_latest_graphite_interval_start(struct timeval *tv); void set_graphite_interval_tv(struct timeval *tv); + +GString *print_graphite_data(struct totalstats *sent_data); + #endif /* GRAPHITE_H_ */ diff --git a/t/.gitignore b/t/.gitignore index 3e81fffa3..20217f0d0 100644 --- a/t/.gitignore +++ b/t/.gitignore @@ -71,3 +71,5 @@ mqtt.c cli.c janus.c websocket.c +test-stats +ssllib.c diff --git a/t/Makefile b/t/Makefile index 7a6c9d4ff..778483db9 100644 --- a/t/Makefile +++ b/t/Makefile @@ -61,12 +61,12 @@ LDLIBS+= $(shell mysql_config --libs) endif SRCS= test-bitstr.c aes-crypt.c aead-aes-crypt.c test-const_str_hash.strhash.c -LIBSRCS= loglib.c auxlib.c str.c rtplib.c +LIBSRCS= loglib.c auxlib.c str.c rtplib.c ssllib.c DAEMONSRCS= crypto.c ssrc.c aux.c rtp.c HASHSRCS= ifeq ($(with_transcoding),yes) -SRCS+= test-transcode.c test-dtmf-detect.c test-payload-tracker.c test-resample.c +SRCS+= test-transcode.c test-dtmf-detect.c test-payload-tracker.c test-resample.c test-stats.c SRCS+= spandsp_recv_fax_pcm.c spandsp_recv_fax_t38.c spandsp_send_fax_pcm.c \ spandsp_send_fax_t38.c ifeq ($(with_amr_tests),yes) @@ -82,7 +82,7 @@ endif OBJS= $(SRCS:.c=.o) $(LIBSRCS:.c=.o) $(DAEMONSRCS:.c=.o) $(HASHSRCS:.c=.strhash.o) -COMMONOBJS= str.o auxlib.o rtplib.o loglib.o +COMMONOBJS= str.o auxlib.o rtplib.o loglib.o ssllib.o include ../lib/common.Makefile @@ -91,7 +91,7 @@ include ../lib/common.Makefile TESTS= test-bitstr aes-crypt aead-aes-crypt test-const_str_hash.strhash ifeq ($(with_transcoding),yes) -TESTS+= test-transcode test-dtmf-detect test-payload-tracker test-resample +TESTS+= test-transcode test-dtmf-detect test-payload-tracker test-resample test-stats ifeq ($(with_amr_tests),yes) TESTS+= test-amr-decode test-amr-encode endif @@ -185,6 +185,14 @@ aes-crypt: aes-crypt.o $(COMMONOBJS) crypto.o aead-aes-crypt: aead-aes-crypt.o $(COMMONOBJS) crypto.o +test-stats: test-stats.o $(COMMONOBJS) codeclib.o resample.o codec.o ssrc.o call.o ice.o aux.o \ + kernel.o media_socket.o stun.o bencode.o socket.o poller.o dtls.o recording.o statistics.o \ + rtcp.o redis.o iptables.o graphite.o call_interfaces.strhash.o sdp.strhash.o rtp.o crypto.o \ + control_ng.strhash.o graphite.o \ + streambuf.o cookie_cache.o udp_listener.o homer.o load.o cdr.o dtmf.o timerthread.o \ + media_player.o jitter_buffer.o dtmflib.o t38.o tcp_listener.o mqtt.o janus.strhash.o \ + websocket.o cli.o + test-transcode: test-transcode.o $(COMMONOBJS) codeclib.o resample.o codec.o ssrc.o call.o ice.o aux.o \ kernel.o media_socket.o stun.o bencode.o socket.o poller.o dtls.o recording.o statistics.o \ rtcp.o redis.o iptables.o graphite.o call_interfaces.strhash.o sdp.strhash.o rtp.o crypto.o \ diff --git a/t/test-stats.c b/t/test-stats.c new file mode 100644 index 000000000..293050844 --- /dev/null +++ b/t/test-stats.c @@ -0,0 +1,2200 @@ +#include +#include +#include "graphite.h" +#include "statistics.h" +#include "poller.h" +#include "control_ng.h" +#include "call_interfaces.h" +#include "ssllib.h" + +int _log_facility_rtcp; +int _log_facility_cdr; +int _log_facility_dtmf; +struct rtpengine_config rtpe_config = { + .dtls_rsa_key_size = 2048, +}; +struct rtpengine_config initial_rtpe_config; +struct poller *rtpe_poller; +struct poller_map *rtpe_poller_map; +GString *dtmf_logs; + +static void __assert_g_string_eq(GString *a, const char *b, unsigned int line) { + if (strcmp(a->str, b) == 0) { + g_string_free(a, TRUE); + return; + } + printf("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX test failed at line %u\n", line); + printf("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX received >>>>> <%s>\n", a->str); + printf("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX doesn't match expected <<<<< <%s>\n", b); + + const char *A = a->str; + while (*A == *b) { + A++; + b++; + } + + printf("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX difference in received at: ... <%s>\n", A); + printf("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX difference in expected at: ... <%s>\n", b); + + abort(); +} +#define assert_g_string_eq(a, b) __assert_g_string_eq(a, b, __LINE__) + +static void __assert_metrics_eq(GQueue *q, const char *b, unsigned int line) { + GString *a = g_string_new(""); + for (GList *l = q->head; l; l = l->next) { + struct stats_metric *m = l->data; +#define APP_S(x) if (m->x) do { g_string_append(a, m->x); g_string_append_c(a, '\n'); } while (0) + APP_S(descr); + APP_S(label); + APP_S(value_long); + APP_S(value_short); + APP_S(prom_label); + } + __assert_g_string_eq(a, b, line); + statistics_free_metrics(&q); +} +#define assert_metrics_eq(a, b) __assert_metrics_eq(a, b, __LINE__) + +int main(void) { + rtpe_common_config_ptr = &rtpe_config.common; + + rtpe_ssl_init(); + rtpe_poller = poller_new(); + call_init(); + statistics_init(); + call_interfaces_init(); + control_ng_init(); + dtls_init(); + + // fake current time + rtpe_now = (struct timeval) {150,0}; + rtpe_totalstats.started = 80; + + // test cmd_time_min/max/avg + + GString *graph_str = print_graphite_data(&rtpe_totalstats_lastinterval); + assert_g_string_eq(graph_str, + "offer_time_min 0.000000 150\n" + "offer_time_max 0.000000 150\n" + "offer_time_avg 0.000000 150\n" + "answer_time_min 0.000000 150\n" + "answer_time_max 0.000000 150\n" + "answer_time_avg 0.000000 150\n" + "delete_time_min 0.000000 150\n" + "delete_time_max 0.000000 150\n" + "delete_time_avg 0.000000 150\n" + "call_dur 0.000000 150\n" + "average_call_dur 0.000000 150\n" + "forced_term_sess 0 150\n" + "managed_sess 0 150\n" + "managed_sess_min 0 150\n" + "managed_sess_max 0 150\n" + "current_sessions_total 0 150\n" + "current_sessions_own 0 150\n" + "current_sessions_foreign 0 150\n" + "current_transcoded_media 0 150\n" + "current_sessions_ipv4 0 150\n" + "current_sessions_ipv6 0 150\n" + "current_sessions_mixed 0 150\n" + "nopacket_relayed_sess 0 150\n" + "oneway_stream_sess 0 150\n" + "regular_term_sess 0 150\n" + "relayed_errors 0 150\n" + "relayed_packets 0 150\n" + "silent_timeout_sess 0 150\n" + "final_timeout_sess 0 150\n" + "offer_timeout_sess 0 150\n" + "timeout_sess 0 150\n" + "reject_sess 0 150\n" + "offers_ps_min 0 150\n" + "offers_ps_max 0 150\n" + "offers_ps_avg 0 150\n" + "answers_ps_min 0 150\n" + "answers_ps_max 0 150\n" + "answers_ps_avg 0 150\n" + "deletes_ps_min 0 150\n" + "deletes_ps_max 0 150\n" + "deletes_ps_avg 0 150\n"); + + GQueue *stats = statistics_gather_metrics(); + assert_metrics_eq(stats, + "\n" + "{\n" + "Statistics over currently running sessions:\n" + "currentstatistics\n" + "\n" + "{\n" + "Owned sessions\n" + "sessionsown\n" + "0\n" + "0\n" + "type=\"own\"\n" + "Foreign sessions\n" + "sessionsforeign\n" + "0\n" + "0\n" + "type=\"foreign\"\n" + "Total sessions\n" + "sessionstotal\n" + "0\n" + "0\n" + "Transcoded media\n" + "transcodedmedia\n" + "0\n" + "0\n" + "Packets per second\n" + "packetrate\n" + "0\n" + "0\n" + "Bytes per second\n" + "byterate\n" + "0\n" + "0\n" + "Errors per second\n" + "errorrate\n" + "0\n" + "0\n" + "\n" + "}\n" + "Total statistics (does not include current running sessions):\n" + "totalstatistics\n" + "\n" + "{\n" + "Uptime of rtpengine\n" + "uptime\n" + "70 seconds\n" + "70\n" + "Total managed sessions\n" + "managedsessions\n" + "0\n" + "0\n" + "Total rejected sessions\n" + "rejectedsessions\n" + "0\n" + "0\n" + "reason=\"rejected\"\n" + "Total timed-out sessions via TIMEOUT\n" + "timeoutsessions\n" + "0\n" + "0\n" + "reason=\"timeout\"\n" + "Total timed-out sessions via SILENT_TIMEOUT\n" + "silenttimeoutsessions\n" + "0\n" + "0\n" + "reason=\"silent_timeout\"\n" + "Total timed-out sessions via FINAL_TIMEOUT\n" + "finaltimeoutsessions\n" + "0\n" + "0\n" + "reason=\"final_timeout\"\n" + "Total timed-out sessions via OFFER_TIMEOUT\n" + "offertimeoutsessions\n" + "0\n" + "0\n" + "reason=\"offer_timeout\"\n" + "Total regular terminated sessions\n" + "regularterminatedsessions\n" + "0\n" + "0\n" + "reason=\"terminated\"\n" + "Total forced terminated sessions\n" + "forcedterminatedsessions\n" + "0\n" + "0\n" + "reason=\"force_terminated\"\n" + "Total relayed packets\n" + "relayedpackets\n" + "0\n" + "0\n" + "Total relayed packet errors\n" + "relayedpacketerrors\n" + "0\n" + "0\n" + "Total relayed bytes\n" + "relayedbytes\n" + "0\n" + "0\n" + "Total number of streams with no relayed packets\n" + "zerowaystreams\n" + "0\n" + "0\n" + "Total number of 1-way streams\n" + "onewaystreams\n" + "0\n" + "0\n" + "Average call duration\n" + "avgcallduration\n" + "0.000000\n" + "0.000000\n" + "\n" + "\n" + "}\n" + "Graphite interval statistics (last reported values to graphite):\n" + "intervalstatistics\n" + "{\n" + "Total calls duration\n" + "totalcallsduration\n" + "0.000000\n" + "0.000000\n" + "\n" + "Min managed sessions\n" + "minmanagedsessions\n" + "0\n" + "0\n" + "Max managed sessions\n" + "maxmanagedsessions\n" + "0\n" + "0\n" + "Min/Max/Avg offer processing delay\n" + "0.000000/0.000000/0.000000 sec\n" + "minofferdelay\n" + "0.000000\n" + "maxofferdelay\n" + "0.000000\n" + "avgofferdelay\n" + "0.000000\n" + "Min/Max/Avg answer processing delay\n" + "0.000000/0.000000/0.000000 sec\n" + "minanswerdelay\n" + "0.000000\n" + "maxanswerdelay\n" + "0.000000\n" + "avganswerdelay\n" + "0.000000\n" + "Min/Max/Avg delete processing delay\n" + "0.000000/0.000000/0.000000 sec\n" + "mindeletedelay\n" + "0.000000\n" + "maxdeletedelay\n" + "0.000000\n" + "avgdeletedelay\n" + "0.000000\n" + "Min/Max/Avg offer requests per second\n" + "0/0/0 per sec\n" + "minofferrequestrate\n" + "0\n" + "maxofferrequestrate\n" + "0\n" + "avgofferrequestrate\n" + "0\n" + "Min/Max/Avg answer requests per second\n" + "0/0/0 per sec\n" + "minanswerrequestrate\n" + "0\n" + "maxanswerrequestrate\n" + "0\n" + "avganswerrequestrate\n" + "0\n" + "Min/Max/Avg delete requests per second\n" + "0/0/0 per sec\n" + "mindeleterequestrate\n" + "0\n" + "maxdeleterequestrate\n" + "0\n" + "avgdeleterequestrate\n" + "0\n" + "\n" + "\n" + "}\n" + "Control statistics:\n" + "controlstatistics\n" + "\n" + "{\n" + "proxies\n" + "[\n" + " Proxy | Ping | Offer | Answer | Delete | Query | List | StartRec | StopRec | StartFwd | StopFwd | BlkDTMF | UnblkDTMF | BlkMedia | UnblkMedia | PlayMedia | StopMedia | PlayDTMF | Stats | SlnMedia | UnslnMedia | Pub | SubReq | SubAns | Unsub \n" + "\n" + "]\n" + "totalpingcount\n" + "0\n" + "totaloffercount\n" + "0\n" + "totalanswercount\n" + "0\n" + "totaldeletecount\n" + "0\n" + "totalquerycount\n" + "0\n" + "totallistcount\n" + "0\n" + "totalstartreccount\n" + "0\n" + "totalstopreccount\n" + "0\n" + "totalstartfwdcount\n" + "0\n" + "totalstopfwdcount\n" + "0\n" + "totalblkdtmfcount\n" + "0\n" + "totalunblkdtmfcount\n" + "0\n" + "totalblkmediacount\n" + "0\n" + "totalunblkmediacount\n" + "0\n" + "totalplaymediacount\n" + "0\n" + "totalstopmediacount\n" + "0\n" + "totalplaydtmfcount\n" + "0\n" + "totalstatscount\n" + "0\n" + "totalslnmediacount\n" + "0\n" + "totalunslnmediacount\n" + "0\n" + "totalpubcount\n" + "0\n" + "totalsubreqcount\n" + "0\n" + "totalsubanscount\n" + "0\n" + "totalunsubcount\n" + "0\n" + "\n" + "}\n" + "interfaces\n" + "[\n" + "]\n" + "transcoders\n" + "\n" + "[\n" + "\n" + "]\n" + "}\n"); + + atomic64_inc(&rtpe_statsps.offers); + struct timeval diff = {2,500000}; + timeval_update_request_time(&rtpe_totalstats_interval.offer, &diff); + + atomic64_inc(&rtpe_statsps.offers); + diff = (struct timeval) {3,200000}; + timeval_update_request_time(&rtpe_totalstats_interval.offer, &diff); + + graph_str = print_graphite_data(&rtpe_totalstats_lastinterval); + assert_g_string_eq(graph_str, + "offer_time_min 2.500000 150\n" + "offer_time_max 3.200000 150\n" + "offer_time_avg 2.850000 150\n" + "answer_time_min 0.000000 150\n" + "answer_time_max 0.000000 150\n" + "answer_time_avg 0.000000 150\n" + "delete_time_min 0.000000 150\n" + "delete_time_max 0.000000 150\n" + "delete_time_avg 0.000000 150\n" + "call_dur 0.000000 150\n" + "average_call_dur 0.000000 150\n" + "forced_term_sess 0 150\n" + "managed_sess 0 150\n" + "managed_sess_min 0 150\n" + "managed_sess_max 0 150\n" + "current_sessions_total 0 150\n" + "current_sessions_own 0 150\n" + "current_sessions_foreign 0 150\n" + "current_transcoded_media 0 150\n" + "current_sessions_ipv4 0 150\n" + "current_sessions_ipv6 0 150\n" + "current_sessions_mixed 0 150\n" + "nopacket_relayed_sess 0 150\n" + "oneway_stream_sess 0 150\n" + "regular_term_sess 0 150\n" + "relayed_errors 0 150\n" + "relayed_packets 0 150\n" + "silent_timeout_sess 0 150\n" + "final_timeout_sess 0 150\n" + "offer_timeout_sess 0 150\n" + "timeout_sess 0 150\n" + "reject_sess 0 150\n" + "offers_ps_min 0 150\n" + "offers_ps_max 0 150\n" + "offers_ps_avg 0 150\n" + "answers_ps_min 0 150\n" + "answers_ps_max 0 150\n" + "answers_ps_avg 0 150\n" + "deletes_ps_min 0 150\n" + "deletes_ps_max 0 150\n" + "deletes_ps_avg 0 150\n"); + + stats = statistics_gather_metrics(); + assert_metrics_eq(stats, + "\n" + "{\n" + "Statistics over currently running sessions:\n" + "currentstatistics\n" + "\n" + "{\n" + "Owned sessions\n" + "sessionsown\n" + "0\n" + "0\n" + "type=\"own\"\n" + "Foreign sessions\n" + "sessionsforeign\n" + "0\n" + "0\n" + "type=\"foreign\"\n" + "Total sessions\n" + "sessionstotal\n" + "0\n" + "0\n" + "Transcoded media\n" + "transcodedmedia\n" + "0\n" + "0\n" + "Packets per second\n" + "packetrate\n" + "0\n" + "0\n" + "Bytes per second\n" + "byterate\n" + "0\n" + "0\n" + "Errors per second\n" + "errorrate\n" + "0\n" + "0\n" + "\n" + "}\n" + "Total statistics (does not include current running sessions):\n" + "totalstatistics\n" + "\n" + "{\n" + "Uptime of rtpengine\n" + "uptime\n" + "70 seconds\n" + "70\n" + "Total managed sessions\n" + "managedsessions\n" + "0\n" + "0\n" + "Total rejected sessions\n" + "rejectedsessions\n" + "0\n" + "0\n" + "reason=\"rejected\"\n" + "Total timed-out sessions via TIMEOUT\n" + "timeoutsessions\n" + "0\n" + "0\n" + "reason=\"timeout\"\n" + "Total timed-out sessions via SILENT_TIMEOUT\n" + "silenttimeoutsessions\n" + "0\n" + "0\n" + "reason=\"silent_timeout\"\n" + "Total timed-out sessions via FINAL_TIMEOUT\n" + "finaltimeoutsessions\n" + "0\n" + "0\n" + "reason=\"final_timeout\"\n" + "Total timed-out sessions via OFFER_TIMEOUT\n" + "offertimeoutsessions\n" + "0\n" + "0\n" + "reason=\"offer_timeout\"\n" + "Total regular terminated sessions\n" + "regularterminatedsessions\n" + "0\n" + "0\n" + "reason=\"terminated\"\n" + "Total forced terminated sessions\n" + "forcedterminatedsessions\n" + "0\n" + "0\n" + "reason=\"force_terminated\"\n" + "Total relayed packets\n" + "relayedpackets\n" + "0\n" + "0\n" + "Total relayed packet errors\n" + "relayedpacketerrors\n" + "0\n" + "0\n" + "Total relayed bytes\n" + "relayedbytes\n" + "0\n" + "0\n" + "Total number of streams with no relayed packets\n" + "zerowaystreams\n" + "0\n" + "0\n" + "Total number of 1-way streams\n" + "onewaystreams\n" + "0\n" + "0\n" + "Average call duration\n" + "avgcallduration\n" + "0.000000\n" + "0.000000\n" + "\n" + "\n" + "}\n" + "Graphite interval statistics (last reported values to graphite):\n" + "intervalstatistics\n" + "{\n" + "Total calls duration\n" + "totalcallsduration\n" + "0.000000\n" + "0.000000\n" + "\n" + "Min managed sessions\n" + "minmanagedsessions\n" + "0\n" + "0\n" + "Max managed sessions\n" + "maxmanagedsessions\n" + "0\n" + "0\n" + "Min/Max/Avg offer processing delay\n" + "2.500000/3.200000/2.850000 sec\n" + "minofferdelay\n" + "2.500000\n" + "maxofferdelay\n" + "3.200000\n" + "avgofferdelay\n" + "2.850000\n" + "Min/Max/Avg answer processing delay\n" + "0.000000/0.000000/0.000000 sec\n" + "minanswerdelay\n" + "0.000000\n" + "maxanswerdelay\n" + "0.000000\n" + "avganswerdelay\n" + "0.000000\n" + "Min/Max/Avg delete processing delay\n" + "0.000000/0.000000/0.000000 sec\n" + "mindeletedelay\n" + "0.000000\n" + "maxdeletedelay\n" + "0.000000\n" + "avgdeletedelay\n" + "0.000000\n" + "Min/Max/Avg offer requests per second\n" + "0/0/0 per sec\n" + "minofferrequestrate\n" + "0\n" + "maxofferrequestrate\n" + "0\n" + "avgofferrequestrate\n" + "0\n" + "Min/Max/Avg answer requests per second\n" + "0/0/0 per sec\n" + "minanswerrequestrate\n" + "0\n" + "maxanswerrequestrate\n" + "0\n" + "avganswerrequestrate\n" + "0\n" + "Min/Max/Avg delete requests per second\n" + "0/0/0 per sec\n" + "mindeleterequestrate\n" + "0\n" + "maxdeleterequestrate\n" + "0\n" + "avgdeleterequestrate\n" + "0\n" + "\n" + "\n" + "}\n" + "Control statistics:\n" + "controlstatistics\n" + "\n" + "{\n" + "proxies\n" + "[\n" + " Proxy | Ping | Offer | Answer | Delete | Query | List | StartRec | StopRec | StartFwd | StopFwd | BlkDTMF | UnblkDTMF | BlkMedia | UnblkMedia | PlayMedia | StopMedia | PlayDTMF | Stats | SlnMedia | UnslnMedia | Pub | SubReq | SubAns | Unsub \n" + "\n" + "]\n" + "totalpingcount\n" + "0\n" + "totaloffercount\n" + "0\n" + "totalanswercount\n" + "0\n" + "totaldeletecount\n" + "0\n" + "totalquerycount\n" + "0\n" + "totallistcount\n" + "0\n" + "totalstartreccount\n" + "0\n" + "totalstopreccount\n" + "0\n" + "totalstartfwdcount\n" + "0\n" + "totalstopfwdcount\n" + "0\n" + "totalblkdtmfcount\n" + "0\n" + "totalunblkdtmfcount\n" + "0\n" + "totalblkmediacount\n" + "0\n" + "totalunblkmediacount\n" + "0\n" + "totalplaymediacount\n" + "0\n" + "totalstopmediacount\n" + "0\n" + "totalplaydtmfcount\n" + "0\n" + "totalstatscount\n" + "0\n" + "totalslnmediacount\n" + "0\n" + "totalunslnmediacount\n" + "0\n" + "totalpubcount\n" + "0\n" + "totalsubreqcount\n" + "0\n" + "totalsubanscount\n" + "0\n" + "totalunsubcount\n" + "0\n" + "\n" + "}\n" + "interfaces\n" + "[\n" + "]\n" + "transcoders\n" + "\n" + "[\n" + "\n" + "]\n" + "}\n"); + + atomic64_inc(&rtpe_statsps.answers); + diff = (struct timeval) {3,200000}; + timeval_update_request_time(&rtpe_totalstats_interval.answer, &diff); + + graph_str = print_graphite_data(&rtpe_totalstats_lastinterval); + assert_g_string_eq(graph_str, + "offer_time_min 0.000000 150\n" + "offer_time_max 0.000000 150\n" + "offer_time_avg 0.000000 150\n" + "answer_time_min 3.200000 150\n" + "answer_time_max 3.200000 150\n" + "answer_time_avg 3.200000 150\n" + "delete_time_min 0.000000 150\n" + "delete_time_max 0.000000 150\n" + "delete_time_avg 0.000000 150\n" + "call_dur 0.000000 150\n" + "average_call_dur 0.000000 150\n" + "forced_term_sess 0 150\n" + "managed_sess 0 150\n" + "managed_sess_min 0 150\n" + "managed_sess_max 0 150\n" + "current_sessions_total 0 150\n" + "current_sessions_own 0 150\n" + "current_sessions_foreign 0 150\n" + "current_transcoded_media 0 150\n" + "current_sessions_ipv4 0 150\n" + "current_sessions_ipv6 0 150\n" + "current_sessions_mixed 0 150\n" + "nopacket_relayed_sess 0 150\n" + "oneway_stream_sess 0 150\n" + "regular_term_sess 0 150\n" + "relayed_errors 0 150\n" + "relayed_packets 0 150\n" + "silent_timeout_sess 0 150\n" + "final_timeout_sess 0 150\n" + "offer_timeout_sess 0 150\n" + "timeout_sess 0 150\n" + "reject_sess 0 150\n" + "offers_ps_min 0 150\n" + "offers_ps_max 0 150\n" + "offers_ps_avg 0 150\n" + "answers_ps_min 0 150\n" + "answers_ps_max 0 150\n" + "answers_ps_avg 0 150\n" + "deletes_ps_min 0 150\n" + "deletes_ps_max 0 150\n" + "deletes_ps_avg 0 150\n"); + + stats = statistics_gather_metrics(); + assert_metrics_eq(stats, + "\n" + "{\n" + "Statistics over currently running sessions:\n" + "currentstatistics\n" + "\n" + "{\n" + "Owned sessions\n" + "sessionsown\n" + "0\n" + "0\n" + "type=\"own\"\n" + "Foreign sessions\n" + "sessionsforeign\n" + "0\n" + "0\n" + "type=\"foreign\"\n" + "Total sessions\n" + "sessionstotal\n" + "0\n" + "0\n" + "Transcoded media\n" + "transcodedmedia\n" + "0\n" + "0\n" + "Packets per second\n" + "packetrate\n" + "0\n" + "0\n" + "Bytes per second\n" + "byterate\n" + "0\n" + "0\n" + "Errors per second\n" + "errorrate\n" + "0\n" + "0\n" + "\n" + "}\n" + "Total statistics (does not include current running sessions):\n" + "totalstatistics\n" + "\n" + "{\n" + "Uptime of rtpengine\n" + "uptime\n" + "70 seconds\n" + "70\n" + "Total managed sessions\n" + "managedsessions\n" + "0\n" + "0\n" + "Total rejected sessions\n" + "rejectedsessions\n" + "0\n" + "0\n" + "reason=\"rejected\"\n" + "Total timed-out sessions via TIMEOUT\n" + "timeoutsessions\n" + "0\n" + "0\n" + "reason=\"timeout\"\n" + "Total timed-out sessions via SILENT_TIMEOUT\n" + "silenttimeoutsessions\n" + "0\n" + "0\n" + "reason=\"silent_timeout\"\n" + "Total timed-out sessions via FINAL_TIMEOUT\n" + "finaltimeoutsessions\n" + "0\n" + "0\n" + "reason=\"final_timeout\"\n" + "Total timed-out sessions via OFFER_TIMEOUT\n" + "offertimeoutsessions\n" + "0\n" + "0\n" + "reason=\"offer_timeout\"\n" + "Total regular terminated sessions\n" + "regularterminatedsessions\n" + "0\n" + "0\n" + "reason=\"terminated\"\n" + "Total forced terminated sessions\n" + "forcedterminatedsessions\n" + "0\n" + "0\n" + "reason=\"force_terminated\"\n" + "Total relayed packets\n" + "relayedpackets\n" + "0\n" + "0\n" + "Total relayed packet errors\n" + "relayedpacketerrors\n" + "0\n" + "0\n" + "Total relayed bytes\n" + "relayedbytes\n" + "0\n" + "0\n" + "Total number of streams with no relayed packets\n" + "zerowaystreams\n" + "0\n" + "0\n" + "Total number of 1-way streams\n" + "onewaystreams\n" + "0\n" + "0\n" + "Average call duration\n" + "avgcallduration\n" + "0.000000\n" + "0.000000\n" + "\n" + "\n" + "}\n" + "Graphite interval statistics (last reported values to graphite):\n" + "intervalstatistics\n" + "{\n" + "Total calls duration\n" + "totalcallsduration\n" + "0.000000\n" + "0.000000\n" + "\n" + "Min managed sessions\n" + "minmanagedsessions\n" + "0\n" + "0\n" + "Max managed sessions\n" + "maxmanagedsessions\n" + "0\n" + "0\n" + "Min/Max/Avg offer processing delay\n" + "0.000000/0.000000/0.000000 sec\n" + "minofferdelay\n" + "0.000000\n" + "maxofferdelay\n" + "0.000000\n" + "avgofferdelay\n" + "0.000000\n" + "Min/Max/Avg answer processing delay\n" + "3.200000/3.200000/3.200000 sec\n" + "minanswerdelay\n" + "3.200000\n" + "maxanswerdelay\n" + "3.200000\n" + "avganswerdelay\n" + "3.200000\n" + "Min/Max/Avg delete processing delay\n" + "0.000000/0.000000/0.000000 sec\n" + "mindeletedelay\n" + "0.000000\n" + "maxdeletedelay\n" + "0.000000\n" + "avgdeletedelay\n" + "0.000000\n" + "Min/Max/Avg offer requests per second\n" + "0/0/0 per sec\n" + "minofferrequestrate\n" + "0\n" + "maxofferrequestrate\n" + "0\n" + "avgofferrequestrate\n" + "0\n" + "Min/Max/Avg answer requests per second\n" + "0/0/0 per sec\n" + "minanswerrequestrate\n" + "0\n" + "maxanswerrequestrate\n" + "0\n" + "avganswerrequestrate\n" + "0\n" + "Min/Max/Avg delete requests per second\n" + "0/0/0 per sec\n" + "mindeleterequestrate\n" + "0\n" + "maxdeleterequestrate\n" + "0\n" + "avgdeleterequestrate\n" + "0\n" + "\n" + "\n" + "}\n" + "Control statistics:\n" + "controlstatistics\n" + "\n" + "{\n" + "proxies\n" + "[\n" + " Proxy | Ping | Offer | Answer | Delete | Query | List | StartRec | StopRec | StartFwd | StopFwd | BlkDTMF | UnblkDTMF | BlkMedia | UnblkMedia | PlayMedia | StopMedia | PlayDTMF | Stats | SlnMedia | UnslnMedia | Pub | SubReq | SubAns | Unsub \n" + "\n" + "]\n" + "totalpingcount\n" + "0\n" + "totaloffercount\n" + "0\n" + "totalanswercount\n" + "0\n" + "totaldeletecount\n" + "0\n" + "totalquerycount\n" + "0\n" + "totallistcount\n" + "0\n" + "totalstartreccount\n" + "0\n" + "totalstopreccount\n" + "0\n" + "totalstartfwdcount\n" + "0\n" + "totalstopfwdcount\n" + "0\n" + "totalblkdtmfcount\n" + "0\n" + "totalunblkdtmfcount\n" + "0\n" + "totalblkmediacount\n" + "0\n" + "totalunblkmediacount\n" + "0\n" + "totalplaymediacount\n" + "0\n" + "totalstopmediacount\n" + "0\n" + "totalplaydtmfcount\n" + "0\n" + "totalstatscount\n" + "0\n" + "totalslnmediacount\n" + "0\n" + "totalunslnmediacount\n" + "0\n" + "totalpubcount\n" + "0\n" + "totalsubreqcount\n" + "0\n" + "totalsubanscount\n" + "0\n" + "totalunsubcount\n" + "0\n" + "\n" + "}\n" + "interfaces\n" + "[\n" + "]\n" + "transcoders\n" + "\n" + "[\n" + "\n" + "]\n" + "}\n"); + + // test cmd_ps_min/max/avg + + call_timer(NULL); + atomic64_add(&rtpe_statsps.offers, 100); + + sleep(1); // timer only runs once per second + + atomic64_add(&rtpe_statsps.offers, 20); + call_timer(NULL); + + sleep(1); + + atomic64_add(&rtpe_statsps.offers, 200); + call_timer(NULL); + + graph_str = print_graphite_data(&rtpe_totalstats_lastinterval); + assert_g_string_eq(graph_str, + "offer_time_min 0.000000 150\n" + "offer_time_max 0.000000 150\n" + "offer_time_avg 0.000000 150\n" + "answer_time_min 0.000000 150\n" + "answer_time_max 0.000000 150\n" + "answer_time_avg 0.000000 150\n" + "delete_time_min 0.000000 150\n" + "delete_time_max 0.000000 150\n" + "delete_time_avg 0.000000 150\n" + "call_dur 0.000000 150\n" + "average_call_dur 0.000000 150\n" + "forced_term_sess 0 150\n" + "managed_sess 0 150\n" + "managed_sess_min 0 150\n" + "managed_sess_max 0 150\n" + "current_sessions_total 0 150\n" + "current_sessions_own 0 150\n" + "current_sessions_foreign 0 150\n" + "current_transcoded_media 0 150\n" + "current_sessions_ipv4 0 150\n" + "current_sessions_ipv6 0 150\n" + "current_sessions_mixed 0 150\n" + "nopacket_relayed_sess 0 150\n" + "oneway_stream_sess 0 150\n" + "regular_term_sess 0 150\n" + "relayed_errors 0 150\n" + "relayed_packets 0 150\n" + "silent_timeout_sess 0 150\n" + "final_timeout_sess 0 150\n" + "offer_timeout_sess 0 150\n" + "timeout_sess 0 150\n" + "reject_sess 0 150\n" + "offers_ps_min 120 150\n" + "offers_ps_max 200 150\n" + "offers_ps_avg 106 150\n" + "answers_ps_min 0 150\n" + "answers_ps_max 0 150\n" + "answers_ps_avg 0 150\n" + "deletes_ps_min 0 150\n" + "deletes_ps_max 0 150\n" + "deletes_ps_avg 0 150\n"); + + stats = statistics_gather_metrics(); + assert_metrics_eq(stats, + "\n" + "{\n" + "Statistics over currently running sessions:\n" + "currentstatistics\n" + "\n" + "{\n" + "Owned sessions\n" + "sessionsown\n" + "0\n" + "0\n" + "type=\"own\"\n" + "Foreign sessions\n" + "sessionsforeign\n" + "0\n" + "0\n" + "type=\"foreign\"\n" + "Total sessions\n" + "sessionstotal\n" + "0\n" + "0\n" + "Transcoded media\n" + "transcodedmedia\n" + "0\n" + "0\n" + "Packets per second\n" + "packetrate\n" + "0\n" + "0\n" + "Bytes per second\n" + "byterate\n" + "0\n" + "0\n" + "Errors per second\n" + "errorrate\n" + "0\n" + "0\n" + "\n" + "}\n" + "Total statistics (does not include current running sessions):\n" + "totalstatistics\n" + "\n" + "{\n" + "Uptime of rtpengine\n" + "uptime\n" + "70 seconds\n" + "70\n" + "Total managed sessions\n" + "managedsessions\n" + "0\n" + "0\n" + "Total rejected sessions\n" + "rejectedsessions\n" + "0\n" + "0\n" + "reason=\"rejected\"\n" + "Total timed-out sessions via TIMEOUT\n" + "timeoutsessions\n" + "0\n" + "0\n" + "reason=\"timeout\"\n" + "Total timed-out sessions via SILENT_TIMEOUT\n" + "silenttimeoutsessions\n" + "0\n" + "0\n" + "reason=\"silent_timeout\"\n" + "Total timed-out sessions via FINAL_TIMEOUT\n" + "finaltimeoutsessions\n" + "0\n" + "0\n" + "reason=\"final_timeout\"\n" + "Total timed-out sessions via OFFER_TIMEOUT\n" + "offertimeoutsessions\n" + "0\n" + "0\n" + "reason=\"offer_timeout\"\n" + "Total regular terminated sessions\n" + "regularterminatedsessions\n" + "0\n" + "0\n" + "reason=\"terminated\"\n" + "Total forced terminated sessions\n" + "forcedterminatedsessions\n" + "0\n" + "0\n" + "reason=\"force_terminated\"\n" + "Total relayed packets\n" + "relayedpackets\n" + "0\n" + "0\n" + "Total relayed packet errors\n" + "relayedpacketerrors\n" + "0\n" + "0\n" + "Total relayed bytes\n" + "relayedbytes\n" + "0\n" + "0\n" + "Total number of streams with no relayed packets\n" + "zerowaystreams\n" + "0\n" + "0\n" + "Total number of 1-way streams\n" + "onewaystreams\n" + "0\n" + "0\n" + "Average call duration\n" + "avgcallduration\n" + "0.000000\n" + "0.000000\n" + "\n" + "\n" + "}\n" + "Graphite interval statistics (last reported values to graphite):\n" + "intervalstatistics\n" + "{\n" + "Total calls duration\n" + "totalcallsduration\n" + "0.000000\n" + "0.000000\n" + "\n" + "Min managed sessions\n" + "minmanagedsessions\n" + "0\n" + "0\n" + "Max managed sessions\n" + "maxmanagedsessions\n" + "0\n" + "0\n" + "Min/Max/Avg offer processing delay\n" + "0.000000/0.000000/0.000000 sec\n" + "minofferdelay\n" + "0.000000\n" + "maxofferdelay\n" + "0.000000\n" + "avgofferdelay\n" + "0.000000\n" + "Min/Max/Avg answer processing delay\n" + "0.000000/0.000000/0.000000 sec\n" + "minanswerdelay\n" + "0.000000\n" + "maxanswerdelay\n" + "0.000000\n" + "avganswerdelay\n" + "0.000000\n" + "Min/Max/Avg delete processing delay\n" + "0.000000/0.000000/0.000000 sec\n" + "mindeletedelay\n" + "0.000000\n" + "maxdeletedelay\n" + "0.000000\n" + "avgdeletedelay\n" + "0.000000\n" + "Min/Max/Avg offer requests per second\n" + "120/200/106 per sec\n" + "minofferrequestrate\n" + "120\n" + "maxofferrequestrate\n" + "200\n" + "avgofferrequestrate\n" + "106\n" + "Min/Max/Avg answer requests per second\n" + "0/0/0 per sec\n" + "minanswerrequestrate\n" + "0\n" + "maxanswerrequestrate\n" + "0\n" + "avganswerrequestrate\n" + "0\n" + "Min/Max/Avg delete requests per second\n" + "0/0/0 per sec\n" + "mindeleterequestrate\n" + "0\n" + "maxdeleterequestrate\n" + "0\n" + "avgdeleterequestrate\n" + "0\n" + "\n" + "\n" + "}\n" + "Control statistics:\n" + "controlstatistics\n" + "\n" + "{\n" + "proxies\n" + "[\n" + " Proxy | Ping | Offer | Answer | Delete | Query | List | StartRec | StopRec | StartFwd | StopFwd | BlkDTMF | UnblkDTMF | BlkMedia | UnblkMedia | PlayMedia | StopMedia | PlayDTMF | Stats | SlnMedia | UnslnMedia | Pub | SubReq | SubAns | Unsub \n" + "\n" + "]\n" + "totalpingcount\n" + "0\n" + "totaloffercount\n" + "0\n" + "totalanswercount\n" + "0\n" + "totaldeletecount\n" + "0\n" + "totalquerycount\n" + "0\n" + "totallistcount\n" + "0\n" + "totalstartreccount\n" + "0\n" + "totalstopreccount\n" + "0\n" + "totalstartfwdcount\n" + "0\n" + "totalstopfwdcount\n" + "0\n" + "totalblkdtmfcount\n" + "0\n" + "totalunblkdtmfcount\n" + "0\n" + "totalblkmediacount\n" + "0\n" + "totalunblkmediacount\n" + "0\n" + "totalplaymediacount\n" + "0\n" + "totalstopmediacount\n" + "0\n" + "totalplaydtmfcount\n" + "0\n" + "totalstatscount\n" + "0\n" + "totalslnmediacount\n" + "0\n" + "totalunslnmediacount\n" + "0\n" + "totalpubcount\n" + "0\n" + "totalsubreqcount\n" + "0\n" + "totalsubanscount\n" + "0\n" + "totalunsubcount\n" + "0\n" + "\n" + "}\n" + "interfaces\n" + "[\n" + "]\n" + "transcoders\n" + "\n" + "[\n" + "\n" + "]\n" + "}\n"); + + // test average call duration + + const str callid1 = STR_CONST_INIT("test1"); + const str callid2 = STR_CONST_INIT("test2"); + struct call *call1 = call_get_or_create(&callid1, false, true); + struct call_monologue *ml1 = call_get_or_create_monologue(call1, &callid1); + struct call *call2 = call_get_or_create(&callid2, false, true); + struct call_monologue *ml2 = call_get_or_create_monologue(call2, &callid2); + ml1->started = (struct timeval) {150,0}; + ml2->started = (struct timeval) {50,0}; + + graph_str = print_graphite_data(&rtpe_totalstats_lastinterval); + assert_g_string_eq(graph_str, + "offer_time_min 0.000000 150\n" + "offer_time_max 0.000000 150\n" + "offer_time_avg 0.000000 150\n" + "answer_time_min 0.000000 150\n" + "answer_time_max 0.000000 150\n" + "answer_time_avg 0.000000 150\n" + "delete_time_min 0.000000 150\n" + "delete_time_max 0.000000 150\n" + "delete_time_avg 0.000000 150\n" + "call_dur 0.000000 150\n" + "average_call_dur 0.000000 150\n" + "forced_term_sess 0 150\n" + "managed_sess 0 150\n" + "managed_sess_min 0 150\n" + "managed_sess_max 2 150\n" + "current_sessions_total 2 150\n" + "current_sessions_own 2 150\n" + "current_sessions_foreign 0 150\n" + "current_transcoded_media 0 150\n" + "current_sessions_ipv4 0 150\n" + "current_sessions_ipv6 0 150\n" + "current_sessions_mixed 0 150\n" + "nopacket_relayed_sess 0 150\n" + "oneway_stream_sess 0 150\n" + "regular_term_sess 0 150\n" + "relayed_errors 0 150\n" + "relayed_packets 0 150\n" + "silent_timeout_sess 0 150\n" + "final_timeout_sess 0 150\n" + "offer_timeout_sess 0 150\n" + "timeout_sess 0 150\n" + "reject_sess 0 150\n" + "offers_ps_min 0 150\n" + "offers_ps_max 0 150\n" + "offers_ps_avg 0 150\n" + "answers_ps_min 0 150\n" + "answers_ps_max 0 150\n" + "answers_ps_avg 0 150\n" + "deletes_ps_min 0 150\n" + "deletes_ps_max 0 150\n" + "deletes_ps_avg 0 150\n"); + + stats = statistics_gather_metrics(); + assert_metrics_eq(stats, + "\n" + "{\n" + "Statistics over currently running sessions:\n" + "currentstatistics\n" + "\n" + "{\n" + "Owned sessions\n" + "sessionsown\n" + "2\n" + "2\n" + "type=\"own\"\n" + "Foreign sessions\n" + "sessionsforeign\n" + "0\n" + "0\n" + "type=\"foreign\"\n" + "Total sessions\n" + "sessionstotal\n" + "2\n" + "2\n" + "Transcoded media\n" + "transcodedmedia\n" + "0\n" + "0\n" + "Packets per second\n" + "packetrate\n" + "0\n" + "0\n" + "Bytes per second\n" + "byterate\n" + "0\n" + "0\n" + "Errors per second\n" + "errorrate\n" + "0\n" + "0\n" + "\n" + "}\n" + "Total statistics (does not include current running sessions):\n" + "totalstatistics\n" + "\n" + "{\n" + "Uptime of rtpengine\n" + "uptime\n" + "70 seconds\n" + "70\n" + "Total managed sessions\n" + "managedsessions\n" + "0\n" + "0\n" + "Total rejected sessions\n" + "rejectedsessions\n" + "0\n" + "0\n" + "reason=\"rejected\"\n" + "Total timed-out sessions via TIMEOUT\n" + "timeoutsessions\n" + "0\n" + "0\n" + "reason=\"timeout\"\n" + "Total timed-out sessions via SILENT_TIMEOUT\n" + "silenttimeoutsessions\n" + "0\n" + "0\n" + "reason=\"silent_timeout\"\n" + "Total timed-out sessions via FINAL_TIMEOUT\n" + "finaltimeoutsessions\n" + "0\n" + "0\n" + "reason=\"final_timeout\"\n" + "Total timed-out sessions via OFFER_TIMEOUT\n" + "offertimeoutsessions\n" + "0\n" + "0\n" + "reason=\"offer_timeout\"\n" + "Total regular terminated sessions\n" + "regularterminatedsessions\n" + "0\n" + "0\n" + "reason=\"terminated\"\n" + "Total forced terminated sessions\n" + "forcedterminatedsessions\n" + "0\n" + "0\n" + "reason=\"force_terminated\"\n" + "Total relayed packets\n" + "relayedpackets\n" + "0\n" + "0\n" + "Total relayed packet errors\n" + "relayedpacketerrors\n" + "0\n" + "0\n" + "Total relayed bytes\n" + "relayedbytes\n" + "0\n" + "0\n" + "Total number of streams with no relayed packets\n" + "zerowaystreams\n" + "0\n" + "0\n" + "Total number of 1-way streams\n" + "onewaystreams\n" + "0\n" + "0\n" + "Average call duration\n" + "avgcallduration\n" + "0.000000\n" + "0.000000\n" + "\n" + "\n" + "}\n" + "Graphite interval statistics (last reported values to graphite):\n" + "intervalstatistics\n" + "{\n" + "Total calls duration\n" + "totalcallsduration\n" + "0.000000\n" + "0.000000\n" + "\n" + "Min managed sessions\n" + "minmanagedsessions\n" + "0\n" + "0\n" + "Max managed sessions\n" + "maxmanagedsessions\n" + "2\n" + "2\n" + "Min/Max/Avg offer processing delay\n" + "0.000000/0.000000/0.000000 sec\n" + "minofferdelay\n" + "0.000000\n" + "maxofferdelay\n" + "0.000000\n" + "avgofferdelay\n" + "0.000000\n" + "Min/Max/Avg answer processing delay\n" + "0.000000/0.000000/0.000000 sec\n" + "minanswerdelay\n" + "0.000000\n" + "maxanswerdelay\n" + "0.000000\n" + "avganswerdelay\n" + "0.000000\n" + "Min/Max/Avg delete processing delay\n" + "0.000000/0.000000/0.000000 sec\n" + "mindeletedelay\n" + "0.000000\n" + "maxdeletedelay\n" + "0.000000\n" + "avgdeletedelay\n" + "0.000000\n" + "Min/Max/Avg offer requests per second\n" + "0/0/0 per sec\n" + "minofferrequestrate\n" + "0\n" + "maxofferrequestrate\n" + "0\n" + "avgofferrequestrate\n" + "0\n" + "Min/Max/Avg answer requests per second\n" + "0/0/0 per sec\n" + "minanswerrequestrate\n" + "0\n" + "maxanswerrequestrate\n" + "0\n" + "avganswerrequestrate\n" + "0\n" + "Min/Max/Avg delete requests per second\n" + "0/0/0 per sec\n" + "mindeleterequestrate\n" + "0\n" + "maxdeleterequestrate\n" + "0\n" + "avgdeleterequestrate\n" + "0\n" + "\n" + "\n" + "}\n" + "Control statistics:\n" + "controlstatistics\n" + "\n" + "{\n" + "proxies\n" + "[\n" + " Proxy | Ping | Offer | Answer | Delete | Query | List | StartRec | StopRec | StartFwd | StopFwd | BlkDTMF | UnblkDTMF | BlkMedia | UnblkMedia | PlayMedia | StopMedia | PlayDTMF | Stats | SlnMedia | UnslnMedia | Pub | SubReq | SubAns | Unsub \n" + "\n" + "]\n" + "totalpingcount\n" + "0\n" + "totaloffercount\n" + "0\n" + "totalanswercount\n" + "0\n" + "totaldeletecount\n" + "0\n" + "totalquerycount\n" + "0\n" + "totallistcount\n" + "0\n" + "totalstartreccount\n" + "0\n" + "totalstopreccount\n" + "0\n" + "totalstartfwdcount\n" + "0\n" + "totalstopfwdcount\n" + "0\n" + "totalblkdtmfcount\n" + "0\n" + "totalunblkdtmfcount\n" + "0\n" + "totalblkmediacount\n" + "0\n" + "totalunblkmediacount\n" + "0\n" + "totalplaymediacount\n" + "0\n" + "totalstopmediacount\n" + "0\n" + "totalplaydtmfcount\n" + "0\n" + "totalstatscount\n" + "0\n" + "totalslnmediacount\n" + "0\n" + "totalunslnmediacount\n" + "0\n" + "totalpubcount\n" + "0\n" + "totalsubreqcount\n" + "0\n" + "totalsubanscount\n" + "0\n" + "totalunsubcount\n" + "0\n" + "\n" + "}\n" + "interfaces\n" + "[\n" + "]\n" + "transcoders\n" + "\n" + "[\n" + "\n" + "]\n" + "}\n"); + + + struct timeval graphite_interval_tv = {100,0}; + rtpe_now = (struct timeval) {200,0}; + + add_total_calls_duration_in_interval(&graphite_interval_tv); + + graph_str = print_graphite_data(&rtpe_totalstats_lastinterval); + assert_g_string_eq(graph_str, + "offer_time_min 0.000000 200\n" + "offer_time_max 0.000000 200\n" + "offer_time_avg 0.000000 200\n" + "answer_time_min 0.000000 200\n" + "answer_time_max 0.000000 200\n" + "answer_time_avg 0.000000 200\n" + "delete_time_min 0.000000 200\n" + "delete_time_max 0.000000 200\n" + "delete_time_avg 0.000000 200\n" + "call_dur 200.000000 200\n" + "average_call_dur 0.000000 200\n" + "forced_term_sess 0 200\n" + "managed_sess 0 200\n" + "managed_sess_min 2 200\n" + "managed_sess_max 2 200\n" + "current_sessions_total 2 200\n" + "current_sessions_own 2 200\n" + "current_sessions_foreign 0 200\n" + "current_transcoded_media 0 200\n" + "current_sessions_ipv4 0 200\n" + "current_sessions_ipv6 0 200\n" + "current_sessions_mixed 0 200\n" + "nopacket_relayed_sess 0 200\n" + "oneway_stream_sess 0 200\n" + "regular_term_sess 0 200\n" + "relayed_errors 0 200\n" + "relayed_packets 0 200\n" + "silent_timeout_sess 0 200\n" + "final_timeout_sess 0 200\n" + "offer_timeout_sess 0 200\n" + "timeout_sess 0 200\n" + "reject_sess 0 200\n" + "offers_ps_min 0 200\n" + "offers_ps_max 0 200\n" + "offers_ps_avg 0 200\n" + "answers_ps_min 0 200\n" + "answers_ps_max 0 200\n" + "answers_ps_avg 0 200\n" + "deletes_ps_min 0 200\n" + "deletes_ps_max 0 200\n" + "deletes_ps_avg 0 200\n"); + + stats = statistics_gather_metrics(); + assert_metrics_eq(stats, + "\n" + "{\n" + "Statistics over currently running sessions:\n" + "currentstatistics\n" + "\n" + "{\n" + "Owned sessions\n" + "sessionsown\n" + "2\n" + "2\n" + "type=\"own\"\n" + "Foreign sessions\n" + "sessionsforeign\n" + "0\n" + "0\n" + "type=\"foreign\"\n" + "Total sessions\n" + "sessionstotal\n" + "2\n" + "2\n" + "Transcoded media\n" + "transcodedmedia\n" + "0\n" + "0\n" + "Packets per second\n" + "packetrate\n" + "0\n" + "0\n" + "Bytes per second\n" + "byterate\n" + "0\n" + "0\n" + "Errors per second\n" + "errorrate\n" + "0\n" + "0\n" + "\n" + "}\n" + "Total statistics (does not include current running sessions):\n" + "totalstatistics\n" + "\n" + "{\n" + "Uptime of rtpengine\n" + "uptime\n" + "120 seconds\n" + "120\n" + "Total managed sessions\n" + "managedsessions\n" + "0\n" + "0\n" + "Total rejected sessions\n" + "rejectedsessions\n" + "0\n" + "0\n" + "reason=\"rejected\"\n" + "Total timed-out sessions via TIMEOUT\n" + "timeoutsessions\n" + "0\n" + "0\n" + "reason=\"timeout\"\n" + "Total timed-out sessions via SILENT_TIMEOUT\n" + "silenttimeoutsessions\n" + "0\n" + "0\n" + "reason=\"silent_timeout\"\n" + "Total timed-out sessions via FINAL_TIMEOUT\n" + "finaltimeoutsessions\n" + "0\n" + "0\n" + "reason=\"final_timeout\"\n" + "Total timed-out sessions via OFFER_TIMEOUT\n" + "offertimeoutsessions\n" + "0\n" + "0\n" + "reason=\"offer_timeout\"\n" + "Total regular terminated sessions\n" + "regularterminatedsessions\n" + "0\n" + "0\n" + "reason=\"terminated\"\n" + "Total forced terminated sessions\n" + "forcedterminatedsessions\n" + "0\n" + "0\n" + "reason=\"force_terminated\"\n" + "Total relayed packets\n" + "relayedpackets\n" + "0\n" + "0\n" + "Total relayed packet errors\n" + "relayedpacketerrors\n" + "0\n" + "0\n" + "Total relayed bytes\n" + "relayedbytes\n" + "0\n" + "0\n" + "Total number of streams with no relayed packets\n" + "zerowaystreams\n" + "0\n" + "0\n" + "Total number of 1-way streams\n" + "onewaystreams\n" + "0\n" + "0\n" + "Average call duration\n" + "avgcallduration\n" + "0.000000\n" + "0.000000\n" + "\n" + "\n" + "}\n" + "Graphite interval statistics (last reported values to graphite):\n" + "intervalstatistics\n" + "{\n" + "Total calls duration\n" + "totalcallsduration\n" + "200.000000\n" + "200.000000\n" + "\n" + "Min managed sessions\n" + "minmanagedsessions\n" + "2\n" + "2\n" + "Max managed sessions\n" + "maxmanagedsessions\n" + "2\n" + "2\n" + "Min/Max/Avg offer processing delay\n" + "0.000000/0.000000/0.000000 sec\n" + "minofferdelay\n" + "0.000000\n" + "maxofferdelay\n" + "0.000000\n" + "avgofferdelay\n" + "0.000000\n" + "Min/Max/Avg answer processing delay\n" + "0.000000/0.000000/0.000000 sec\n" + "minanswerdelay\n" + "0.000000\n" + "maxanswerdelay\n" + "0.000000\n" + "avganswerdelay\n" + "0.000000\n" + "Min/Max/Avg delete processing delay\n" + "0.000000/0.000000/0.000000 sec\n" + "mindeletedelay\n" + "0.000000\n" + "maxdeletedelay\n" + "0.000000\n" + "avgdeletedelay\n" + "0.000000\n" + "Min/Max/Avg offer requests per second\n" + "0/0/0 per sec\n" + "minofferrequestrate\n" + "0\n" + "maxofferrequestrate\n" + "0\n" + "avgofferrequestrate\n" + "0\n" + "Min/Max/Avg answer requests per second\n" + "0/0/0 per sec\n" + "minanswerrequestrate\n" + "0\n" + "maxanswerrequestrate\n" + "0\n" + "avganswerrequestrate\n" + "0\n" + "Min/Max/Avg delete requests per second\n" + "0/0/0 per sec\n" + "mindeleterequestrate\n" + "0\n" + "maxdeleterequestrate\n" + "0\n" + "avgdeleterequestrate\n" + "0\n" + "\n" + "\n" + "}\n" + "Control statistics:\n" + "controlstatistics\n" + "\n" + "{\n" + "proxies\n" + "[\n" + " Proxy | Ping | Offer | Answer | Delete | Query | List | StartRec | StopRec | StartFwd | StopFwd | BlkDTMF | UnblkDTMF | BlkMedia | UnblkMedia | PlayMedia | StopMedia | PlayDTMF | Stats | SlnMedia | UnslnMedia | Pub | SubReq | SubAns | Unsub \n" + "\n" + "]\n" + "totalpingcount\n" + "0\n" + "totaloffercount\n" + "0\n" + "totalanswercount\n" + "0\n" + "totaldeletecount\n" + "0\n" + "totalquerycount\n" + "0\n" + "totallistcount\n" + "0\n" + "totalstartreccount\n" + "0\n" + "totalstopreccount\n" + "0\n" + "totalstartfwdcount\n" + "0\n" + "totalstopfwdcount\n" + "0\n" + "totalblkdtmfcount\n" + "0\n" + "totalunblkdtmfcount\n" + "0\n" + "totalblkmediacount\n" + "0\n" + "totalunblkmediacount\n" + "0\n" + "totalplaymediacount\n" + "0\n" + "totalstopmediacount\n" + "0\n" + "totalplaydtmfcount\n" + "0\n" + "totalstatscount\n" + "0\n" + "totalslnmediacount\n" + "0\n" + "totalunslnmediacount\n" + "0\n" + "totalpubcount\n" + "0\n" + "totalsubreqcount\n" + "0\n" + "totalsubanscount\n" + "0\n" + "totalunsubcount\n" + "0\n" + "\n" + "}\n" + "interfaces\n" + "[\n" + "]\n" + "transcoders\n" + "\n" + "[\n" + "\n" + "]\n" + "}\n"); + + + call_destroy(call1); + call_destroy(call2); + obj_put(call1); + obj_put(call2); + + // test average call duration + + graph_str = print_graphite_data(&rtpe_totalstats_lastinterval); + assert_g_string_eq(graph_str, + "offer_time_min 0.000000 200\n" + "offer_time_max 0.000000 200\n" + "offer_time_avg 0.000000 200\n" + "answer_time_min 0.000000 200\n" + "answer_time_max 0.000000 200\n" + "answer_time_avg 0.000000 200\n" + "delete_time_min 0.000000 200\n" + "delete_time_max 0.000000 200\n" + "delete_time_avg 0.000000 200\n" + "call_dur 0.000000 200\n" + "average_call_dur 100.000000 200\n" + "forced_term_sess 0 200\n" + "managed_sess 2 200\n" + "managed_sess_min 0 200\n" + "managed_sess_max 2 200\n" + "current_sessions_total 0 200\n" + "current_sessions_own 0 200\n" + "current_sessions_foreign 0 200\n" + "current_transcoded_media 0 200\n" + "current_sessions_ipv4 0 200\n" + "current_sessions_ipv6 0 200\n" + "current_sessions_mixed 0 200\n" + "nopacket_relayed_sess 0 200\n" + "oneway_stream_sess 0 200\n" + "regular_term_sess 0 200\n" + "relayed_errors 0 200\n" + "relayed_packets 0 200\n" + "silent_timeout_sess 0 200\n" + "final_timeout_sess 0 200\n" + "offer_timeout_sess 0 200\n" + "timeout_sess 0 200\n" + "reject_sess 0 200\n" + "offers_ps_min 0 200\n" + "offers_ps_max 0 200\n" + "offers_ps_avg 0 200\n" + "answers_ps_min 0 200\n" + "answers_ps_max 0 200\n" + "answers_ps_avg 0 200\n" + "deletes_ps_min 0 200\n" + "deletes_ps_max 0 200\n" + "deletes_ps_avg 0 200\n"); + + stats = statistics_gather_metrics(); + assert_metrics_eq(stats, + "\n" + "{\n" + "Statistics over currently running sessions:\n" + "currentstatistics\n" + "\n" + "{\n" + "Owned sessions\n" + "sessionsown\n" + "0\n" + "0\n" + "type=\"own\"\n" + "Foreign sessions\n" + "sessionsforeign\n" + "0\n" + "0\n" + "type=\"foreign\"\n" + "Total sessions\n" + "sessionstotal\n" + "0\n" + "0\n" + "Transcoded media\n" + "transcodedmedia\n" + "0\n" + "0\n" + "Packets per second\n" + "packetrate\n" + "0\n" + "0\n" + "Bytes per second\n" + "byterate\n" + "0\n" + "0\n" + "Errors per second\n" + "errorrate\n" + "0\n" + "0\n" + "\n" + "}\n" + "Total statistics (does not include current running sessions):\n" + "totalstatistics\n" + "\n" + "{\n" + "Uptime of rtpengine\n" + "uptime\n" + "120 seconds\n" + "120\n" + "Total managed sessions\n" + "managedsessions\n" + "2\n" + "2\n" + "Total rejected sessions\n" + "rejectedsessions\n" + "0\n" + "0\n" + "reason=\"rejected\"\n" + "Total timed-out sessions via TIMEOUT\n" + "timeoutsessions\n" + "0\n" + "0\n" + "reason=\"timeout\"\n" + "Total timed-out sessions via SILENT_TIMEOUT\n" + "silenttimeoutsessions\n" + "0\n" + "0\n" + "reason=\"silent_timeout\"\n" + "Total timed-out sessions via FINAL_TIMEOUT\n" + "finaltimeoutsessions\n" + "0\n" + "0\n" + "reason=\"final_timeout\"\n" + "Total timed-out sessions via OFFER_TIMEOUT\n" + "offertimeoutsessions\n" + "0\n" + "0\n" + "reason=\"offer_timeout\"\n" + "Total regular terminated sessions\n" + "regularterminatedsessions\n" + "0\n" + "0\n" + "reason=\"terminated\"\n" + "Total forced terminated sessions\n" + "forcedterminatedsessions\n" + "0\n" + "0\n" + "reason=\"force_terminated\"\n" + "Total relayed packets\n" + "relayedpackets\n" + "0\n" + "0\n" + "Total relayed packet errors\n" + "relayedpacketerrors\n" + "0\n" + "0\n" + "Total relayed bytes\n" + "relayedbytes\n" + "0\n" + "0\n" + "Total number of streams with no relayed packets\n" + "zerowaystreams\n" + "0\n" + "0\n" + "Total number of 1-way streams\n" + "onewaystreams\n" + "0\n" + "0\n" + "Average call duration\n" + "avgcallduration\n" + "100.000000\n" + "100.000000\n" + "\n" + "\n" + "}\n" + "Graphite interval statistics (last reported values to graphite):\n" + "intervalstatistics\n" + "{\n" + "Total calls duration\n" + "totalcallsduration\n" + "0.000000\n" + "0.000000\n" + "\n" + "Min managed sessions\n" + "minmanagedsessions\n" + "0\n" + "0\n" + "Max managed sessions\n" + "maxmanagedsessions\n" + "2\n" + "2\n" + "Min/Max/Avg offer processing delay\n" + "0.000000/0.000000/0.000000 sec\n" + "minofferdelay\n" + "0.000000\n" + "maxofferdelay\n" + "0.000000\n" + "avgofferdelay\n" + "0.000000\n" + "Min/Max/Avg answer processing delay\n" + "0.000000/0.000000/0.000000 sec\n" + "minanswerdelay\n" + "0.000000\n" + "maxanswerdelay\n" + "0.000000\n" + "avganswerdelay\n" + "0.000000\n" + "Min/Max/Avg delete processing delay\n" + "0.000000/0.000000/0.000000 sec\n" + "mindeletedelay\n" + "0.000000\n" + "maxdeletedelay\n" + "0.000000\n" + "avgdeletedelay\n" + "0.000000\n" + "Min/Max/Avg offer requests per second\n" + "0/0/0 per sec\n" + "minofferrequestrate\n" + "0\n" + "maxofferrequestrate\n" + "0\n" + "avgofferrequestrate\n" + "0\n" + "Min/Max/Avg answer requests per second\n" + "0/0/0 per sec\n" + "minanswerrequestrate\n" + "0\n" + "maxanswerrequestrate\n" + "0\n" + "avganswerrequestrate\n" + "0\n" + "Min/Max/Avg delete requests per second\n" + "0/0/0 per sec\n" + "mindeleterequestrate\n" + "0\n" + "maxdeleterequestrate\n" + "0\n" + "avgdeleterequestrate\n" + "0\n" + "\n" + "\n" + "}\n" + "Control statistics:\n" + "controlstatistics\n" + "\n" + "{\n" + "proxies\n" + "[\n" + " Proxy | Ping | Offer | Answer | Delete | Query | List | StartRec | StopRec | StartFwd | StopFwd | BlkDTMF | UnblkDTMF | BlkMedia | UnblkMedia | PlayMedia | StopMedia | PlayDTMF | Stats | SlnMedia | UnslnMedia | Pub | SubReq | SubAns | Unsub \n" + "\n" + "]\n" + "totalpingcount\n" + "0\n" + "totaloffercount\n" + "0\n" + "totalanswercount\n" + "0\n" + "totaldeletecount\n" + "0\n" + "totalquerycount\n" + "0\n" + "totallistcount\n" + "0\n" + "totalstartreccount\n" + "0\n" + "totalstopreccount\n" + "0\n" + "totalstartfwdcount\n" + "0\n" + "totalstopfwdcount\n" + "0\n" + "totalblkdtmfcount\n" + "0\n" + "totalunblkdtmfcount\n" + "0\n" + "totalblkmediacount\n" + "0\n" + "totalunblkmediacount\n" + "0\n" + "totalplaymediacount\n" + "0\n" + "totalstopmediacount\n" + "0\n" + "totalplaydtmfcount\n" + "0\n" + "totalstatscount\n" + "0\n" + "totalslnmediacount\n" + "0\n" + "totalunslnmediacount\n" + "0\n" + "totalpubcount\n" + "0\n" + "totalsubreqcount\n" + "0\n" + "totalsubanscount\n" + "0\n" + "totalunsubcount\n" + "0\n" + "\n" + "}\n" + "interfaces\n" + "[\n" + "]\n" + "transcoders\n" + "\n" + "[\n" + "\n" + "]\n" + "}\n"); + + + // cleanup + + statistics_free(); + call_free(); + call_interfaces_free(); + control_ng_cleanup(); + dtls_cert_free(); + + return 0; +} + +int get_local_log_level(unsigned int u) { + return 7; +}