mirror of
http://git.haproxy.org/git/haproxy.git/
synced 2025-02-18 19:56:59 +00:00
MINOR: backend: Add sample fetches to get the server's weight
The following sample fetches have been added : * srv_iweight : returns the initial server's weight * srv_uweight : returns the user-visible server's weight * srv_weight : returns the current (or effetctive) server's weight The requested server must be passed as argument, evnetually preceded by the backend name. For instance : srv_weight(back-http/www1)
This commit is contained in:
parent
c55a626217
commit
1bea865811
@ -16160,6 +16160,21 @@ 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
|
||||
|
||||
srv_iweight([<backend>/]<server>): integer
|
||||
Returns an integer corresponding to the server's initial weight. If <backend>
|
||||
is omitted, then the server is looked up in the current backend. See also
|
||||
"srv_weight" and "srv_uweight".
|
||||
|
||||
srv_uweight([<backend>/]<server>): integer
|
||||
Returns an integer corresponding to the user visible server's weight. If
|
||||
<backend> is omitted, then the server is looked up in the current
|
||||
backend. See also "srv_weight" and "srv_iweight".
|
||||
|
||||
srv_weight([<backend>/]<server>): integer
|
||||
Returns an integer corresponding to the current (or effective) server's
|
||||
weight. If <backend> is omitted, then the server is looked up in the current
|
||||
backend. See also "srv_iweight" and "srv_uweight".
|
||||
|
||||
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
|
||||
|
@ -2810,6 +2810,48 @@ smp_fetch_srv_sess_rate(const struct arg *args, struct sample *smp, const char *
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* set temp integer to the server weight.
|
||||
* Accepts exactly 1 argument. Argument is a server, other types will lead to
|
||||
* undefined behaviour.
|
||||
*/
|
||||
static int
|
||||
smp_fetch_srv_weight(const struct arg *args, struct sample *smp, const char *kw, void *private)
|
||||
{
|
||||
struct server *srv = args->data.srv;
|
||||
struct proxy *px = srv->proxy;
|
||||
|
||||
smp->flags = SMP_F_VOL_TEST;
|
||||
smp->data.type = SMP_T_SINT;
|
||||
smp->data.u.sint = (srv->cur_eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* set temp integer to the server initial weight.
|
||||
* Accepts exactly 1 argument. Argument is a server, other types will lead to
|
||||
* undefined behaviour.
|
||||
*/
|
||||
static int
|
||||
smp_fetch_srv_iweight(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->iweight;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* set temp integer to the server user-specified weight.
|
||||
* Accepts exactly 1 argument. Argument is a server, other types will lead to
|
||||
* undefined behaviour.
|
||||
*/
|
||||
static int
|
||||
smp_fetch_srv_uweight(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->uweight;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int sample_conv_nbsrv(const struct arg *args, struct sample *smp, void *private)
|
||||
{
|
||||
|
||||
@ -2881,6 +2923,9 @@ static struct sample_fetch_kw_list smp_kws = {ILH, {
|
||||
{ "srv_name", smp_fetch_srv_name, 0, NULL, SMP_T_STR, SMP_USE_SERVR, },
|
||||
{ "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, },
|
||||
{ "srv_weight", smp_fetch_srv_weight, ARG1(1,SRV), NULL, SMP_T_SINT, SMP_USE_INTRN, },
|
||||
{ "srv_iweight", smp_fetch_srv_iweight, ARG1(1,SRV), NULL, SMP_T_SINT, SMP_USE_INTRN, },
|
||||
{ "srv_uweight", smp_fetch_srv_uweight, ARG1(1,SRV), NULL, SMP_T_SINT, SMP_USE_INTRN, },
|
||||
{ /* END */ },
|
||||
}};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user