From ff2b7afe0b72874e158400aaa58f413dda030489 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Fri, 13 Oct 2017 11:46:26 +0200 Subject: [PATCH] MINOR: server: add the srv_queue() sample fetch method srv_queue([/]) : integer Returns an integer value corresponding to the number of connections currently pending in the designated server's queue. If is omitted, then the server is looked up in the current backend. It can sometimes be used together with the "use-server" directive to force to use a known faster server when it is not much loaded. See also the "srv_conn", "avg_queue" and "queue" sample fetch methods. --- doc/configuration.txt | 8 ++++++++ src/backend.c | 14 ++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/doc/configuration.txt b/doc/configuration.txt index c3aa6fa84..c7359a85f 100644 --- a/doc/configuration.txt +++ b/doc/configuration.txt @@ -13373,6 +13373,14 @@ srv_is_up([/]) : boolean using dummy servers as boolean variables that can be enabled or disabled from the CLI, so that rules depending on those ACLs can be tweaked in realtime. +srv_queue([/]) : integer + Returns an integer value corresponding to the number of connections currently + pending in the designated server's queue. If is omitted, then the + server is looked up in the current backend. It can sometimes be used together + with the "use-server" directive to force to use a known faster server when it + is not much loaded. See also the "srv_conn", "avg_queue" and "queue" sample + fetch methods. + srv_sess_rate([/]) : integer Returns an integer corresponding to the sessions creation rate on the designated server, in number of new sessions per second. If is diff --git a/src/backend.c b/src/backend.c index 52adab009..06f15a1ca 100644 --- a/src/backend.c +++ b/src/backend.c @@ -1798,6 +1798,19 @@ smp_fetch_srv_conn(const struct arg *args, struct sample *smp, const char *kw, v return 1; } +/* set temp integer to the number of connections pending in the server's queue. + * Accepts exactly 1 argument. Argument is a server, other types will lead to + * undefined behaviour. + */ +static int +smp_fetch_srv_queue(const struct arg *args, struct sample *smp, const char *kw, void *private) +{ + smp->flags = SMP_F_VOL_TEST; + smp->data.type = SMP_T_SINT; + smp->data.u.sint = args->data.srv->nbpend; + return 1; +} + /* set temp integer to the number of enabled servers on the proxy. * Accepts exactly 1 argument. Argument is a server, other types will lead to * undefined behaviour. @@ -1845,6 +1858,7 @@ static struct sample_fetch_kw_list smp_kws = {ILH, { { "srv_conn", smp_fetch_srv_conn, ARG1(1,SRV), NULL, SMP_T_SINT, SMP_USE_INTRN, }, { "srv_id", smp_fetch_srv_id, 0, NULL, SMP_T_SINT, SMP_USE_SERVR, }, { "srv_is_up", smp_fetch_srv_is_up, ARG1(1,SRV), NULL, SMP_T_BOOL, SMP_USE_INTRN, }, + { "srv_queue", smp_fetch_srv_queue, ARG1(1,SRV), NULL, SMP_T_SINT, SMP_USE_INTRN, }, { "srv_sess_rate", smp_fetch_srv_sess_rate, ARG1(1,SRV), NULL, SMP_T_SINT, SMP_USE_INTRN, }, { /* END */ }, }};