From 0a00302fabef8f8c35b84894309e7c1da534c85d Mon Sep 17 00:00:00 2001 From: William Lallemand Date: Mon, 27 May 2024 11:06:40 +0200 Subject: [PATCH] MINOR: sample: implement the uptime sample fetch 'uptime' returns the uptime of the current HAProxy worker in seconds. --- doc/configuration.txt | 3 +++ src/sample.c | 11 +++++++++++ 2 files changed, 14 insertions(+) diff --git a/doc/configuration.txt b/doc/configuration.txt index aa3704c249..596e5c9849 100644 --- a/doc/configuration.txt +++ b/doc/configuration.txt @@ -21435,6 +21435,9 @@ txn.sess_term_state : string # Return a 429-Too-Many-Requests if stream timed out in queue http-after-response set-status 429 if { txn.sess_term_state "sQ" } +uptime : integer + Returns the uptime of the current HAProxy worker in seconds. + uuid([]) : string Returns a UUID following the RFC 9562 standard. If the version is not specified, a UUID version 4 (fully random) is returned. diff --git a/src/sample.c b/src/sample.c index 49017fe56b..3e5b576ae7 100644 --- a/src/sample.c +++ b/src/sample.c @@ -4823,6 +4823,16 @@ static int smp_fetch_uuid(const struct arg *args, struct sample *smp, const char return 1; } +/* returns the uptime in seconds */ +static int +smp_fetch_uptime(const struct arg *args, struct sample *smp, const char *kw, void *private) +{ + smp->data.type = SMP_T_SINT; + smp->data.u.sint = ns_to_sec(now_ns - start_time_ns); + return 1; +} + + /* Check if QUIC support was compiled and was not disabled by "no-quic" global option */ static int smp_fetch_quic_enabled(const struct arg *args, struct sample *smp, const char *kw, void *private) { @@ -5123,6 +5133,7 @@ static struct sample_fetch_kw_list smp_kws = {ILH, { { "thread", smp_fetch_thread, 0, NULL, SMP_T_SINT, SMP_USE_CONST }, { "rand", smp_fetch_rand, ARG1(0,SINT), NULL, SMP_T_SINT, SMP_USE_CONST }, { "stopping", smp_fetch_stopping, 0, NULL, SMP_T_BOOL, SMP_USE_INTRN }, + { "uptime", smp_fetch_uptime, 0, NULL, SMP_T_SINT, SMP_USE_CONST }, { "uuid", smp_fetch_uuid, ARG1(0, SINT), smp_check_uuid, SMP_T_STR, SMP_USE_CONST }, { "cpu_calls", smp_fetch_cpu_calls, 0, NULL, SMP_T_SINT, SMP_USE_INTRN },