]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: sample: implement the uptime sample fetch
authorWilliam Lallemand <wlallemand@haproxy.com>
Mon, 27 May 2024 09:06:40 +0000 (11:06 +0200)
committerWilliam Lallemand <wlallemand@haproxy.com>
Mon, 27 May 2024 09:06:40 +0000 (11:06 +0200)
'uptime' returns the uptime of the current HAProxy worker in seconds.

doc/configuration.txt
src/sample.c

index aa3704c2490442749efe55c58a413a523e2e16e1..596e5c98497b19ea31821351fab0defb6f0216c9 100644 (file)
@@ -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([<version>]) : string
   Returns a UUID following the RFC 9562 standard. If the version is not
   specified, a UUID version 4 (fully random) is returned.
index 49017fe56bb852be846f8d50c469550947e0e733..3e5b576ae7854f19bea53b24f41b40c08a4d78a6 100644 (file)
@@ -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 },