From e4a29447ce44802c03b22faf5cfc6e681b3643e7 Mon Sep 17 00:00:00 2001 From: Amaury Denoyelle Date: Wed, 24 Apr 2024 11:10:07 +0200 Subject: [PATCH] MEDIUM: stats: define stats-file keyword 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 | 6 ++++++ src/cfgparse-global.c | 16 ++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/doc/configuration.txt b/doc/configuration.txt index 16094c194..6733e650b 100644 --- a/doc/configuration.txt +++ b/doc/configuration.txt @@ -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 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 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 diff --git a/src/cfgparse-global.c b/src/cfgparse-global.c index b173511c9..1f73fbdd8 100644 --- a/src/cfgparse-global.c +++ b/src/cfgparse-global.c @@ -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;