diff --git a/daemon/call.c b/daemon/call.c index 3dd8402a7..b411d645e 100644 --- a/daemon/call.c +++ b/daemon/call.c @@ -63,11 +63,9 @@ struct xmlrpc_helper { }; -/* XXX rework these */ -struct global_stats_counter rtpe_statsps; -struct global_stats_counter rtpe_stats_cumulative; -struct global_stats_counter rtpe_stats; struct global_stats_gauge rtpe_stats_gauge; +struct global_stats_ax rtpe_stats; +struct global_stats_counter rtpe_stats_cumulative; rwlock_t rtpe_callhash_lock; GHashTable *rtpe_callhash; @@ -570,22 +568,22 @@ void call_timer(void *ptr) { call_timer_iterator(c, &hlp); ITERATE_CALL_LIST_NEXT_END(c); - atomic64_local_copy_zero_struct(&tmpstats, &rtpe_statsps, bytes); - atomic64_local_copy_zero_struct(&tmpstats, &rtpe_statsps, packets); - atomic64_local_copy_zero_struct(&tmpstats, &rtpe_statsps, errors); + atomic64_local_copy_zero_struct(&tmpstats, &rtpe_stats.ax, bytes); + atomic64_local_copy_zero_struct(&tmpstats, &rtpe_stats.ax, packets); + atomic64_local_copy_zero_struct(&tmpstats, &rtpe_stats.ax, errors); - atomic64_set(&rtpe_stats.bytes, atomic64_get_na(&tmpstats.bytes) / run_diff); - atomic64_set(&rtpe_stats.packets, atomic64_get_na(&tmpstats.packets) / run_diff); - atomic64_set(&rtpe_stats.errors, atomic64_get_na(&tmpstats.errors) / run_diff); + atomic64_set(&rtpe_stats.intv.bytes, atomic64_get_na(&tmpstats.bytes) / run_diff); + atomic64_set(&rtpe_stats.intv.packets, atomic64_get_na(&tmpstats.packets) / run_diff); + atomic64_set(&rtpe_stats.intv.errors, atomic64_get_na(&tmpstats.errors) / run_diff); /* update statistics regarding requests per second */ - offers = atomic64_get_set(&rtpe_statsps.offers, 0); + offers = atomic64_get_set(&rtpe_stats.ax.offers, 0); update_requests_per_second_stats(&rtpe_totalstats_interval.offers_ps, offers / run_diff); - answers = atomic64_get_set(&rtpe_statsps.answers, 0); + answers = atomic64_get_set(&rtpe_stats.ax.answers, 0); update_requests_per_second_stats(&rtpe_totalstats_interval.answers_ps, answers / run_diff); - deletes = atomic64_get_set(&rtpe_statsps.deletes, 0); + deletes = atomic64_get_set(&rtpe_stats.ax.deletes, 0); update_requests_per_second_stats(&rtpe_totalstats_interval.deletes_ps, deletes / run_diff); // stats derived while iterating calls diff --git a/daemon/call_interfaces.c b/daemon/call_interfaces.c index d3fc584da..7368bc038 100644 --- a/daemon/call_interfaces.c +++ b/daemon/call_interfaces.c @@ -456,7 +456,7 @@ void calls_status_tcp(struct streambuf_stream *s) { rwlock_lock_r(&rtpe_callhash_lock); streambuf_printf(s->outbuf, "proxy %u "UINT64F"/%i/%i\n", g_hash_table_size(rtpe_callhash), - atomic64_get(&rtpe_stats.bytes), 0, 0); + atomic64_get(&rtpe_stats.intv.bytes), 0, 0); rwlock_unlock_r(&rtpe_callhash_lock); ITERATE_CALL_LIST_START(CALL_ITERATOR_MAIN, c); @@ -1264,7 +1264,7 @@ static enum load_limit_reasons call_offer_session_limit(void) { } if (ret == LOAD_LIMIT_NONE && rtpe_config.bw_limit) { - uint64_t bw = atomic64_get(&rtpe_stats.bytes); + uint64_t bw = atomic64_get(&rtpe_stats.intv.bytes); if (bw >= rtpe_config.bw_limit) { ilog(LOG_WARN, "Bandwidth limit exceeded (%" PRIu64 " > %" PRIu64 ")", bw, rtpe_config.bw_limit); diff --git a/daemon/cli.c b/daemon/cli.c index 960e43c0b..5d1ef9bf3 100644 --- a/daemon/cli.c +++ b/daemon/cli.c @@ -407,11 +407,11 @@ static void cli_incoming_params_revert(str *instr, struct cli_writer *cw) { static void cli_incoming_list_counters(str *instr, struct cli_writer *cw) { cw->cw_printf(cw, "\nCurrent per-second counters:\n\n"); cw->cw_printf(cw, " Packets per second :%" PRIu64 "\n", - atomic64_get(&rtpe_stats.packets)); + atomic64_get(&rtpe_stats.intv.packets)); cw->cw_printf(cw, " Bytes per second :%" PRIu64 "\n", - atomic64_get(&rtpe_stats.bytes)); + atomic64_get(&rtpe_stats.intv.bytes)); cw->cw_printf(cw, " Errors per second :%" PRIu64 "\n", - atomic64_get(&rtpe_stats.errors)); + atomic64_get(&rtpe_stats.intv.errors)); } static void cli_incoming_list_totals(str *instr, struct cli_writer *cw) { diff --git a/daemon/control_ng.c b/daemon/control_ng.c index c21c252da..c5f55c6b4 100644 --- a/daemon/control_ng.c +++ b/daemon/control_ng.c @@ -350,15 +350,15 @@ int control_ng_process(str *buf, const endpoint_t *sin, char *addr, // XXX could generalise these, same as above switch (command) { case NGC_OFFER: - atomic64_inc(&rtpe_statsps.offers); + atomic64_inc(&rtpe_stats.ax.offers); timeval_update_request_time(&rtpe_totalstats_interval.offer, &cmd_process_time); break; case NGC_ANSWER: - atomic64_inc(&rtpe_statsps.answers); + atomic64_inc(&rtpe_stats.ax.answers); timeval_update_request_time(&rtpe_totalstats_interval.answer, &cmd_process_time); break; case NGC_DELETE: - atomic64_inc(&rtpe_statsps.deletes); + atomic64_inc(&rtpe_stats.ax.deletes); timeval_update_request_time(&rtpe_totalstats_interval.delete, &cmd_process_time); break; default: diff --git a/daemon/statistics.c b/daemon/statistics.c index 5109c7618..e84cb286e 100644 --- a/daemon/statistics.c +++ b/daemon/statistics.c @@ -475,9 +475,9 @@ GQueue *statistics_gather_metrics(void) { METRIC("transcodedmedia", "Transcoded media", UINT64F, UINT64F, atomic64_get(&rtpe_stats_gauge.transcoded_media)); PROM("transcoded_media", "gauge"); - METRIC("packetrate", "Packets per second", UINT64F, UINT64F, atomic64_get(&rtpe_stats.packets)); - METRIC("byterate", "Bytes per second", UINT64F, UINT64F, atomic64_get(&rtpe_stats.bytes)); - METRIC("errorrate", "Errors per second", UINT64F, UINT64F, atomic64_get(&rtpe_stats.errors)); + METRIC("packetrate", "Packets per second", UINT64F, UINT64F, atomic64_get(&rtpe_stats.intv.packets)); + 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)); mutex_lock(&rtpe_totalstats.total_average_lock); avg = rtpe_totalstats.total_average_call_dur; diff --git a/include/call.h b/include/call.h index 4abebf818..f645778ee 100644 --- a/include/call.h +++ b/include/call.h @@ -541,14 +541,13 @@ extern rwlock_t rtpe_callhash_lock; extern GHashTable *rtpe_callhash; extern struct call_iterator_list rtpe_call_iterators[NUM_CALL_ITERATORS]; -extern struct global_stats_counter rtpe_statsps; /* per second stats, running timer */ -extern struct global_stats_counter rtpe_stats_cumulative; // total, cumulative -extern struct global_stats_counter rtpe_stats; /* copied from statsps once a second */ extern struct global_stats_gauge rtpe_stats_gauge; +extern struct global_stats_ax rtpe_stats; +extern struct global_stats_counter rtpe_stats_cumulative; // total, cumulative #define RTPE_STATS_ADD(field, num) \ do { \ - atomic64_add(&rtpe_statsps.field, num); \ + atomic64_add(&rtpe_stats.ax.field, num); \ atomic64_add(&rtpe_stats_cumulative.field, num); \ } while (0) #define RTPE_STATS_INC(field) RTPE_STATS_ADD(field, 1) diff --git a/include/statistics.h b/include/statistics.h index 22077d08c..3854d5bd4 100644 --- a/include/statistics.h +++ b/include/statistics.h @@ -38,6 +38,11 @@ struct global_stats_counter { atomic64 deletes; }; +struct global_stats_ax { + struct global_stats_counter ax; // running accumulator + struct global_stats_counter intv; // last per-interval values +}; + struct request_time { mutex_t lock; diff --git a/t/test-stats.c b/t/test-stats.c index fdc0c5620..b500a58c4 100644 --- a/t/test-stats.c +++ b/t/test-stats.c @@ -367,11 +367,11 @@ int main(void) { "]\n" "}\n"); - atomic64_inc(&rtpe_statsps.offers); + atomic64_inc(&rtpe_stats.ax.offers); struct timeval diff = {2,500000}; timeval_update_request_time(&rtpe_totalstats_interval.offer, &diff); - atomic64_inc(&rtpe_statsps.offers); + atomic64_inc(&rtpe_stats.ax.offers); diff = (struct timeval) {3,200000}; timeval_update_request_time(&rtpe_totalstats_interval.offer, &diff); @@ -669,7 +669,7 @@ int main(void) { "]\n" "}\n"); - atomic64_inc(&rtpe_statsps.answers); + atomic64_inc(&rtpe_stats.ax.answers); diff = (struct timeval) {3,200000}; timeval_update_request_time(&rtpe_totalstats_interval.answer, &diff); @@ -970,17 +970,17 @@ int main(void) { // test cmd_ps_min/max/avg call_timer(NULL); - atomic64_add(&rtpe_statsps.offers, 100); + atomic64_add(&rtpe_stats.ax.offers, 100); rtpe_now.tv_sec += 2; - atomic64_add(&rtpe_statsps.offers, 20); + atomic64_add(&rtpe_stats.ax.offers, 20); call_timer(NULL); // timer run time interval increased rtpe_now.tv_sec += 5; - atomic64_add(&rtpe_statsps.offers, 200); + atomic64_add(&rtpe_stats.ax.offers, 200); call_timer(NULL); graph_str = print_graphite_data(&rtpe_totalstats_lastinterval);