From 10ab56831e725acb4fe211efaf87f5185551d6cf Mon Sep 17 00:00:00 2001 From: Amaury Denoyelle Date: Tue, 30 Apr 2024 17:10:16 +0200 Subject: [PATCH] MINOR: stats: convert age as generic column for proxy stat Convert FN_AGE in stat_cols_px[] as generic columns. These values will be automatically used for dump/preload of a stats-file. Remove srv_lastsession() / be_lastsession() function which are now useless as last_sess is calculated via me_generate_field(). --- include/haproxy/backend.h | 1 - include/haproxy/server.h | 1 - src/backend.c | 8 -------- src/server.c | 8 -------- src/stats.c | 24 ++++++++++-------------- 5 files changed, 10 insertions(+), 32 deletions(-) diff --git a/include/haproxy/backend.h b/include/haproxy/backend.h index a2015dc81..93a4bee2b 100644 --- a/include/haproxy/backend.h +++ b/include/haproxy/backend.h @@ -59,7 +59,6 @@ int tcp_persist_rdp_cookie(struct stream *s, struct channel *req, int an_bit); int be_downtime(struct proxy *px); void recount_servers(struct proxy *px); void update_backend_weight(struct proxy *px); -int be_lastsession(const struct proxy *be); /* Returns number of usable servers in backend */ static inline int be_usable_srv(struct proxy *be) diff --git a/include/haproxy/server.h b/include/haproxy/server.h index 4d27e769f..8d58e74c4 100644 --- a/include/haproxy/server.h +++ b/include/haproxy/server.h @@ -43,7 +43,6 @@ extern struct list servers_list; extern struct dict server_key_dict; int srv_downtime(const struct server *s); -int srv_lastsession(const struct server *s); int srv_getinter(const struct check *check); void srv_settings_init(struct server *srv); void srv_settings_cpy(struct server *srv, const struct server *src, int srv_tmpl); diff --git a/src/backend.c b/src/backend.c index 7779eb1b4..bd6f80e39 100644 --- a/src/backend.c +++ b/src/backend.c @@ -62,14 +62,6 @@ #define TRACE_SOURCE &trace_strm -int be_lastsession(const struct proxy *be) -{ - if (be->be_counters.last_sess) - return ns_to_sec(now_ns) - be->be_counters.last_sess; - - return -1; -} - /* helper function to invoke the correct hash method */ unsigned int gen_hash(const struct proxy* px, const char* key, unsigned long len) { diff --git a/src/server.c b/src/server.c index 878bddfd7..b9036d319 100644 --- a/src/server.c +++ b/src/server.c @@ -147,14 +147,6 @@ int srv_downtime(const struct server *s) return ns_to_sec(now_ns) - s->counters.last_change + s->down_time; } -int srv_lastsession(const struct server *s) -{ - if (s->counters.last_sess) - return ns_to_sec(now_ns) - s->counters.last_sess; - - return -1; -} - int srv_getinter(const struct check *check) { const struct server *s = check->server; diff --git a/src/stats.c b/src/stats.c index 57b386b66..1f296b562 100644 --- a/src/stats.c +++ b/src/stats.c @@ -222,7 +222,7 @@ const struct stat_col stat_cols_px[ST_I_PX_MAX] = { [ST_I_PX_BCK] = { .name = "bck", .desc = "Total number of backup UP servers with a non-zero weight" }, [ST_I_PX_CHKFAIL] = ME_NEW_BE("chkfail", FN_COUNTER, FF_U64, failed_checks, STATS_PX_CAP____S, "Total number of failed individual health checks per server/backend, since the worker process started"), [ST_I_PX_CHKDOWN] = ME_NEW_BE("chkdown", FN_COUNTER, FF_U64, down_trans, STATS_PX_CAP___BS, "Total number of failed checks causing UP to DOWN server transitions, per server/backend, since the worker process started"), - [ST_I_PX_LASTCHG] = { .name = "lastchg", .desc = "How long ago the last server state changed, in seconds" }, + [ST_I_PX_LASTCHG] = ME_NEW_BE("lastchg", FN_AGE, FF_U32, last_change, STATS_PX_CAP___BS, "How long ago the last server state changed, in seconds"), [ST_I_PX_DOWNTIME] = { .name = "downtime", .desc = "Total time spent in DOWN state, for server or backend" }, [ST_I_PX_QLIMIT] = { .name = "qlimit", .desc = "Limit on the number of connections in queue, for servers only (maxqueue argument)" }, [ST_I_PX_PID] = { .name = "pid", .desc = "Relative worker process number (1)" }, @@ -255,7 +255,7 @@ const struct stat_col stat_cols_px[ST_I_PX_MAX] = { [ST_I_PX_COMP_OUT] = ME_NEW_PX("comp_out", FN_COUNTER, FF_U64, comp_out[COMP_DIR_RES], STATS_PX_CAP__FB_, "Total number of bytes emitted by the HTTP compressor for this object since the worker process started"), [ST_I_PX_COMP_BYP] = ME_NEW_PX("comp_byp", FN_COUNTER, FF_U64, comp_byp[COMP_DIR_RES], STATS_PX_CAP__FB_, "Total number of bytes that bypassed HTTP compression for this object since the worker process started (CPU/memory/bandwidth limitation)"), [ST_I_PX_COMP_RSP] = ME_NEW_PX("comp_rsp", FN_COUNTER, FF_U64, p.http.comp_rsp, STATS_PX_CAP__FB_, "Total number of HTTP responses that were compressed for this object since the worker process started"), - [ST_I_PX_LASTSESS] = { .name = "lastsess", .desc = "How long ago some traffic was seen on this object on this worker process, in seconds" }, + [ST_I_PX_LASTSESS] = ME_NEW_BE("lastsess", FN_AGE, FF_S32, last_sess, STATS_PX_CAP___BS, "How long ago some traffic was seen on this object on this worker process, in seconds"), [ST_I_PX_LAST_CHK] = { .name = "last_chk", .desc = "Short description of the latest health check report for this server (see also check_desc)" }, [ST_I_PX_LAST_AGT] = { .name = "last_agt", .desc = "Short description of the latest agent check report for this server (see also agent_desc)" }, [ST_I_PX_QTIME] = { .name = "qtime", .desc = "Time spent in the queue, in milliseconds, averaged over the 1024 last requests (backend/server)" }, @@ -717,6 +717,14 @@ static int stcol_hide(enum stat_idx_px idx, enum obj_type *objt) ref = ref->track; return !ref->observe; + case ST_I_PX_LASTSESS: + if (srv) + return !srv->counters.last_sess; + else if (px) + return !px->be_counters.last_sess; + else + return 0; + default: return 0; } @@ -1335,9 +1343,6 @@ int stats_fill_sv_line(struct proxy *px, struct server *sv, int flags, field = mkf_str(FO_STATUS, fld_status); break; - case ST_I_PX_LASTCHG: - field = mkf_u32(FN_AGE, ns_to_sec(now_ns) - sv->counters.last_change); - break; case ST_I_PX_WEIGHT: field = mkf_u32(FN_AVG, (sv->cur_eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv); break; @@ -1470,9 +1475,6 @@ int stats_fill_sv_line(struct proxy *px, struct server *sv, int flags, if ((sv->agent.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) field = mkf_u32(FO_CONFIG|FS_SERVICE, sv->agent.health); break; - case ST_I_PX_LASTSESS: - field = mkf_s32(FN_AGE, srv_lastsession(sv)); - break; case ST_I_PX_QTIME: field = mkf_u32(FN_AVG, swrate_avg(sv->counters.q_time, srv_samples_window)); break; @@ -1708,9 +1710,6 @@ int stats_fill_be_line(struct proxy *px, int flags, struct field *line, int len, case ST_I_PX_BCK: field = mkf_u32(0, px->srv_bck); break; - case ST_I_PX_LASTCHG: - field = mkf_u32(FN_AGE, ns_to_sec(now_ns) - px->be_counters.last_change); - break; case ST_I_PX_DOWNTIME: if (px->srv) field = mkf_u32(FN_COUNTER, be_downtime(px)); @@ -1738,9 +1737,6 @@ int stats_fill_be_line(struct proxy *px, int flags, struct field *line, int len, if (flags & STAT_F_SHLGNDS) field = mkf_str(FO_CONFIG|FS_SERVICE, backend_lb_algo_str(px->lbprm.algo & BE_LB_ALGO)); break; - case ST_I_PX_LASTSESS: - field = mkf_s32(FN_AGE, be_lastsession(px)); - break; case ST_I_PX_QTIME: field = mkf_u32(FN_AVG, swrate_avg(px->be_counters.q_time, be_samples_window)); break;