Browse Source

TT#101150 obsolete more fields from struct totalstats

total_managed_sess, total_average_call_dur, total_average_lock,

managed_sess_max, managed_sess_min, managed_sess_lock

Change-Id: Ibe3f619ec6d2f21270fc81901dde55b5242b0daa
pull/1373/head
Richard Fuchs 4 years ago
parent
commit
2ae5cc79ba
6 changed files with 33 additions and 101 deletions
  1. +4
    -1
      daemon/call.c
  2. +15
    -28
      daemon/graphite.c
  3. +9
    -61
      daemon/statistics.c
  4. +2
    -0
      include/counter_stats_fields.inc
  5. +0
    -8
      include/statistics.h
  6. +3
    -3
      t/test-stats.c

+ 4
- 1
daemon/call.c View File

@ -3056,8 +3056,10 @@ void call_destroy(struct call *c) {
rwlock_lock_w(&rtpe_callhash_lock); rwlock_lock_w(&rtpe_callhash_lock);
ret = (g_hash_table_lookup(rtpe_callhash, &c->callid) == c); ret = (g_hash_table_lookup(rtpe_callhash, &c->callid) == c);
if (ret)
if (ret) {
g_hash_table_remove(rtpe_callhash, &c->callid); g_hash_table_remove(rtpe_callhash, &c->callid);
RTPE_GAUGE_DEC(total_sessions);
}
rwlock_unlock_w(&rtpe_callhash_lock); rwlock_unlock_w(&rtpe_callhash_lock);
// if call not found in callhash => previously deleted // if call not found in callhash => previously deleted
@ -3403,6 +3405,7 @@ restart:
goto restart; goto restart;
} }
g_hash_table_insert(rtpe_callhash, &c->callid, obj_get(c)); g_hash_table_insert(rtpe_callhash, &c->callid, obj_get(c));
RTPE_GAUGE_INC(total_sessions);
c->foreign_call = foreign ? 1 : 0; c->foreign_call = foreign ? 1 : 0;


+ 15
- 28
daemon/graphite.c View File

@ -83,13 +83,6 @@ GString *print_graphite_data(struct totalstats *sent_data) {
/* atomically copy values to stack and reset to zero */ /* atomically copy values to stack and reset to zero */
mutex_lock(&rtpe_totalstats_interval.total_average_lock);
ts->total_average_call_dur = rtpe_totalstats_interval.total_average_call_dur;
ts->total_managed_sess = rtpe_totalstats_interval.total_managed_sess;
ZERO(rtpe_totalstats_interval.total_average_call_dur);
ZERO(rtpe_totalstats_interval.total_managed_sess);
mutex_unlock(&rtpe_totalstats_interval.total_average_lock);
mutex_lock(&rtpe_totalstats_interval.total_calls_duration_lock); mutex_lock(&rtpe_totalstats_interval.total_calls_duration_lock);
ts->total_calls_duration_interval = rtpe_totalstats_interval.total_calls_duration_interval; ts->total_calls_duration_interval = rtpe_totalstats_interval.total_calls_duration_interval;
rtpe_totalstats_interval.total_calls_duration_interval.tv_sec = 0; rtpe_totalstats_interval.total_calls_duration_interval.tv_sec = 0;
@ -97,18 +90,6 @@ GString *print_graphite_data(struct totalstats *sent_data) {
//ZERO(rtpe_totalstats_interval.total_calls_duration_interval); //ZERO(rtpe_totalstats_interval.total_calls_duration_interval);
mutex_unlock(&rtpe_totalstats_interval.total_calls_duration_lock); mutex_unlock(&rtpe_totalstats_interval.total_calls_duration_lock);
rwlock_lock_r(&rtpe_callhash_lock);
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;
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);
GString *graph_str = g_string_new(""); GString *graph_str = g_string_new("");
#define GPF(fmt, ...) \ #define GPF(fmt, ...) \
@ -126,14 +107,20 @@ 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("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);
struct timeval avg_duration;
uint64_t managed_sess = atomic64_get_na(&rtpe_stats_graphite_interval.managed_sess);
if (managed_sess)
timeval_from_us(&avg_duration, atomic64_get_na(&rtpe_stats_graphite_interval.call_duration) / managed_sess);
else
avg_duration = (struct timeval) {0,0};
GPF("average_call_dur %llu.%06llu",(unsigned long long)avg_duration.tv_sec,(unsigned long long)avg_duration.tv_usec);
GPF("forced_term_sess "UINT64F, atomic64_get_na(&rtpe_stats_graphite_interval.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, total_sessions);
GPF("current_sessions_own "UINT64F, own_sessions);
GPF("current_sessions_foreign "UINT64F, foreign_sessions);
GPF("managed_sess "UINT64F, atomic64_get(&rtpe_stats.ax.managed_sess));
GPF("managed_sess_min "UINT64F, atomic64_get_na(&rtpe_stats_gauge_graphite_min_max_interval.min.total_sessions));
GPF("managed_sess_max "UINT64F, atomic64_get_na(&rtpe_stats_gauge_graphite_min_max_interval.max.total_sessions));
GPF("current_sessions_total "UINT64F, atomic64_get(&rtpe_stats_gauge.total_sessions));
GPF("current_sessions_own "UINT64F, atomic64_get(&rtpe_stats_gauge.total_sessions) - atomic64_get(&rtpe_stats_gauge.foreign_sessions));
GPF("current_sessions_foreign "UINT64F, atomic64_get(&rtpe_stats_gauge.foreign_sessions));
GPF("current_transcoded_media "UINT64F, atomic64_get(&rtpe_stats_gauge.transcoded_media)); 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_ipv4 "UINT64F, atomic64_get(&rtpe_stats_gauge.ipv4_sessions));
GPF("current_sessions_ipv6 "UINT64F, atomic64_get(&rtpe_stats_gauge.ipv6_sessions)); GPF("current_sessions_ipv6 "UINT64F, atomic64_get(&rtpe_stats_gauge.ipv6_sessions));
@ -195,8 +182,8 @@ GString *print_graphite_data(struct totalstats *sent_data) {
ilog(LOG_DEBUG, "min_sessions:%llu max_sessions:%llu, call_dur_per_interval:%llu.%06llu at time %llu\n", ilog(LOG_DEBUG, "min_sessions:%llu max_sessions:%llu, call_dur_per_interval:%llu.%06llu at time %llu\n",
(unsigned long long) ts->managed_sess_min,
(unsigned long long) ts->managed_sess_max,
(unsigned long long) atomic64_get_na(&rtpe_stats_gauge_graphite_min_max_interval.min.total_sessions),
(unsigned long long) atomic64_get_na(&rtpe_stats_gauge_graphite_min_max_interval.max.total_sessions),
(unsigned long long ) ts->total_calls_duration_interval.tv_sec, (unsigned long long ) ts->total_calls_duration_interval.tv_sec,
(unsigned long long ) ts->total_calls_duration_interval.tv_usec, (unsigned long long ) ts->total_calls_duration_interval.tv_usec,
(unsigned long long ) rtpe_now.tv_sec); (unsigned long long ) rtpe_now.tv_sec);


+ 9
- 61
daemon/statistics.c View File

@ -15,31 +15,6 @@ mutex_t rtpe_codec_stats_lock;
GHashTable *rtpe_codec_stats; GHashTable *rtpe_codec_stats;
static void timeval_totalstats_average_add(struct totalstats *s, const struct timeval *add) {
struct timeval dp, oa;
mutex_lock(&s->total_average_lock);
// new average = ((old average * old num sessions) + datapoint) / new num sessions
// ... but this will overflow when num sessions becomes very large
// timeval_multiply(&t, &s->total_average_call_dur, s->total_managed_sess);
// timeval_add(&t, &t, add);
// s->total_managed_sess++;
// timeval_divide(&s->total_average_call_dur, &t, s->total_managed_sess);
// alternative:
// new average = old average + (datapoint / new num sessions) - (old average / new num sessions)
s->total_managed_sess++;
timeval_divide(&dp, add, s->total_managed_sess);
timeval_divide(&oa, &s->total_average_call_dur, s->total_managed_sess);
timeval_add(&s->total_average_call_dur, &s->total_average_call_dur, &dp);
timeval_subtract(&s->total_average_call_dur, &s->total_average_call_dur, &oa);
mutex_unlock(&s->total_average_lock);
}
static void timeval_totalstats_call_duration_add(struct totalstats *s, static void timeval_totalstats_call_duration_add(struct totalstats *s,
struct timeval *call_start, struct timeval *call_stop, struct timeval *call_start, struct timeval *call_stop,
struct timeval *interval_start, int interval_dur_s) { struct timeval *interval_start, int interval_dur_s) {
@ -164,26 +139,10 @@ void statistics_update_foreignown_dec(struct call* c) {
if (IS_FOREIGN_CALL(c)) { if (IS_FOREIGN_CALL(c)) {
RTPE_GAUGE_DEC(foreign_sessions); RTPE_GAUGE_DEC(foreign_sessions);
} }
if(IS_OWN_CALL(c)) {
mutex_lock(&rtpe_totalstats_interval.managed_sess_lock);
rtpe_totalstats_interval.managed_sess_min = MIN(rtpe_totalstats_interval.managed_sess_min,
g_hash_table_size(rtpe_callhash) - atomic64_get(&rtpe_stats_gauge.foreign_sessions));
mutex_unlock(&rtpe_totalstats_interval.managed_sess_lock);
}
} }
void statistics_update_foreignown_inc(struct call* c) { void statistics_update_foreignown_inc(struct call* c) {
if (IS_OWN_CALL(c)) {
mutex_lock(&rtpe_totalstats_interval.managed_sess_lock);
rtpe_totalstats_interval.managed_sess_max = MAX(
rtpe_totalstats_interval.managed_sess_max,
g_hash_table_size(rtpe_callhash)
- atomic64_get(&rtpe_stats_gauge.foreign_sessions));
mutex_unlock(&rtpe_totalstats_interval.managed_sess_lock);
}
else if (IS_FOREIGN_CALL(c)) { /* foreign call*/
if (IS_FOREIGN_CALL(c)) { /* foreign call*/
RTPE_GAUGE_INC(foreign_sessions); RTPE_GAUGE_INC(foreign_sessions);
RTPE_STATS_INC(foreign_sess); RTPE_STATS_INC(foreign_sess);
} }
@ -259,8 +218,9 @@ void statistics_update_oneway(struct call* c) {
else if (ml->term_reason==FORCED) else if (ml->term_reason==FORCED)
RTPE_STATS_INC(forced_term_sess); 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);
RTPE_STATS_ADD(call_duration, timeval_us(&tim_result_duration));
RTPE_STATS_INC(managed_sess);
timeval_totalstats_call_duration_add( timeval_totalstats_call_duration_add(
&rtpe_totalstats_interval, &ml->started, &ml->terminated, &rtpe_totalstats_interval, &ml->started, &ml->terminated,
&rtpe_latest_graphite_interval_start, &rtpe_latest_graphite_interval_start,
@ -422,11 +382,6 @@ GQueue *statistics_gather_metrics(void) {
struct timeval avg, calls_dur_iv; struct timeval avg, calls_dur_iv;
uint64_t cur_sessions, num_sessions, min_sess_iv, max_sess_iv; uint64_t cur_sessions, num_sessions, min_sess_iv, max_sess_iv;
mutex_lock(&rtpe_totalstats.total_average_lock);
avg = rtpe_totalstats.total_average_call_dur;
num_sessions = rtpe_totalstats.total_managed_sess;
mutex_unlock(&rtpe_totalstats.total_average_lock);
HEADER("{", ""); HEADER("{", "");
HEADER("currentstatistics", "Statistics over currently running sessions:"); HEADER("currentstatistics", "Statistics over currently running sessions:");
HEADER("{", ""); HEADER("{", "");
@ -450,10 +405,9 @@ GQueue *statistics_gather_metrics(void) {
METRIC("byterate", "Bytes per second", UINT64F, UINT64F, atomic64_get(&rtpe_stats.intv.bytes)); METRIC("byterate", "Bytes per second", UINT64F, UINT64F, atomic64_get(&rtpe_stats.intv.bytes));
METRIC("errorrate", "Errors per second", UINT64F, UINT64F, atomic64_get(&rtpe_stats.intv.errors)); METRIC("errorrate", "Errors per second", UINT64F, UINT64F, atomic64_get(&rtpe_stats.intv.errors));
mutex_lock(&rtpe_totalstats.total_average_lock);
avg = rtpe_totalstats.total_average_call_dur;
num_sessions = rtpe_totalstats.total_managed_sess;
mutex_unlock(&rtpe_totalstats.total_average_lock);
num_sessions = atomic64_get(&rtpe_stats.ax.managed_sess);
long long avg_us = num_sessions ? atomic64_get(&rtpe_stats.ax.call_duration) / num_sessions : 0;
timeval_from_us(&avg, avg_us);
HEADER("}", ""); HEADER("}", "");
HEADER("totalstatistics", "Total statistics (does not include current running sessions):"); HEADER("totalstatistics", "Total statistics (does not include current running sessions):");
@ -501,8 +455,8 @@ GQueue *statistics_gather_metrics(void) {
mutex_lock(&rtpe_totalstats_lastinterval_lock); mutex_lock(&rtpe_totalstats_lastinterval_lock);
calls_dur_iv = rtpe_totalstats_lastinterval.total_calls_duration_interval; calls_dur_iv = rtpe_totalstats_lastinterval.total_calls_duration_interval;
min_sess_iv = rtpe_totalstats_lastinterval.managed_sess_min;
max_sess_iv = rtpe_totalstats_lastinterval.managed_sess_max;
min_sess_iv = atomic64_get(&rtpe_stats_gauge_graphite_min_max_interval.min.total_sessions);
max_sess_iv = atomic64_get(&rtpe_stats_gauge_graphite_min_max_interval.max.total_sessions);
mutex_unlock(&rtpe_totalstats_lastinterval_lock); mutex_unlock(&rtpe_totalstats_lastinterval_lock);
HEADER(NULL, ""); HEADER(NULL, "");
@ -726,9 +680,6 @@ void statistics_free_metrics(GQueue **q) {
} }
void statistics_free() { void statistics_free() {
mutex_destroy(&rtpe_totalstats.total_average_lock);
mutex_destroy(&rtpe_totalstats_interval.total_average_lock);
mutex_destroy(&rtpe_totalstats_interval.managed_sess_lock);
mutex_destroy(&rtpe_totalstats_interval.total_calls_duration_lock); mutex_destroy(&rtpe_totalstats_interval.total_calls_duration_lock);
mutex_destroy(&rtpe_totalstats_lastinterval_lock); mutex_destroy(&rtpe_totalstats_lastinterval_lock);
@ -745,9 +696,6 @@ static void codec_stats_free(void *p) {
} }
void statistics_init() { void statistics_init() {
mutex_init(&rtpe_totalstats.total_average_lock);
mutex_init(&rtpe_totalstats_interval.total_average_lock);
mutex_init(&rtpe_totalstats_interval.managed_sess_lock);
mutex_init(&rtpe_totalstats_interval.total_calls_duration_lock); mutex_init(&rtpe_totalstats_interval.total_calls_duration_lock);
time(&rtpe_totalstats.started); time(&rtpe_totalstats.started);


+ 2
- 0
include/counter_stats_fields.inc View File

@ -3,6 +3,7 @@ F(bytes)
F(errors) F(errors)
FA(ng_commands, NGC_COUNT) FA(ng_commands, NGC_COUNT)
F(timeout_sess) F(timeout_sess)
F(managed_sess)
F(foreign_sess) F(foreign_sess)
F(rejected_sess) F(rejected_sess)
F(silent_timeout_sess) F(silent_timeout_sess)
@ -12,3 +13,4 @@ F(regular_term_sess)
F(forced_term_sess) F(forced_term_sess)
F(nopacket_relayed_sess) F(nopacket_relayed_sess)
F(oneway_stream_sess) F(oneway_stream_sess)
F(call_duration)

+ 0
- 8
include/statistics.h View File

@ -65,14 +65,6 @@ struct global_stats_min_max {
struct totalstats { struct totalstats {
time_t started; time_t started;
mutex_t total_average_lock; /* for these two below */
uint64_t total_managed_sess;
struct timeval total_average_call_dur;
mutex_t managed_sess_lock; /* for these below */
uint64_t managed_sess_max; /* per graphite interval statistic */
uint64_t managed_sess_min; /* per graphite interval statistic */
mutex_t total_calls_duration_lock; /* for these two below */ mutex_t total_calls_duration_lock; /* for these two below */
struct timeval total_calls_duration_interval; struct timeval total_calls_duration_interval;
}; };


+ 3
- 3
t/test-stats.c View File

@ -3211,7 +3211,7 @@ int main(void) {
"average_call_dur 0.000000 157\n" "average_call_dur 0.000000 157\n"
"forced_term_sess 0 157\n" "forced_term_sess 0 157\n"
"managed_sess 0 157\n" "managed_sess 0 157\n"
"managed_sess_min 0 157\n"
"managed_sess_min 1 157\n"
"managed_sess_max 2 157\n" "managed_sess_max 2 157\n"
"current_sessions_total 2 157\n" "current_sessions_total 2 157\n"
"current_sessions_own 2 157\n" "current_sessions_own 2 157\n"
@ -3427,8 +3427,8 @@ int main(void) {
"\n" "\n"
"Min managed sessions\n" "Min managed sessions\n"
"minmanagedsessions\n" "minmanagedsessions\n"
"0\n"
"0\n"
"1\n"
"1\n"
"Max managed sessions\n" "Max managed sessions\n"
"maxmanagedsessions\n" "maxmanagedsessions\n"
"2\n" "2\n"


Loading…
Cancel
Save