From: Christopher Faulet Date: Tue, 24 Sep 2019 14:35:19 +0000 (+0200) Subject: BUG/MINOR: contrib/prometheus-exporter: Return the time averages in seconds X-Git-Tag: v2.1-dev2~13 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=af4bf14183ccfac8b06a009178e2ae32cea8de4e;p=thirdparty%2Fhaproxy.git BUG/MINOR: contrib/prometheus-exporter: Return the time averages in seconds The metrics QTIME, CTIME, RTIME and TTIME are now returned in seconds using a float representation instead of in milliseconds. So these metrics are now consistent with their announced type and respect Prometheus naming conventions. This patch fixes the issue #288. It may be backported to 2.0. If so, the previous patch, introducing the support for float fields in stats is mantatory and should be backported first. --- diff --git a/contrib/prometheus-exporter/service-prometheus.c b/contrib/prometheus-exporter/service-prometheus.c index b1bb1747ed..f6eb8d5a85 100644 --- a/contrib/prometheus-exporter/service-prometheus.c +++ b/contrib/prometheus-exporter/service-prometheus.c @@ -1079,6 +1079,7 @@ static int promex_metric_to_str(struct buffer *out, struct field *f, size_t max) case FF_U32: ret = chunk_appendf(out, "%u\n", f->u.u32); break; case FF_S64: ret = chunk_appendf(out, "%lld\n", (long long)f->u.s64); break; case FF_U64: ret = chunk_appendf(out, "%llu\n", (unsigned long long)f->u.u64); break; + case FF_FLT: ret = chunk_appendf(out, "%f\n", f->u.flt); break; case FF_STR: ret = chunk_strcat(out, "Nan\n"); break; default: ret = chunk_strcat(out, "Nan\n"); break; } @@ -1607,6 +1608,7 @@ static int promex_dump_back_metrics(struct appctx *appctx, struct htx *htx) size_t max = htx_get_max_blksz(htx, channel_htx_recv_max(chn, htx)); int ret = 1; uint32_t weight; + double secs; while (appctx->st2 && appctx->st2 < ST_F_TOTAL_FIELDS) { while (appctx->ctx.stats.px) { @@ -1657,16 +1659,20 @@ static int promex_dump_back_metrics(struct appctx *appctx, struct htx *htx) metric = mkf_u64(FN_COUNTER, px->be_counters.bytes_out); break; case ST_F_QTIME: - metric = mkf_u32(FN_AVG, swrate_avg(px->be_counters.q_time, TIME_STATS_SAMPLES)); + secs = (double)swrate_avg(px->be_counters.q_time, TIME_STATS_SAMPLES) / 1000.0; + metric = mkf_flt(FN_AVG, secs); break; case ST_F_CTIME: - metric = mkf_u32(FN_AVG, swrate_avg(px->be_counters.c_time, TIME_STATS_SAMPLES)); + secs = (double)swrate_avg(px->be_counters.c_time, TIME_STATS_SAMPLES) / 1000.0; + metric = mkf_flt(FN_AVG, secs); break; case ST_F_RTIME: - metric = mkf_u32(FN_AVG, swrate_avg(px->be_counters.d_time, TIME_STATS_SAMPLES)); + secs = (double)swrate_avg(px->be_counters.d_time, TIME_STATS_SAMPLES) / 1000.0; + metric = mkf_flt(FN_AVG, secs); break; case ST_F_TTIME: - metric = mkf_u32(FN_AVG, swrate_avg(px->be_counters.t_time, TIME_STATS_SAMPLES)); + secs = (double)swrate_avg(px->be_counters.t_time, TIME_STATS_SAMPLES) / 1000.0; + metric = mkf_flt(FN_AVG, secs); break; case ST_F_DREQ: metric = mkf_u64(FN_COUNTER, px->be_counters.denied_req); @@ -1828,6 +1834,7 @@ static int promex_dump_srv_metrics(struct appctx *appctx, struct htx *htx) size_t max = htx_get_max_blksz(htx, channel_htx_recv_max(chn, htx)); int ret = 1; uint32_t weight; + double secs; while (appctx->st2 && appctx->st2 < ST_F_TOTAL_FIELDS) { while (appctx->ctx.stats.px) { @@ -1878,16 +1885,20 @@ static int promex_dump_srv_metrics(struct appctx *appctx, struct htx *htx) metric = mkf_u64(FN_COUNTER, sv->counters.bytes_out); break; case ST_F_QTIME: - metric = mkf_u32(FN_AVG, swrate_avg(sv->counters.q_time, TIME_STATS_SAMPLES)); + secs = (double)swrate_avg(sv->counters.q_time, TIME_STATS_SAMPLES) / 1000.0; + metric = mkf_flt(FN_AVG, secs); break; case ST_F_CTIME: - metric = mkf_u32(FN_AVG, swrate_avg(sv->counters.c_time, TIME_STATS_SAMPLES)); + secs = (double)swrate_avg(sv->counters.c_time, TIME_STATS_SAMPLES) / 1000.0; + metric = mkf_flt(FN_AVG, secs); break; case ST_F_RTIME: - metric = mkf_u32(FN_AVG, swrate_avg(sv->counters.d_time, TIME_STATS_SAMPLES)); + secs = (double)swrate_avg(sv->counters.d_time, TIME_STATS_SAMPLES) / 1000.0; + metric = mkf_flt(FN_AVG, secs); break; case ST_F_TTIME: - metric = mkf_u32(FN_AVG, swrate_avg(sv->counters.t_time, TIME_STATS_SAMPLES)); + secs = (double)swrate_avg(sv->counters.t_time, TIME_STATS_SAMPLES) / 1000.0; + metric = mkf_flt(FN_AVG, secs); break; case ST_F_CONNECT: metric = mkf_u64(FN_COUNTER, sv->counters.connect);