diff --git a/daemon/call.c b/daemon/call.c index bd3e28d4a..cfda650c9 100644 --- a/daemon/call.c +++ b/daemon/call.c @@ -66,6 +66,8 @@ struct xmlrpc_helper { struct global_stats_gauge rtpe_stats_gauge; struct global_stats_ax rtpe_stats; struct global_stats_counter rtpe_stats_cumulative; +struct global_stats_ax rtpe_stats_graphite; +struct global_stats_counter rtpe_stats_graphite_interval; rwlock_t rtpe_callhash_lock; GHashTable *rtpe_callhash; diff --git a/daemon/graphite.c b/daemon/graphite.c index 64ca81ad7..65e749270 100644 --- a/daemon/graphite.c +++ b/daemon/graphite.c @@ -102,6 +102,10 @@ static int connect_to_graphite_server(const endpoint_t *graphite_ep) { } GString *print_graphite_data(struct totalstats *sent_data) { + + long long time_diff_us = timeval_diff(&rtpe_now, &rtpe_latest_graphite_interval_start); + stats_counters_ax_calc_avg(&rtpe_stats_graphite, time_diff_us, &rtpe_stats_graphite_interval); + struct totalstats *ts = sent_data; /* atomically copy values to stack and reset to zero */ @@ -381,8 +385,9 @@ static void graphite_loop_run(endpoint_t *graphite_ep, int seconds) { if (graphite_sock.fd >= 0 && connection_state == STATE_CONNECTED) { add_total_calls_duration_in_interval(&graphite_interval_tv); + gettimeofday(&rtpe_now, NULL); rc = send_graphite_data(&graphite_stats); - gettimeofday(&rtpe_latest_graphite_interval_start, NULL); + rtpe_latest_graphite_interval_start = rtpe_now; if (rc < 0) { ilog(LOG_ERROR,"Sending graphite data failed."); close_socket(&graphite_sock); diff --git a/include/call.h b/include/call.h index f645778ee..a8f8544ec 100644 --- a/include/call.h +++ b/include/call.h @@ -544,11 +544,14 @@ extern struct call_iterator_list rtpe_call_iterators[NUM_CALL_ITERATORS]; 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 +extern struct global_stats_ax rtpe_stats_graphite; +extern struct global_stats_counter rtpe_stats_graphite_interval; // copied out when graphite stats run #define RTPE_STATS_ADD(field, num) \ do { \ atomic64_add(&rtpe_stats.ax.field, num); \ atomic64_add(&rtpe_stats_cumulative.field, num); \ + atomic64_add(&rtpe_stats_graphite.ax.field, num); \ } while (0) #define RTPE_STATS_INC(field) RTPE_STATS_ADD(field, 1)