MEDIUM: stats: Enable more accurate moving average calculation for stats

Enable more accurate generation of moving averages for partially
populated samples window.
This commit is contained in:
Marcin Deranek 2020-05-15 20:02:40 +02:00 committed by Willy Tarreau
parent 3c27ddabec
commit a8dbdf3c4b
2 changed files with 34 additions and 16 deletions

View File

@ -1610,6 +1610,8 @@ int stats_fill_sv_stats(struct proxy *px, struct server *sv, int flags,
struct buffer *out = get_trash_chunk();
enum srv_stats_state state;
char *fld_status;
long long srv_samples_counter;
unsigned int srv_samples_window = TIME_STATS_SAMPLES;
if (len < ST_F_TOTAL_FIELDS)
return 0;
@ -1809,10 +1811,14 @@ int stats_fill_sv_stats(struct proxy *px, struct server *sv, int flags,
stats[ST_F_SRV_ABRT] = mkf_u64(FN_COUNTER, sv->counters.srv_aborts);
stats[ST_F_LASTSESS] = mkf_s32(FN_AGE, srv_lastsession(sv));
stats[ST_F_QTIME] = mkf_u32(FN_AVG, swrate_avg(sv->counters.q_time, TIME_STATS_SAMPLES));
stats[ST_F_CTIME] = mkf_u32(FN_AVG, swrate_avg(sv->counters.c_time, TIME_STATS_SAMPLES));
stats[ST_F_RTIME] = mkf_u32(FN_AVG, swrate_avg(sv->counters.d_time, TIME_STATS_SAMPLES));
stats[ST_F_TTIME] = mkf_u32(FN_AVG, swrate_avg(sv->counters.t_time, TIME_STATS_SAMPLES));
srv_samples_counter = (px->mode == PR_MODE_HTTP) ? sv->counters.p.http.cum_req : sv->counters.cum_lbconn;
if (srv_samples_counter < TIME_STATS_SAMPLES && srv_samples_counter > 0)
srv_samples_window = srv_samples_counter;
stats[ST_F_QTIME] = mkf_u32(FN_AVG, swrate_avg(sv->counters.q_time, srv_samples_window));
stats[ST_F_CTIME] = mkf_u32(FN_AVG, swrate_avg(sv->counters.c_time, srv_samples_window));
stats[ST_F_RTIME] = mkf_u32(FN_AVG, swrate_avg(sv->counters.d_time, srv_samples_window));
stats[ST_F_TTIME] = mkf_u32(FN_AVG, swrate_avg(sv->counters.t_time, srv_samples_window));
stats[ST_F_QT_MAX] = mkf_u32(FN_MAX, sv->counters.qtime_max);
stats[ST_F_CT_MAX] = mkf_u32(FN_MAX, sv->counters.ctime_max);
@ -1870,6 +1876,9 @@ static int stats_dump_sv_stats(struct stream_interface *si, struct proxy *px, st
*/
int stats_fill_be_stats(struct proxy *px, int flags, struct field *stats, int len)
{
long long be_samples_counter;
unsigned int be_samples_window = TIME_STATS_SAMPLES;
if (len < ST_F_TOTAL_FIELDS)
return 0;
@ -1942,10 +1951,14 @@ int stats_fill_be_stats(struct proxy *px, int flags, struct field *stats, int le
stats[ST_F_COMP_RSP] = mkf_u64(FN_COUNTER, px->be_counters.p.http.comp_rsp);
stats[ST_F_LASTSESS] = mkf_s32(FN_AGE, be_lastsession(px));
stats[ST_F_QTIME] = mkf_u32(FN_AVG, swrate_avg(px->be_counters.q_time, TIME_STATS_SAMPLES));
stats[ST_F_CTIME] = mkf_u32(FN_AVG, swrate_avg(px->be_counters.c_time, TIME_STATS_SAMPLES));
stats[ST_F_RTIME] = mkf_u32(FN_AVG, swrate_avg(px->be_counters.d_time, TIME_STATS_SAMPLES));
stats[ST_F_TTIME] = mkf_u32(FN_AVG, swrate_avg(px->be_counters.t_time, TIME_STATS_SAMPLES));
be_samples_counter = (px->mode == PR_MODE_HTTP) ? px->be_counters.p.http.cum_req : px->be_counters.cum_lbconn;
if (be_samples_counter < TIME_STATS_SAMPLES && be_samples_counter > 0)
be_samples_window = be_samples_counter;
stats[ST_F_QTIME] = mkf_u32(FN_AVG, swrate_avg(px->be_counters.q_time, be_samples_window));
stats[ST_F_CTIME] = mkf_u32(FN_AVG, swrate_avg(px->be_counters.c_time, be_samples_window));
stats[ST_F_RTIME] = mkf_u32(FN_AVG, swrate_avg(px->be_counters.d_time, be_samples_window));
stats[ST_F_TTIME] = mkf_u32(FN_AVG, swrate_avg(px->be_counters.t_time, be_samples_window));
stats[ST_F_QT_MAX] = mkf_u32(FN_MAX, px->be_counters.qtime_max);
stats[ST_F_CT_MAX] = mkf_u32(FN_MAX, px->be_counters.ctime_max);

View File

@ -2441,6 +2441,7 @@ void stream_update_time_stats(struct stream *s)
int t_data;
int t_close;
struct server *srv;
unsigned int samples_window;
t_request = 0;
t_queue = s->logs.t_queue;
@ -2463,19 +2464,23 @@ void stream_update_time_stats(struct stream *s)
srv = objt_server(s->target);
if (srv) {
swrate_add(&srv->counters.q_time, TIME_STATS_SAMPLES, t_queue);
swrate_add(&srv->counters.c_time, TIME_STATS_SAMPLES, t_connect);
swrate_add(&srv->counters.d_time, TIME_STATS_SAMPLES, t_data);
swrate_add(&srv->counters.t_time, TIME_STATS_SAMPLES, t_close);
samples_window = (((s->be->mode == PR_MODE_HTTP) ?
srv->counters.p.http.cum_req : srv->counters.cum_lbconn) > TIME_STATS_SAMPLES) ? TIME_STATS_SAMPLES : 0;
swrate_add_dynamic(&srv->counters.q_time, samples_window, t_queue);
swrate_add_dynamic(&srv->counters.c_time, samples_window, t_connect);
swrate_add_dynamic(&srv->counters.d_time, samples_window, t_data);
swrate_add_dynamic(&srv->counters.t_time, samples_window, t_close);
HA_ATOMIC_UPDATE_MAX(&srv->counters.qtime_max, t_queue);
HA_ATOMIC_UPDATE_MAX(&srv->counters.ctime_max, t_connect);
HA_ATOMIC_UPDATE_MAX(&srv->counters.dtime_max, t_data);
HA_ATOMIC_UPDATE_MAX(&srv->counters.ttime_max, t_close);
}
swrate_add(&s->be->be_counters.q_time, TIME_STATS_SAMPLES, t_queue);
swrate_add(&s->be->be_counters.c_time, TIME_STATS_SAMPLES, t_connect);
swrate_add(&s->be->be_counters.d_time, TIME_STATS_SAMPLES, t_data);
swrate_add(&s->be->be_counters.t_time, TIME_STATS_SAMPLES, t_close);
samples_window = (((s->be->mode == PR_MODE_HTTP) ?
s->be->be_counters.p.http.cum_req : s->be->be_counters.cum_lbconn) > TIME_STATS_SAMPLES) ? TIME_STATS_SAMPLES : 0;
swrate_add_dynamic(&s->be->be_counters.q_time, samples_window, t_queue);
swrate_add_dynamic(&s->be->be_counters.c_time, samples_window, t_connect);
swrate_add_dynamic(&s->be->be_counters.d_time, samples_window, t_data);
swrate_add_dynamic(&s->be->be_counters.t_time, samples_window, t_close);
HA_ATOMIC_UPDATE_MAX(&s->be->be_counters.qtime_max, t_queue);
HA_ATOMIC_UPDATE_MAX(&s->be->be_counters.ctime_max, t_connect);
HA_ATOMIC_UPDATE_MAX(&s->be->be_counters.dtime_max, t_data);