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.
This commit is contained in:
Amaury Denoyelle 2024-04-24 11:10:07 +02:00
parent 782be288ca
commit e4a29447ce
2 changed files with 22 additions and 0 deletions

View File

@ -1318,6 +1318,7 @@ The following keywords are supported in the "global" section :
- ssl-server-verify - ssl-server-verify
- ssl-skip-self-issued-ca - ssl-skip-self-issued-ca
- stats - stats
- stats-file
- strict-limits - strict-limits
- uid - uid
- ulimit-n - ulimit-n
@ -2661,6 +2662,11 @@ stats timeout <timeout, in milliseconds>
to change this value with "stats timeout". The value must be passed in 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 }. 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 strict-limits
Makes process fail at startup when a setrlimit fails. HAProxy tries to set the 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 best setrlimit according to what has been calculated. If it fails, it will

View File

@ -52,6 +52,7 @@ static const char *common_kw_list[] = {
"presetenv", "unsetenv", "resetenv", "strict-limits", "localpeer", "presetenv", "unsetenv", "resetenv", "strict-limits", "localpeer",
"numa-cpu-mapping", "defaults", "listen", "frontend", "backend", "numa-cpu-mapping", "defaults", "listen", "frontend", "backend",
"peers", "resolvers", "cluster-secret", "no-quic", "limited-quic", "peers", "resolvers", "cluster-secret", "no-quic", "limited-quic",
"stats-file",
NULL /* must be last */ 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]); 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 */ else if (strcmp(args[0], "log-tag") == 0) { /* tag to report to syslog */
if (alertif_too_many_args(1, file, linenum, args, &err_code)) if (alertif_too_many_args(1, file, linenum, args, &err_code))
goto out; goto out;