[MINOR] acl: add srv_conn acl to count connections on a

specific backend server

These ACLs are used to check the number of active connections on the specified server in the specified backend.
This commit is contained in:
Herv COMMOWICK 2011-08-05 12:09:44 +02:00 committed by Willy Tarreau
parent 2a0f4d27a4
commit daa824e513
4 changed files with 21 additions and 2 deletions

View File

@ -7456,6 +7456,12 @@ src_updt_conn_cnt(table) <integer>
tcp-request content reject if { src_update_count gt 3 }
server local 127.0.0.1:22
srv_conn(backend/server) <integer>
Applies to the number of currently established connections on the server,
possibly including the connection being evaluated.
It can be used to use a specific farm when one server is full.
See also the "fe_conn", "be_conn" and "queue" criteria.
srv_id <integer>
Applies to the server's id. Can be used in frontends or backends.

View File

@ -308,7 +308,7 @@ struct acl_expr {
union { /* optional argument of the subject (eg: header or cookie name) */
char *str;
struct userlist *ul;
struct server *srv;
struct server *srv; /* must be initialised by acl_find_targets */
} arg;
int arg_len; /* optional argument length */
struct list patterns; /* list of acl_patterns */

View File

@ -1732,7 +1732,8 @@ acl_find_targets(struct proxy *p)
list_for_each_entry(acl, &p->acl, list) {
list_for_each_entry(expr, &acl->expr, list) {
if (strcmp(expr->kw->kw, "srv_is_up") == 0) {
if (strcmp(expr->kw->kw, "srv_is_up") == 0 ||
strcmp(expr->kw->kw, "srv_conn") == 0) {
struct proxy *px;
struct server *srv;
char *pname, *sname;

View File

@ -1551,6 +1551,17 @@ acl_fetch_avg_queue_size(struct proxy *px, struct session *l4, void *l7, int dir
return 1;
}
/* set test->i to the number of concurrent connections on the server in the backend */
static int
acl_fetch_srv_conn(struct proxy *px, struct session *l4, void *l7, int dir,
struct acl_expr *expr, struct acl_test *test)
{
struct server *srv = expr->arg.srv;
test->i = srv->cur_sess;
return 1;
}
/* Note: must not be declared <const> as its list will be overwritten */
static struct acl_kw_list acl_kws = {{ },{
{ "nbsrv", acl_parse_int, acl_fetch_nbsrv, acl_match_int, ACL_USE_NOTHING },
@ -1562,6 +1573,7 @@ static struct acl_kw_list acl_kws = {{ },{
{ "avg_queue", acl_parse_int, acl_fetch_avg_queue_size, acl_match_int, ACL_USE_NOTHING },
{ "srv_is_up", acl_parse_nothing, acl_fetch_srv_is_up, acl_match_nothing, ACL_USE_NOTHING },
{ "srv_id", acl_parse_int, acl_fetch_srv_id, acl_match_int, ACL_USE_RTR_INTERNAL },
{ "srv_conn", acl_parse_int, acl_fetch_srv_conn, acl_match_int, ACL_USE_NOTHING },
{ NULL, NULL, NULL, NULL },
}};