diff --git a/include/haproxy/freq_ctr.h b/include/haproxy/freq_ctr.h index f3f690390..f037cbbad 100644 --- a/include/haproxy/freq_ctr.h +++ b/include/haproxy/freq_ctr.h @@ -32,6 +32,14 @@ ullong freq_ctr_total(const struct freq_ctr *ctr, uint period, int pend); int freq_ctr_overshoot_period(const struct freq_ctr *ctr, uint period, uint freq); uint update_freq_ctr_period_slow(struct freq_ctr *ctr, uint period, uint inc); +/* Only usable during single threaded startup phase. */ +static inline void preload_freq_ctr(struct freq_ctr *ctr, uint value) +{ + ctr->curr_ctr = 0; + ctr->prev_ctr = value; + ctr->curr_tick = now_ms & ~1; +} + /* Update a frequency counter by incremental units. It is automatically * rotated if the period is over. It is important that it correctly initializes * a null area. diff --git a/src/stats-file.c b/src/stats-file.c index 828c0a1bf..4f07ddc90 100644 --- a/src/stats-file.c +++ b/src/stats-file.c @@ -211,6 +211,10 @@ static int load_ctr(const struct stat_col *col, const struct ist token, value.u.u64 = read_uint64(&ptr, istend(token)); break; + case FF_U32: + value.u.u32 = read_uint(&ptr, istend(token)); + break; + default: /* Unsupported field nature. */ return 1; @@ -223,6 +227,9 @@ static int load_ctr(const struct stat_col *col, const struct ist token, if (fn == FN_COUNTER && ff == FF_U64) { *(uint64_t *)counter = value.u.u64; } + else if (fn == FN_RATE && ff == FF_U32) { + preload_freq_ctr(counter, value.u.u32); + } else { /* Unsupported field format/nature combination. */ return 1; diff --git a/src/stats.c b/src/stats.c index 65b701fdb..0a26a01ec 100644 --- a/src/stats.c +++ b/src/stats.c @@ -801,6 +801,11 @@ static struct field me_generate_field(const struct stat_col *col, ABORT_NOW(); } } + else if (fn == FN_RATE) { + /* freq-ctr always uses FF_U32 */ + BUG_ON(stcol_format(col) != FF_U32); + value = mkf_u32(FN_RATE, read_freq_ctr(counter)); + } else { /* No generic column available for other field nature. */ ABORT_NOW();