]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: stats: define stats-file keyword
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Wed, 24 Apr 2024 09:10:07 +0000 (11:10 +0200)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Fri, 26 Apr 2024 12:18:15 +0000 (14:18 +0200)
This commit is the final to implement preloading of haproxy internal
counters via stats-file parsing.

Define a global keyword "stats-file". It allows to specify the path to
the stats-file which will be parsed on process startup.

doc/configuration.txt
src/cfgparse-global.c

index 16094c194a75f44f14b2499c1073325348345a9d..6733e650b4fc3de15e10666d7f6b81e33083ab80 100644 (file)
@@ -1318,6 +1318,7 @@ The following keywords are supported in the "global" section :
    - ssl-server-verify
    - ssl-skip-self-issued-ca
    - stats
+   - stats-file
    - strict-limits
    - uid
    - ulimit-n
@@ -2661,6 +2662,11 @@ stats timeout <timeout, in milliseconds>
   to change this value with "stats timeout". The value must be passed in
   milliseconds, or be suffixed by a time unit among { us, ms, s, m, h, d }.
 
+stats-file <path>
+  Path to a generated haproxy stats-file. On startup haproxy will preload the
+  values to its internal counters. Use the CLI command "dump stats-file" to
+  produce such stats-file. See the management manual for more details.
+
 strict-limits
   Makes process fail at startup when a setrlimit fails. HAProxy tries to set the
   best setrlimit according to what has been calculated. If it fails, it will
index b173511c9b844f82c95c555403bfe4e23abd61d8..1f73fbdd89c1a73b60ab3f304e0a86f58019aca9 100644 (file)
@@ -52,6 +52,7 @@ static const char *common_kw_list[] = {
        "presetenv", "unsetenv", "resetenv", "strict-limits", "localpeer",
        "numa-cpu-mapping", "defaults", "listen", "frontend", "backend",
        "peers", "resolvers", "cluster-secret", "no-quic", "limited-quic",
+       "stats-file",
        NULL /* must be last */
 };
 
@@ -1031,6 +1032,21 @@ int cfg_parse_global(const char *file, int linenum, char **args, int kwm)
 
                global.server_state_file = strdup(args[1]);
        }
+       else if (strcmp(args[0], "stats-file") == 0) { /* path to the file where HAProxy can load the server states */
+               if (global.stats_file != NULL) {
+                       ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
+                       err_code |= ERR_ALERT;
+                       goto out;
+               }
+
+               if (!*(args[1])) {
+                       ha_alert("parsing [%s:%d] : '%s' expect one argument: a file path.\n", file, linenum, args[0]);
+                       err_code |= ERR_FATAL;
+                       goto out;
+               }
+
+               global.stats_file = strdup(args[1]);
+       }
        else if (strcmp(args[0], "log-tag") == 0) {  /* tag to report to syslog */
                if (alertif_too_many_args(1, file, linenum, args, &err_code))
                        goto out;