diff --git a/daemon/call_interfaces.c b/daemon/call_interfaces.c index 7368bc038..ae2149675 100644 --- a/daemon/call_interfaces.c +++ b/daemon/call_interfaces.c @@ -1236,8 +1236,7 @@ static enum load_limit_reasons call_offer_session_limit(void) { { /* foreign calls can't get rejected * total_rejected_sess applies only to "own" sessions */ - atomic64_inc(&rtpe_totalstats.total_rejected_sess); - atomic64_inc(&rtpe_totalstats_interval.total_rejected_sess); + RTPE_STATS_INC(rejected_sess); ilog(LOG_ERROR, "Parallel session limit reached (%i)",rtpe_config.max_sessions); ret = LOAD_LIMIT_MAX_SESSIONS; diff --git a/daemon/graphite.c b/daemon/graphite.c index d1629da81..d20da117a 100644 --- a/daemon/graphite.c +++ b/daemon/graphite.c @@ -109,15 +109,6 @@ GString *print_graphite_data(struct totalstats *sent_data) { struct totalstats *ts = sent_data; /* atomically copy values to stack and reset to zero */ - atomic64_local_copy_zero_struct(ts, &rtpe_totalstats_interval, total_timeout_sess); - atomic64_local_copy_zero_struct(ts, &rtpe_totalstats_interval, total_rejected_sess); - atomic64_local_copy_zero_struct(ts, &rtpe_totalstats_interval, total_silent_timeout_sess); - atomic64_local_copy_zero_struct(ts, &rtpe_totalstats_interval, total_final_timeout_sess); - atomic64_local_copy_zero_struct(ts, &rtpe_totalstats_interval, total_offer_timeout_sess); - atomic64_local_copy_zero_struct(ts, &rtpe_totalstats_interval, total_regular_term_sess); - atomic64_local_copy_zero_struct(ts, &rtpe_totalstats_interval, total_forced_term_sess); - atomic64_local_copy_zero_struct(ts, &rtpe_totalstats_interval, total_nopacket_relayed_sess); - atomic64_local_copy_zero_struct(ts, &rtpe_totalstats_interval, total_oneway_stream_sess); mutex_lock(&rtpe_totalstats_interval.total_average_lock); ts->total_average_call_dur = rtpe_totalstats_interval.total_average_call_dur; @@ -145,11 +136,11 @@ GString *print_graphite_data(struct totalstats *sent_data) { mutex_lock(&rtpe_totalstats_interval.managed_sess_lock); ts->managed_sess_max = rtpe_totalstats_interval.managed_sess_max; ts->managed_sess_min = rtpe_totalstats_interval.managed_sess_min; - ts->total_sessions = g_hash_table_size(rtpe_callhash); - ts->foreign_sessions = atomic64_get(&rtpe_stats_gauge.foreign_sessions); - ts->own_sessions = ts->total_sessions - ts->foreign_sessions; - rtpe_totalstats_interval.managed_sess_max = ts->own_sessions;; - rtpe_totalstats_interval.managed_sess_min = ts->own_sessions; + uint64_t total_sessions = g_hash_table_size(rtpe_callhash); + uint64_t foreign_sessions = atomic64_get(&rtpe_stats_gauge.foreign_sessions); + uint64_t own_sessions = total_sessions - foreign_sessions; + rtpe_totalstats_interval.managed_sess_max = own_sessions;; + rtpe_totalstats_interval.managed_sess_min = own_sessions; mutex_unlock(&rtpe_totalstats_interval.managed_sess_lock); rwlock_unlock_r(&rtpe_callhash_lock); @@ -183,27 +174,27 @@ GString *print_graphite_data(struct totalstats *sent_data) { GPF("call_dur %llu.%06llu",(unsigned long long)ts->total_calls_duration_interval.tv_sec,(unsigned long long)ts->total_calls_duration_interval.tv_usec); GPF("average_call_dur %llu.%06llu",(unsigned long long)ts->total_average_call_dur.tv_sec,(unsigned long long)ts->total_average_call_dur.tv_usec); - GPF("forced_term_sess "UINT64F, atomic64_get_na(&ts->total_forced_term_sess)); + GPF("forced_term_sess "UINT64F, atomic64_get_na(&rtpe_stats_graphite_interval.forced_term_sess)); GPF("managed_sess "UINT64F, ts->total_managed_sess); GPF("managed_sess_min "UINT64F, ts->managed_sess_min); GPF("managed_sess_max "UINT64F, ts->managed_sess_max); - GPF("current_sessions_total "UINT64F, ts->total_sessions); - GPF("current_sessions_own "UINT64F, ts->own_sessions); - GPF("current_sessions_foreign "UINT64F, ts->foreign_sessions); + GPF("current_sessions_total "UINT64F, total_sessions); + GPF("current_sessions_own "UINT64F, own_sessions); + GPF("current_sessions_foreign "UINT64F, foreign_sessions); GPF("current_transcoded_media "UINT64F, atomic64_get(&rtpe_stats_gauge.transcoded_media)); GPF("current_sessions_ipv4 "UINT64F, atomic64_get(&rtpe_stats_gauge.ipv4_sessions)); GPF("current_sessions_ipv6 "UINT64F, atomic64_get(&rtpe_stats_gauge.ipv6_sessions)); GPF("current_sessions_mixed "UINT64F, atomic64_get(&rtpe_stats_gauge.mixed_sessions)); - GPF("nopacket_relayed_sess "UINT64F, atomic64_get_na(&ts->total_nopacket_relayed_sess)); - GPF("oneway_stream_sess "UINT64F, atomic64_get_na(&ts->total_oneway_stream_sess)); - GPF("regular_term_sess "UINT64F, atomic64_get_na(&ts->total_regular_term_sess)); + GPF("nopacket_relayed_sess "UINT64F, atomic64_get_na(&rtpe_stats_graphite_interval.nopacket_relayed_sess)); + GPF("oneway_stream_sess "UINT64F, atomic64_get_na(&rtpe_stats_graphite_interval.oneway_stream_sess)); + GPF("regular_term_sess "UINT64F, atomic64_get_na(&rtpe_stats_graphite_interval.regular_term_sess)); GPF("relayed_errors "UINT64F, atomic64_get_na(&rtpe_stats_graphite_interval.errors)); GPF("relayed_packets "UINT64F, atomic64_get_na(&rtpe_stats_graphite_interval.packets)); - GPF("silent_timeout_sess "UINT64F, atomic64_get_na(&ts->total_silent_timeout_sess)); - GPF("final_timeout_sess "UINT64F, atomic64_get_na(&ts->total_final_timeout_sess)); - GPF("offer_timeout_sess "UINT64F, atomic64_get_na(&ts->total_offer_timeout_sess)); - GPF("timeout_sess "UINT64F, atomic64_get_na(&ts->total_timeout_sess)); - GPF("reject_sess "UINT64F, atomic64_get_na(&ts->total_rejected_sess)); + GPF("silent_timeout_sess "UINT64F, atomic64_get_na(&rtpe_stats_graphite_interval.silent_timeout_sess)); + GPF("final_timeout_sess "UINT64F, atomic64_get_na(&rtpe_stats_graphite_interval.final_timeout_sess)); + GPF("offer_timeout_sess "UINT64F, atomic64_get_na(&rtpe_stats_graphite_interval.offer_timeout_sess)); + GPF("timeout_sess "UINT64F, atomic64_get_na(&rtpe_stats_graphite_interval.timeout_sess)); + GPF("reject_sess "UINT64F, atomic64_get_na(&rtpe_stats_graphite_interval.rejected_sess)); GPF("offers_ps_min %llu",(unsigned long long)ts->offers_ps.ps_min); GPF("offers_ps_max %llu",(unsigned long long)ts->offers_ps.ps_max); diff --git a/daemon/statistics.c b/daemon/statistics.c index 904107a77..e0e6285f4 100644 --- a/daemon/statistics.c +++ b/daemon/statistics.c @@ -185,7 +185,7 @@ void statistics_update_foreignown_inc(struct call* c) { } else if (IS_FOREIGN_CALL(c)) { /* foreign call*/ atomic64_inc(&rtpe_stats_gauge.foreign_sessions); - atomic64_inc(&rtpe_totalstats.total_foreign_sessions); + RTPE_STATS_INC(foreign_sess); } } @@ -230,10 +230,8 @@ void statistics_update_oneway(struct call* c) { if (ps && ps2 && atomic64_get(&ps2->stats.packets)==0) { if (atomic64_get(&ps->stats.packets)!=0 && IS_OWN_CALL(c)){ - if (atomic64_get(&ps->stats.packets)!=0) { - atomic64_inc(&rtpe_totalstats.total_oneway_stream_sess); - atomic64_inc(&rtpe_totalstats_interval.total_oneway_stream_sess); - } + if (atomic64_get(&ps->stats.packets)!=0) + RTPE_STATS_INC(oneway_stream_sess); } else { total_nopacket_relayed_sess++; @@ -241,10 +239,8 @@ void statistics_update_oneway(struct call* c) { } } - if (IS_OWN_CALL(c)) { - atomic64_add(&rtpe_totalstats.total_nopacket_relayed_sess, total_nopacket_relayed_sess / 2); - atomic64_add(&rtpe_totalstats_interval.total_nopacket_relayed_sess, total_nopacket_relayed_sess / 2); - } + if (IS_OWN_CALL(c)) + RTPE_STATS_INC(nopacket_relayed_sess); if (c->monologues.head) { ml = c->monologues.head->data; @@ -252,22 +248,16 @@ void statistics_update_oneway(struct call* c) { timeval_subtract(&tim_result_duration, &rtpe_now, &ml->started); if (IS_OWN_CALL(c)) { - if (ml->term_reason==TIMEOUT) { - atomic64_inc(&rtpe_totalstats.total_timeout_sess); - atomic64_inc(&rtpe_totalstats_interval.total_timeout_sess); - } else if (ml->term_reason==SILENT_TIMEOUT) { - atomic64_inc(&rtpe_totalstats.total_silent_timeout_sess); - atomic64_inc(&rtpe_totalstats_interval.total_silent_timeout_sess); - } else if (ml->term_reason==OFFER_TIMEOUT) { - atomic64_inc(&rtpe_totalstats.total_offer_timeout_sess); - atomic64_inc(&rtpe_totalstats_interval.total_offer_timeout_sess); - } else if (ml->term_reason==REGULAR) { - atomic64_inc(&rtpe_totalstats.total_regular_term_sess); - atomic64_inc(&rtpe_totalstats_interval.total_regular_term_sess); - } else if (ml->term_reason==FORCED) { - atomic64_inc(&rtpe_totalstats.total_forced_term_sess); - atomic64_inc(&rtpe_totalstats_interval.total_forced_term_sess); - } + if (ml->term_reason==TIMEOUT) + RTPE_STATS_INC(timeout_sess); + else if (ml->term_reason==SILENT_TIMEOUT) + RTPE_STATS_INC(silent_timeout_sess); + else if (ml->term_reason==OFFER_TIMEOUT) + RTPE_STATS_INC(offer_timeout_sess); + else if (ml->term_reason==REGULAR) + RTPE_STATS_INC(regular_term_sess); + else if (ml->term_reason==FORCED) + RTPE_STATS_INC(forced_term_sess); timeval_totalstats_average_add(&rtpe_totalstats, &tim_result_duration); timeval_totalstats_average_add(&rtpe_totalstats_interval, &tim_result_duration); @@ -280,10 +270,8 @@ void statistics_update_oneway(struct call* c) { NULL, 0); } - if (ml->term_reason==FINAL_TIMEOUT) { - atomic64_inc(&rtpe_totalstats.total_final_timeout_sess); - atomic64_inc(&rtpe_totalstats_interval.total_final_timeout_sess); - } + if (ml->term_reason==FINAL_TIMEOUT) + RTPE_STATS_INC(final_timeout_sess); } } @@ -478,25 +466,25 @@ GQueue *statistics_gather_metrics(void) { METRIC("managedsessions", "Total managed sessions", UINT64F, UINT64F, num_sessions); PROM("sessions_total", "counter"); - METRIC("rejectedsessions", "Total rejected sessions", UINT64F, UINT64F, atomic64_get(&rtpe_totalstats.total_rejected_sess)); + METRIC("rejectedsessions", "Total rejected sessions", UINT64F, UINT64F, atomic64_get(&rtpe_stats_cumulative.rejected_sess)); PROM("closed_sessions_total", "counter"); PROMLAB("reason=\"rejected\""); - METRIC("timeoutsessions", "Total timed-out sessions via TIMEOUT", UINT64F, UINT64F, atomic64_get(&rtpe_totalstats.total_timeout_sess)); + METRIC("timeoutsessions", "Total timed-out sessions via TIMEOUT", UINT64F, UINT64F, atomic64_get(&rtpe_stats_cumulative.timeout_sess)); PROM("closed_sessions_total", "counter"); PROMLAB("reason=\"timeout\""); - METRIC("silenttimeoutsessions", "Total timed-out sessions via SILENT_TIMEOUT", UINT64F, UINT64F,atomic64_get(&rtpe_totalstats.total_silent_timeout_sess)); + METRIC("silenttimeoutsessions", "Total timed-out sessions via SILENT_TIMEOUT", UINT64F, UINT64F,atomic64_get(&rtpe_stats_cumulative.silent_timeout_sess)); PROM("closed_sessions_total", "counter"); PROMLAB("reason=\"silent_timeout\""); - METRIC("finaltimeoutsessions", "Total timed-out sessions via FINAL_TIMEOUT", UINT64F, UINT64F,atomic64_get(&rtpe_totalstats.total_final_timeout_sess)); + METRIC("finaltimeoutsessions", "Total timed-out sessions via FINAL_TIMEOUT", UINT64F, UINT64F,atomic64_get(&rtpe_stats_cumulative.final_timeout_sess)); PROM("closed_sessions_total", "counter"); PROMLAB("reason=\"final_timeout\""); - METRIC("offertimeoutsessions", "Total timed-out sessions via OFFER_TIMEOUT", UINT64F, UINT64F,atomic64_get(&rtpe_totalstats.total_offer_timeout_sess)); + METRIC("offertimeoutsessions", "Total timed-out sessions via OFFER_TIMEOUT", UINT64F, UINT64F,atomic64_get(&rtpe_stats_cumulative.offer_timeout_sess)); PROM("closed_sessions_total", "counter"); PROMLAB("reason=\"offer_timeout\""); - METRIC("regularterminatedsessions", "Total regular terminated sessions", UINT64F, UINT64F, atomic64_get(&rtpe_totalstats.total_regular_term_sess)); + METRIC("regularterminatedsessions", "Total regular terminated sessions", UINT64F, UINT64F, atomic64_get(&rtpe_stats_cumulative.regular_term_sess)); PROM("closed_sessions_total", "counter"); PROMLAB("reason=\"terminated\""); - METRIC("forcedterminatedsessions", "Total forced terminated sessions", UINT64F, UINT64F, atomic64_get(&rtpe_totalstats.total_forced_term_sess)); + METRIC("forcedterminatedsessions", "Total forced terminated sessions", UINT64F, UINT64F, atomic64_get(&rtpe_stats_cumulative.forced_term_sess)); PROM("closed_sessions_total", "counter"); PROMLAB("reason=\"force_terminated\""); @@ -507,9 +495,9 @@ GQueue *statistics_gather_metrics(void) { METRIC("relayedbytes", "Total relayed bytes", UINT64F, UINT64F, atomic64_get(&rtpe_stats_cumulative.bytes)); PROM("bytes_total", "counter"); - METRIC("zerowaystreams", "Total number of streams with no relayed packets", UINT64F, UINT64F, atomic64_get(&rtpe_totalstats.total_nopacket_relayed_sess)); + METRIC("zerowaystreams", "Total number of streams with no relayed packets", UINT64F, UINT64F, atomic64_get(&rtpe_stats_cumulative.nopacket_relayed_sess)); PROM("zero_packet_streams_total", "counter"); - METRIC("onewaystreams", "Total number of 1-way streams", UINT64F, UINT64F,atomic64_get(&rtpe_totalstats.total_oneway_stream_sess)); + METRIC("onewaystreams", "Total number of 1-way streams", UINT64F, UINT64F,atomic64_get(&rtpe_stats_cumulative.oneway_stream_sess)); PROM("one_way_sessions_total", "counter"); METRICva("avgcallduration", "Average call duration", "%ld.%06ld", "%ld.%06ld", avg.tv_sec, avg.tv_usec); diff --git a/include/counter_stats_fields.inc b/include/counter_stats_fields.inc index 3f77b150d..ad96363b3 100644 --- a/include/counter_stats_fields.inc +++ b/include/counter_stats_fields.inc @@ -4,3 +4,13 @@ F(errors) F(offers) F(answers) F(deletes) +F(timeout_sess) +F(foreign_sess) +F(rejected_sess) +F(silent_timeout_sess) +F(offer_timeout_sess) +F(final_timeout_sess) +F(regular_term_sess) +F(forced_term_sess) +F(nopacket_relayed_sess) +F(oneway_stream_sess) diff --git a/include/statistics.h b/include/statistics.h index 8d9a12df4..d1fda0da4 100644 --- a/include/statistics.h +++ b/include/statistics.h @@ -58,20 +58,6 @@ struct requests_ps { struct totalstats { time_t started; - atomic64 total_timeout_sess; - atomic64 total_foreign_sessions; - atomic64 total_rejected_sess; - atomic64 total_silent_timeout_sess; - atomic64 total_offer_timeout_sess; - atomic64 total_final_timeout_sess; - atomic64 total_regular_term_sess; - atomic64 total_forced_term_sess; - atomic64 total_nopacket_relayed_sess; - atomic64 total_oneway_stream_sess; - - uint64_t foreign_sessions; - uint64_t own_sessions; - uint64_t total_sessions; mutex_t total_average_lock; /* for these two below */ uint64_t total_managed_sess; diff --git a/t/test-stats.c b/t/test-stats.c index b500a58c4..739eedf95 100644 --- a/t/test-stats.c +++ b/t/test-stats.c @@ -1914,7 +1914,7 @@ int main(void) { "current_sessions_ipv4 0 200\n" "current_sessions_ipv6 0 200\n" "current_sessions_mixed 0 200\n" - "nopacket_relayed_sess 0 200\n" + "nopacket_relayed_sess 2 200\n" "oneway_stream_sess 0 200\n" "regular_term_sess 0 200\n" "relayed_errors 0 200\n" @@ -2035,8 +2035,8 @@ int main(void) { "0\n" "Total number of streams with no relayed packets\n" "zerowaystreams\n" - "0\n" - "0\n" + "2\n" + "2\n" "Total number of 1-way streams\n" "onewaystreams\n" "0\n"