Browse Source

TT#178352 generalise metrics gathering and printing

Keep a running lifetime total of all "gauge" type metrics. Also track
the square of the sums of all "gauge" type metrics in order to determine
the standard deviation.

Change-Id: I23f60774a6421636f1a913674c7d1b54a1c5f702
pull/1525/head
Richard Fuchs 4 years ago
parent
commit
6b5a8f5560
8 changed files with 32 additions and 23 deletions
  1. +1
    -0
      daemon/call.c
  2. +2
    -3
      daemon/ssrc.c
  3. +23
    -17
      daemon/statistics.c
  4. +2
    -0
      include/call.h
  5. +0
    -3
      include/counter_stats_fields.inc
  6. +1
    -0
      include/gauge_stats_fields.inc
  7. +2
    -0
      include/statistics.h
  8. +1
    -0
      t/test-payload-tracker.c

+ 1
- 0
daemon/call.c View File

@ -65,6 +65,7 @@ struct xmlrpc_helper {
struct global_stats_gauge rtpe_stats_gauge;
struct global_stats_gauge_min_max rtpe_stats_gauge_cumulative;
struct global_stats_gauge_min_max rtpe_stats_gauge_graphite_min_max;
struct global_stats_gauge_min_max rtpe_stats_gauge_graphite_min_max_interval;


+ 2
- 3
daemon/ssrc.c View File

@ -395,14 +395,13 @@ void ssrc_receiver_report(struct call_media *m, const struct ssrc_receiver_repor
.reported = *tv,
.packetloss = (unsigned int) rr->fraction_lost * 100 / 256,
};
other_e->packets_lost = rr->packets_lost;
mos_calc(ssb);
if (ssb->mos) {
ilog(LOG_DEBUG, "Calculated MOS from RR for %s%x%s is %.1f", FMT_M(rr->from),
(double) ssb->mos / 10.0);
RTPE_STATS_ADD(mos, ssb->mos);
RTPE_STATS_ADD(mos2, ssb->mos * ssb->mos);
RTPE_STATS_INC(mos_num);
RTPE_GAUGE_SET(mos, ssb->mos);
}
// got a new stats block, add it to reporting ssrc


+ 23
- 17
daemon/statistics.c View File

@ -523,25 +523,31 @@ GQueue *statistics_gather_metrics(void) {
HEADER(NULL, "");
HEADER("}", "");
uint64_t metric_num, metric_tot, metric2_tot;
double metric_mean, metric_variance;
#define STAT_GET_PRINT(stat_name, name, divisor) \
metric_num = atomic64_get(&rtpe_stats_gauge_cumulative.count.stat_name); \
metric_tot = atomic64_get(&rtpe_stats_gauge_cumulative.avg.stat_name); \
metric2_tot = atomic64_get(&rtpe_stats_gauge_cumulative.stddev.stat_name); \
metric_mean = metric_num ? (double) metric_tot / (double) metric_num : 0.0; \
metric_variance = metric_num \
? fabs((double) metric2_tot / (double) metric_num - metric_mean * metric_mean) \
: 0.0; \
METRIC(#stat_name "_total", "Sum of all " name " values sampled", "%.6f", "%.6f", \
(double) metric_tot / (divisor)); \
PROM(#stat_name "_total", "counter"); \
METRIC(#stat_name "2_total", "Sum of all " name " square values sampled", "%.6f", "%.6f", \
(double) metric2_tot / (divisor * divisor)); \
PROM(#stat_name "2_total", "counter"); \
METRIC(#stat_name "_samples_total", "Total number of " name " samples", UINT64F, UINT64F, metric_num); \
PROM(#stat_name "_samples_total", "counter"); \
METRIC(#stat_name "_average", "Average " name, "%.6f", "%.6f", metric_mean / 10.0); \
METRIC(#stat_name "_stddev", name " standard deviation", "%.6f", "%.6f", sqrt(metric_variance) / 10.0); \
HEADER("mos", "MOS statistics:");
HEADER("{", "");
uint64_t mos_num = atomic64_get(&rtpe_stats_cumulative.mos_num);
uint64_t mos_tot = atomic64_get(&rtpe_stats_cumulative.mos);
uint64_t mos2_tot = atomic64_get(&rtpe_stats_cumulative.mos2);
double mos_mean = mos_num ? (double) mos_tot / (double) mos_num : 0.0;
double mos_variance = mos_num
? fabs((double) mos2_tot / (double) mos_num - mos_mean * mos_mean)
: 0.0;
METRIC("mos_total", "Sum of all MOS values sampled", "%.6f", "%.6f",
(double) mos_tot / 10.0);
PROM("mos_total", "counter");
METRIC("mos2_total", "Sum of all MOS square values sampled", "%.6f", "%.6f",
(double) mos2_tot / 100.0);
PROM("mos2_total", "counter");
METRIC("mos_samples_total", "Total number of MOS samples", UINT64F, UINT64F, mos_num);
PROM("mos_samples_total", "counter");
METRIC("mos_average", "Average MOS", "%.6f", "%.6f", mos_mean / 10.0);
METRIC("mos_stddev", "MOS standard deviation", "%.6f", "%.6f", sqrt(mos_variance) / 10.0);
STAT_GET_PRINT(mos, "MOS", 10.0);
HEADER(NULL, "");
HEADER("}", "");


+ 2
- 0
include/call.h View File

@ -605,12 +605,14 @@ extern GHashTable *rtpe_callhash;
extern struct call_iterator_list rtpe_call_iterators[NUM_CALL_ITERATORS];
extern struct global_stats_gauge rtpe_stats_gauge;
extern struct global_stats_gauge_min_max rtpe_stats_gauge_cumulative; // lifetime min/max/average/sums
extern struct global_stats_gauge_min_max rtpe_stats_gauge_graphite_min_max;
extern struct global_stats_gauge_min_max rtpe_stats_gauge_graphite_min_max_interval;
#define RTPE_GAUGE_SET(field, num) \
do { \
atomic64_set(&rtpe_stats_gauge.field, num); \
RTPE_GAUGE_SET_MIN_MAX(field, rtpe_stats_gauge_cumulative, num); \
RTPE_GAUGE_SET_MIN_MAX(field, rtpe_stats_gauge_graphite_min_max, num); \
} while (0)
#define RTPE_GAUGE_ADD(field, num) \


+ 0
- 3
include/counter_stats_fields.inc View File

@ -19,6 +19,3 @@ F(oneway_stream_sess)
F(call_duration)
F(call_duration2)
F(total_calls_duration_intv)
F(mos)
F(mos2)
F(mos_num)

+ 1
- 0
include/gauge_stats_fields.inc View File

@ -8,3 +8,4 @@ FdA(ng_command_times, NGC_COUNT)
F(userspace_streams)
F(kernel_only_streams)
F(kernel_user_streams)
F(mos)

+ 2
- 0
include/statistics.h View File

@ -42,6 +42,7 @@ struct global_stats_gauge_min_max {
struct global_stats_gauge min;
struct global_stats_gauge max;
struct global_stats_gauge avg; // sum while accumulation is running
struct global_stats_gauge stddev; // sum^2 while accumulation is running
struct global_stats_gauge count;
};
@ -177,6 +178,7 @@ INLINE void stats_counters_min_max_reset(struct global_stats_min_max *mm, struct
atomic64_min(&min_max_struct.min.field, val); \
atomic64_max(&min_max_struct.max.field, val); \
atomic64_add(&min_max_struct.avg.field, val); \
atomic64_add(&min_max_struct.stddev.field, (val) * (val)); \
atomic64_inc(&min_max_struct.count.field); \
} while (0)


+ 1
- 0
t/test-payload-tracker.c View File

@ -7,6 +7,7 @@
struct rtpengine_config rtpe_config;
struct global_stats_gauge rtpe_stats_gauge;
struct global_stats_gauge_min_max rtpe_stats_gauge_cumulative;
struct global_stats_gauge_min_max rtpe_stats_gauge_graphite_min_max;
struct global_stats_gauge_min_max rtpe_stats_gauge_graphite_min_max_interval;
struct global_stats_ax rtpe_stats;


Loading…
Cancel
Save