]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: stats: extract proxy clear-counter in a dedicated function
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Thu, 2 May 2024 13:25:28 +0000 (15:25 +0200)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Thu, 2 May 2024 14:43:26 +0000 (16:43 +0200)
Split code related to proxies list looping in cli_parse_clear_counters()
to a new dedicated function. This function is placed in the new module
stats-proxy.

include/haproxy/stats-proxy.h
src/stats-proxy.c
src/stats.c

index e68f670249edcffe29d3653a57fc63606116ed9a..81a60f0161f4d92d01736750cfa624091fe3a546 100644 (file)
@@ -1,10 +1,14 @@
 #ifndef _HAPROXY_STATS_PROXY_H
 #define _HAPROXY_STATS_PROXY_H
 
+#include <haproxy/api-t.h>
+
 struct buffer;
 struct htx;
 struct stconn;
 
 int stats_dump_proxies(struct stconn *sc, struct buffer *buf, struct htx *htx);
 
+void proxy_stats_clear_counters(int clrall, struct list *stat_modules);
+
 #endif /* _HAPROXY_STATS_PROXY_H */
index 0d3a6855596fd9c6c3be52c3f4f129a0ef4f0cf5..a158d87cf24d8a92b6e2b298a4c2ba1b610f73e0 100644 (file)
@@ -1591,3 +1591,96 @@ int stats_dump_proxies(struct stconn *sc, struct buffer *buf, struct htx *htx)
   full:
        return 0;
 }
+
+void proxy_stats_clear_counters(int clrall, struct list *stat_modules)
+{
+       struct proxy *px;
+       struct server *sv;
+       struct listener *li;
+       struct stats_module *mod;
+
+       for (px = proxies_list; px; px = px->next) {
+               if (clrall) {
+                       memset(&px->be_counters, 0, sizeof(px->be_counters));
+                       memset(&px->fe_counters, 0, sizeof(px->fe_counters));
+               }
+               else {
+                       px->be_counters.conn_max = 0;
+                       px->be_counters.p.http.rps_max = 0;
+                       px->be_counters.sps_max = 0;
+                       px->be_counters.cps_max = 0;
+                       px->be_counters.nbpend_max = 0;
+                       px->be_counters.qtime_max = 0;
+                       px->be_counters.ctime_max = 0;
+                       px->be_counters.dtime_max = 0;
+                       px->be_counters.ttime_max = 0;
+
+                       px->fe_counters.conn_max = 0;
+                       px->fe_counters.p.http.rps_max = 0;
+                       px->fe_counters.sps_max = 0;
+                       px->fe_counters.cps_max = 0;
+               }
+
+               for (sv = px->srv; sv; sv = sv->next)
+                       if (clrall)
+                               memset(&sv->counters, 0, sizeof(sv->counters));
+                       else {
+                               sv->counters.cur_sess_max = 0;
+                               sv->counters.nbpend_max = 0;
+                               sv->counters.sps_max = 0;
+                               sv->counters.qtime_max = 0;
+                               sv->counters.ctime_max = 0;
+                               sv->counters.dtime_max = 0;
+                               sv->counters.ttime_max = 0;
+                       }
+
+               list_for_each_entry(li, &px->conf.listeners, by_fe)
+                       if (li->counters) {
+                               if (clrall)
+                                       memset(li->counters, 0, sizeof(*li->counters));
+                               else
+                                       li->counters->conn_max = 0;
+                       }
+       }
+
+       list_for_each_entry(mod, stat_modules, list) {
+               if (!mod->clearable && !clrall)
+                       continue;
+
+               for (px = proxies_list; px; px = px->next) {
+                       enum stats_domain_px_cap mod_cap = stats_px_get_cap(mod->domain_flags);
+
+                       if (px->cap & PR_CAP_FE && mod_cap & STATS_PX_CAP_FE) {
+                               EXTRA_COUNTERS_INIT(px->extra_counters_fe,
+                                                   mod,
+                                                   mod->counters,
+                                                   mod->counters_size);
+                       }
+
+                       if (px->cap & PR_CAP_BE && mod_cap & STATS_PX_CAP_BE) {
+                               EXTRA_COUNTERS_INIT(px->extra_counters_be,
+                                                   mod,
+                                                   mod->counters,
+                                                   mod->counters_size);
+                       }
+
+                       if (mod_cap & STATS_PX_CAP_SRV) {
+                               for (sv = px->srv; sv; sv = sv->next) {
+                                       EXTRA_COUNTERS_INIT(sv->extra_counters,
+                                                           mod,
+                                                           mod->counters,
+                                                           mod->counters_size);
+                               }
+                       }
+
+                       if (mod_cap & STATS_PX_CAP_LI) {
+                               list_for_each_entry(li, &px->conf.listeners, by_fe) {
+                                       EXTRA_COUNTERS_INIT(li->extra_counters,
+                                                           mod,
+                                                           mod->counters,
+                                                           mod->counters_size);
+                               }
+                       }
+               }
+       }
+}
index 582e952ae633afff81866bd7478b6565ad66cbfc..2baffc5863f1d2df7f595a12d495161a700556c2 100644 (file)
@@ -862,10 +862,6 @@ more:
 
 static int cli_parse_clear_counters(char **args, char *payload, struct appctx *appctx, void *private)
 {
-       struct proxy *px;
-       struct server *sv;
-       struct listener *li;
-       struct stats_module *mod;
        int clrall = 0;
 
        if (strcmp(args[2], "all") == 0)
@@ -876,96 +872,13 @@ static int cli_parse_clear_counters(char **args, char *payload, struct appctx *a
            (clrall && !cli_has_level(appctx, ACCESS_LVL_ADMIN)))
                return 1;
 
-       for (px = proxies_list; px; px = px->next) {
-               if (clrall) {
-                       memset(&px->be_counters, 0, sizeof(px->be_counters));
-                       memset(&px->fe_counters, 0, sizeof(px->fe_counters));
-               }
-               else {
-                       px->be_counters.conn_max = 0;
-                       px->be_counters.p.http.rps_max = 0;
-                       px->be_counters.sps_max = 0;
-                       px->be_counters.cps_max = 0;
-                       px->be_counters.nbpend_max = 0;
-                       px->be_counters.qtime_max = 0;
-                       px->be_counters.ctime_max = 0;
-                       px->be_counters.dtime_max = 0;
-                       px->be_counters.ttime_max = 0;
-
-                       px->fe_counters.conn_max = 0;
-                       px->fe_counters.p.http.rps_max = 0;
-                       px->fe_counters.sps_max = 0;
-                       px->fe_counters.cps_max = 0;
-               }
-
-               for (sv = px->srv; sv; sv = sv->next)
-                       if (clrall)
-                               memset(&sv->counters, 0, sizeof(sv->counters));
-                       else {
-                               sv->counters.cur_sess_max = 0;
-                               sv->counters.nbpend_max = 0;
-                               sv->counters.sps_max = 0;
-                               sv->counters.qtime_max = 0;
-                               sv->counters.ctime_max = 0;
-                               sv->counters.dtime_max = 0;
-                               sv->counters.ttime_max = 0;
-                       }
-
-               list_for_each_entry(li, &px->conf.listeners, by_fe)
-                       if (li->counters) {
-                               if (clrall)
-                                       memset(li->counters, 0, sizeof(*li->counters));
-                               else
-                                       li->counters->conn_max = 0;
-                       }
-       }
-
        global.cps_max = 0;
        global.sps_max = 0;
        global.ssl_max = 0;
        global.ssl_fe_keys_max = 0;
        global.ssl_be_keys_max = 0;
 
-       list_for_each_entry(mod, &stats_module_list[STATS_DOMAIN_PROXY], list) {
-               if (!mod->clearable && !clrall)
-                       continue;
-
-               for (px = proxies_list; px; px = px->next) {
-                       enum stats_domain_px_cap mod_cap = stats_px_get_cap(mod->domain_flags);
-
-                       if (px->cap & PR_CAP_FE && mod_cap & STATS_PX_CAP_FE) {
-                               EXTRA_COUNTERS_INIT(px->extra_counters_fe,
-                                                   mod,
-                                                   mod->counters,
-                                                   mod->counters_size);
-                       }
-
-                       if (px->cap & PR_CAP_BE && mod_cap & STATS_PX_CAP_BE) {
-                               EXTRA_COUNTERS_INIT(px->extra_counters_be,
-                                                   mod,
-                                                   mod->counters,
-                                                   mod->counters_size);
-                       }
-
-                       if (mod_cap & STATS_PX_CAP_SRV) {
-                               for (sv = px->srv; sv; sv = sv->next) {
-                                       EXTRA_COUNTERS_INIT(sv->extra_counters,
-                                                           mod,
-                                                           mod->counters,
-                                                           mod->counters_size);
-                               }
-                       }
-
-                       if (mod_cap & STATS_PX_CAP_LI) {
-                               list_for_each_entry(li, &px->conf.listeners, by_fe) {
-                                       EXTRA_COUNTERS_INIT(li->extra_counters,
-                                                           mod,
-                                                           mod->counters,
-                                                           mod->counters_size);
-                               }
-                       }
-               }
-       }
+       proxy_stats_clear_counters(clrall, &stats_module_list[STATS_DOMAIN_PROXY]);
 
        resolv_stats_clear_counters(clrall, &stats_module_list[STATS_DOMAIN_RESOLVERS]);