]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: add be_conn_free sample fetch
authorPatrick Hemmer <haproxy@stormcloud9.net>
Thu, 14 Jun 2018 21:10:27 +0000 (17:10 -0400)
committerWilly Tarreau <w@1wt.eu>
Mon, 27 Aug 2018 12:10:16 +0000 (14:10 +0200)
This adds the sample fetch 'be_conn_free([<backend>])'. This sample fetch
provides the total number of unused connections across available servers in the
specified backend.

doc/configuration.txt
src/backend.c

index 6e33f5994e4124b1cc7fbeb036924f5cd34b2fc9..6eec8c10bd4ef4718c83b100381f2a3bdbbfcc87 100644 (file)
@@ -13682,7 +13682,19 @@ be_conn([<backend>]) : integer
   possibly including the connection being evaluated. If no backend name is
   specified, the current one is used. But it is also possible to check another
   backend. It can be used to use a specific farm when the nominal one is full.
-  See also the "fe_conn", "queue" and "be_sess_rate" criteria.
+  See also the "fe_conn", "queue", "be_conn_free", and "be_sess_rate" criteria.
+
+be_conn_free([<backend>]) : integer
+  Returns an integer value corresponding to the number of available connections
+  across available servers in the backend. Queue slots are not included. Backup
+  servers are also not included, unless all other servers are down. If no
+  backend name is specified, the current one is used. But it is also possible
+  to check another backend. It can be used to use a specific farm when the
+  nominal one is full. See also the "be_conn" and "connslots" criteria.
+
+  OTHER CAVEATS AND NOTES: if any of the server maxconn, or maxqueue is 0
+  (meaning unlimited), then this fetch clearly does not make sense, in which
+  case the value returned will be -1.
 
 be_sess_rate([<backend>]) : integer
   Returns an integer value corresponding to the sessions creation rate on the
index 1aadca59010ba1c73ee10ad08df79687869c6a5b..01bd4b1611c98ae21add11a9a360c747af809db8 100644 (file)
@@ -1792,6 +1792,46 @@ smp_fetch_be_conn(const struct arg *args, struct sample *smp, const char *kw, vo
        return 1;
 }
 
+/* set temp integer to the number of available connections across available
+       *       servers on the backend.
+ * Accepts exactly 1 argument. Argument is a backend, other types will lead to
+ * undefined behaviour.
+       */
+static int
+smp_fetch_be_conn_free(const struct arg *args, struct sample *smp, const char *kw, void *private)
+{
+       struct server *iterator;
+       struct proxy *px;
+       unsigned int maxconn;
+
+       smp->flags = SMP_F_VOL_TEST;
+       smp->data.type = SMP_T_SINT;
+       smp->data.u.sint = 0;
+
+       for (iterator = args->data.prx->srv; iterator; iterator = iterator->next) {
+               if (iterator->cur_state == SRV_ST_STOPPED)
+                       continue;
+
+               px = iterator->proxy;
+               if (!srv_currently_usable(iterator) ||
+                   ((iterator->flags & SRV_F_BACKUP) &&
+                    (px->srv_act || (iterator != px->lbprm.fbck && !(px->options & PR_O_USE_ALL_BK)))))
+                       continue;
+
+               if (iterator->maxconn == 0) {
+                       /* one active server is unlimited, return -1 */
+                       smp->data.u.sint = -1;
+                       return 1;
+               }
+
+               maxconn = srv_dynamic_maxconn(iterator);
+               if (maxconn > iterator->cur_sess)
+                       smp->data.u.sint += maxconn - iterator->cur_sess;
+       }
+
+       return 1;
+}
+
 /* set temp integer to the total number of queued connections on the backend.
  * Accepts exactly 1 argument. Argument is a backend, other types will lead to
  * undefined behaviour.
@@ -1897,6 +1937,7 @@ static int sample_conv_nbsrv(const struct arg *args, struct sample *smp, void *p
 static struct sample_fetch_kw_list smp_kws = {ILH, {
        { "avg_queue",     smp_fetch_avg_queue_size, ARG1(1,BE),  NULL, SMP_T_SINT, SMP_USE_INTRN, },
        { "be_conn",       smp_fetch_be_conn,        ARG1(1,BE),  NULL, SMP_T_SINT, SMP_USE_INTRN, },
+       { "be_conn_free",  smp_fetch_be_conn_free,   ARG1(1,BE),  NULL, SMP_T_SINT, SMP_USE_INTRN, },
        { "be_id",         smp_fetch_be_id,          0,           NULL, SMP_T_SINT, SMP_USE_BKEND, },
        { "be_name",       smp_fetch_be_name,        0,           NULL, SMP_T_STR,  SMP_USE_BKEND, },
        { "be_sess_rate",  smp_fetch_be_sess_rate,   ARG1(1,BE),  NULL, SMP_T_SINT, SMP_USE_INTRN, },