]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: stats: convert age as generic column for proxy stat
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Tue, 30 Apr 2024 15:10:16 +0000 (17:10 +0200)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Thu, 2 May 2024 08:55:25 +0000 (10:55 +0200)
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
include/haproxy/server.h
src/backend.c
src/server.c
src/stats.c

index a2015dc8116634893f2a62fbd3e9a0046c43b2b0..93a4bee2b53190f336eec19bc53b70dd9eaa53d0 100644 (file)
@@ -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)
index 4d27e769ffb4af0ff236ef3e6b2fb7e8e23ca840..8d58e74c4581230f2efd3fea493ebc10b7eaf40e 100644 (file)
@@ -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);
index 7779eb1b43c04a244e511740ba9076352b3380ff..bd6f80e39636e93c0f1c0c1ccd14c32147652a1f 100644 (file)
 
 #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)
 {
index 878bddfd7cd5982b72896ebf09749c7aeb762d27..b9036d319b779e7dc26b4cefd4efedec65c4f808 100644 (file)
@@ -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;
index 57b386b6624e67f97db6e20578a22de75c1c13b3..1f296b56278ed68a9db439ddac0a50fe7864cccc 100644 (file)
@@ -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;