mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-09-24 23:31:40 +02:00
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:
parent
3c27ddabec
commit
a8dbdf3c4b
29
src/stats.c
29
src/stats.c
@ -1610,6 +1610,8 @@ int stats_fill_sv_stats(struct proxy *px, struct server *sv, int flags,
|
|||||||
struct buffer *out = get_trash_chunk();
|
struct buffer *out = get_trash_chunk();
|
||||||
enum srv_stats_state state;
|
enum srv_stats_state state;
|
||||||
char *fld_status;
|
char *fld_status;
|
||||||
|
long long srv_samples_counter;
|
||||||
|
unsigned int srv_samples_window = TIME_STATS_SAMPLES;
|
||||||
|
|
||||||
if (len < ST_F_TOTAL_FIELDS)
|
if (len < ST_F_TOTAL_FIELDS)
|
||||||
return 0;
|
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_SRV_ABRT] = mkf_u64(FN_COUNTER, sv->counters.srv_aborts);
|
||||||
stats[ST_F_LASTSESS] = mkf_s32(FN_AGE, srv_lastsession(sv));
|
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));
|
srv_samples_counter = (px->mode == PR_MODE_HTTP) ? sv->counters.p.http.cum_req : sv->counters.cum_lbconn;
|
||||||
stats[ST_F_CTIME] = mkf_u32(FN_AVG, swrate_avg(sv->counters.c_time, TIME_STATS_SAMPLES));
|
if (srv_samples_counter < TIME_STATS_SAMPLES && srv_samples_counter > 0)
|
||||||
stats[ST_F_RTIME] = mkf_u32(FN_AVG, swrate_avg(sv->counters.d_time, TIME_STATS_SAMPLES));
|
srv_samples_window = srv_samples_counter;
|
||||||
stats[ST_F_TTIME] = mkf_u32(FN_AVG, swrate_avg(sv->counters.t_time, TIME_STATS_SAMPLES));
|
|
||||||
|
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_QT_MAX] = mkf_u32(FN_MAX, sv->counters.qtime_max);
|
||||||
stats[ST_F_CT_MAX] = mkf_u32(FN_MAX, sv->counters.ctime_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)
|
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)
|
if (len < ST_F_TOTAL_FIELDS)
|
||||||
return 0;
|
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_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_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));
|
be_samples_counter = (px->mode == PR_MODE_HTTP) ? px->be_counters.p.http.cum_req : px->be_counters.cum_lbconn;
|
||||||
stats[ST_F_CTIME] = mkf_u32(FN_AVG, swrate_avg(px->be_counters.c_time, TIME_STATS_SAMPLES));
|
if (be_samples_counter < TIME_STATS_SAMPLES && be_samples_counter > 0)
|
||||||
stats[ST_F_RTIME] = mkf_u32(FN_AVG, swrate_avg(px->be_counters.d_time, TIME_STATS_SAMPLES));
|
be_samples_window = be_samples_counter;
|
||||||
stats[ST_F_TTIME] = mkf_u32(FN_AVG, swrate_avg(px->be_counters.t_time, TIME_STATS_SAMPLES));
|
|
||||||
|
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_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);
|
stats[ST_F_CT_MAX] = mkf_u32(FN_MAX, px->be_counters.ctime_max);
|
||||||
|
21
src/stream.c
21
src/stream.c
@ -2441,6 +2441,7 @@ void stream_update_time_stats(struct stream *s)
|
|||||||
int t_data;
|
int t_data;
|
||||||
int t_close;
|
int t_close;
|
||||||
struct server *srv;
|
struct server *srv;
|
||||||
|
unsigned int samples_window;
|
||||||
|
|
||||||
t_request = 0;
|
t_request = 0;
|
||||||
t_queue = s->logs.t_queue;
|
t_queue = s->logs.t_queue;
|
||||||
@ -2463,19 +2464,23 @@ void stream_update_time_stats(struct stream *s)
|
|||||||
|
|
||||||
srv = objt_server(s->target);
|
srv = objt_server(s->target);
|
||||||
if (srv) {
|
if (srv) {
|
||||||
swrate_add(&srv->counters.q_time, TIME_STATS_SAMPLES, t_queue);
|
samples_window = (((s->be->mode == PR_MODE_HTTP) ?
|
||||||
swrate_add(&srv->counters.c_time, TIME_STATS_SAMPLES, t_connect);
|
srv->counters.p.http.cum_req : srv->counters.cum_lbconn) > TIME_STATS_SAMPLES) ? TIME_STATS_SAMPLES : 0;
|
||||||
swrate_add(&srv->counters.d_time, TIME_STATS_SAMPLES, t_data);
|
swrate_add_dynamic(&srv->counters.q_time, samples_window, t_queue);
|
||||||
swrate_add(&srv->counters.t_time, TIME_STATS_SAMPLES, t_close);
|
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.qtime_max, t_queue);
|
||||||
HA_ATOMIC_UPDATE_MAX(&srv->counters.ctime_max, t_connect);
|
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.dtime_max, t_data);
|
||||||
HA_ATOMIC_UPDATE_MAX(&srv->counters.ttime_max, t_close);
|
HA_ATOMIC_UPDATE_MAX(&srv->counters.ttime_max, t_close);
|
||||||
}
|
}
|
||||||
swrate_add(&s->be->be_counters.q_time, TIME_STATS_SAMPLES, t_queue);
|
samples_window = (((s->be->mode == PR_MODE_HTTP) ?
|
||||||
swrate_add(&s->be->be_counters.c_time, TIME_STATS_SAMPLES, t_connect);
|
s->be->be_counters.p.http.cum_req : s->be->be_counters.cum_lbconn) > TIME_STATS_SAMPLES) ? TIME_STATS_SAMPLES : 0;
|
||||||
swrate_add(&s->be->be_counters.d_time, TIME_STATS_SAMPLES, t_data);
|
swrate_add_dynamic(&s->be->be_counters.q_time, samples_window, t_queue);
|
||||||
swrate_add(&s->be->be_counters.t_time, TIME_STATS_SAMPLES, t_close);
|
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.qtime_max, t_queue);
|
||||||
HA_ATOMIC_UPDATE_MAX(&s->be->be_counters.ctime_max, t_connect);
|
HA_ATOMIC_UPDATE_MAX(&s->be->be_counters.ctime_max, t_connect);
|
||||||
HA_ATOMIC_UPDATE_MAX(&s->be->be_counters.dtime_max, t_data);
|
HA_ATOMIC_UPDATE_MAX(&s->be->be_counters.dtime_max, t_data);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user