O seguinte parece funcionar para mim, mas foi necessário corrigir o haproxy-1.4.15 / src / backend.c:
# diff haproxy-1.4.15/src/backend.c backend.c
1298a1299,1333
> /* set test->i to the number of enabled servers on the proxy */
> static int
> acl_fetch_connfree(struct proxy *px, struct session *l4, void *l7, int dir,
> struct acl_expr *expr, struct acl_test *test)
> {
> struct server *iterator;
> test->flags = ACL_TEST_F_VOL_TEST;
> if (expr->arg_len) {
> /* another proxy was designated, we must look for it */
> for (px = proxy; px; px = px->next)
> if ((px->cap & PR_CAP_BE) && !strcmp(px->id, expr->arg.str))
> break;
> }
> if (!px)
> return 0;
>
> test->i = 0;
> iterator = px->srv;
> while (iterator) {
> if ((iterator->state & SRV_RUNNING) == 0) {
> iterator = iterator->next;
> continue;
> }
> if (iterator->maxconn == 0) {
> test->i = -1;
> return 1;
> }
>
> test->i += (iterator->maxconn - (iterator->cur_sess + iterator->nbpend));
> iterator = iterator->next;
> }
>
> return 1;
> }
>
1461a1497
> { "connfree", acl_parse_int, acl_fetch_connfree, acl_match_int, ACL_USE_NOTHING },
Posso usar connfree
na minha acl:
frontend frontend1
bind *:12345
acl main_full connfree(main) eq 0
use_backend backup if main_full
default_backend main
backend main
balance leastconn
default-server maxconn 1 maxqueue 1
server main2 10.0.0.1:12345 check
server main1 10.0.0.2:12345 check
backend backup
balance leastconn
default-server maxconn 1 maxqueue 1
server backup1 10.0.1.1:12345 check
server backup2 10.0.1.2:12345 check
Espero que a comparação de acl_fetch_connfree()
a acl_fetch_connslots()
torne óbvia a mudança:
old = (maxconn - conns atuais) + (maxqueue - conns pendentes)
new = maxconn - (conns atuais + conns pendentes)