]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: sample: add a few basic internal fetches (nbproc, proc, stopping)
authorWilly Tarreau <w@1wt.eu>
Mon, 24 Nov 2014 15:02:05 +0000 (16:02 +0100)
committerWilly Tarreau <w@1wt.eu>
Mon, 24 Nov 2014 16:44:02 +0000 (17:44 +0100)
Sometimes, either for debugging or for logging we'd like to have a bit
of information about the running process. Here are 3 new fetches for this :

nbproc : integer
  Returns an integer value corresponding to the number of processes that were
  started (it equals the global "nbproc" setting). This is useful for logging
  and debugging purposes.

proc : integer
  Returns an integer value corresponding to the position of the process calling
  the function, between 1 and global.nbproc. This is useful for logging and
  debugging purposes.

stopping : boolean
  Returns TRUE if the process calling the function is currently stopping. This
  can be useful for logging, or for relaxing certain checks or helping close
  certain connections upon graceful shutdown.

doc/configuration.txt
src/sample.c

index 7e578c1417ff4e37434cc8148fb205efadfab742..ec412d4c911c5f5ecfa843a75a38ef5134d261ff 100644 (file)
@@ -10538,6 +10538,11 @@ fe_sess_rate([<frontend>]) : integer
             tcp-request content accept if ! too_fast
             tcp-request content accept if WAIT_END
 
+nbproc : integer
+  Returns an integer value corresponding to the number of processes that were
+  started (it equals the global "nbproc" setting). This is useful for logging
+  and debugging purposes.
+
 nbsrv([<backend>]) : integer
   Returns an integer value corresponding to the number of usable servers of
   either the current backend or the named backend. This is mostly used with
@@ -10546,6 +10551,11 @@ nbsrv([<backend>]) : integer
   to handle some load. It is useful to report a failure when combined with
   "monitor fail".
 
+proc : integer
+  Returns an integer value corresponding to the position of the process calling
+  the function, between 1 and global.nbproc. This is useful for logging and
+  debugging purposes.
+
 queue([<backend>]) : integer
   Returns the total number of queued connections of the designated backend,
   including all the connections in server queues. If no backend name is
@@ -10596,6 +10606,11 @@ srv_sess_rate([<backend>/]<server>) : integer
         acl srv2_full srv_sess_rate(be1/srv2) gt 50
         use_backend be2 if srv1_full or srv2_full
 
+stopping : boolean
+  Returns TRUE if the process calling the function is currently stopping. This
+  can be useful for logging, or for relaxing certain checks or helping close
+  certain connections upon graceful shutdown.
+
 table_avl([<table>]) : integer
   Returns the total number of available entries in the current proxy's
   stick-table or in the designated stick-table. See also table_cnt.
index 7db506d0a85892684d13fa59ce3691258b2a8b5f..be00c3c182ae856ce54b707b61ed6e3e6bf34411 100644 (file)
@@ -1625,6 +1625,26 @@ smp_fetch_date(struct proxy *px, struct session *s, void *l7, unsigned int opt,
        return 1;
 }
 
+/* returns the number of processes */
+static int
+smp_fetch_nbproc(struct proxy *px, struct session *s, void *l7, unsigned int opt,
+                 const struct arg *args, struct sample *smp, const char *kw)
+{
+       smp->type = SMP_T_UINT;
+       smp->data.uint = global.nbproc;
+       return 1;
+}
+
+/* returns the number of the current process (between 1 and nbproc */
+static int
+smp_fetch_proc(struct proxy *px, struct session *s, void *l7, unsigned int opt,
+               const struct arg *args, struct sample *smp, const char *kw)
+{
+       smp->type = SMP_T_UINT;
+       smp->data.uint = relative_pid;
+       return 1;
+}
+
 /* generate a random 32-bit integer for whatever purpose, with an optional
  * range specified in argument.
  */
@@ -1643,6 +1663,16 @@ smp_fetch_rand(struct proxy *px, struct session *s, void *l7, unsigned int opt,
        return 1;
 }
 
+/* returns true if the current process is stopping */
+static int
+smp_fetch_stopping(struct proxy *px, struct session *s, void *l7, unsigned int opt,
+                   const struct arg *args, struct sample *smp, const char *kw)
+{
+       smp->type = SMP_T_BOOL;
+       smp->data.uint = stopping;
+       return 1;
+}
+
 /* Note: must not be declared <const> as its list will be overwritten.
  * Note: fetches that may return multiple types must be declared as the lowest
  * common denominator, the type that can be casted into all other ones. For
@@ -1653,7 +1683,10 @@ static struct sample_fetch_kw_list smp_kws = {ILH, {
        { "always_true",  smp_fetch_true,  0,            NULL, SMP_T_BOOL, SMP_USE_INTRN },
        { "env",          smp_fetch_env,   ARG1(1,STR),  NULL, SMP_T_STR,  SMP_USE_INTRN },
        { "date",         smp_fetch_date,  ARG1(0,SINT), NULL, SMP_T_UINT, SMP_USE_INTRN },
+       { "nbproc",       smp_fetch_nbproc,0,            NULL, SMP_T_UINT, SMP_USE_INTRN },
+       { "proc",         smp_fetch_proc,  0,            NULL, SMP_T_UINT, SMP_USE_INTRN },
        { "rand",         smp_fetch_rand,  ARG1(0,UINT), NULL, SMP_T_UINT, SMP_USE_INTRN },
+       { "stopping",     smp_fetch_stopping, 0,         NULL, SMP_T_BOOL, SMP_USE_INTRN },
        { /* END */ },
 }};