Add a DRAIN sub-state for a server which will be shown on the stats page instead of UP if an agent check is in use and the agent has most recently returned "drain".
Signed-off-by: Simon Horman <ho...@verge.net.au> --- include/types/server.h | 3 ++- src/checks.c | 7 +++++++ src/dumpstats.c | 12 +++++++++--- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/include/types/server.h b/include/types/server.h index 1eec648..ff6bec0 100644 --- a/include/types/server.h +++ b/include/types/server.h @@ -52,7 +52,8 @@ #define SRV_GOINGDOWN 0x0020 /* this server says that it's going down (404) */ #define SRV_WARMINGUP 0x0040 /* this server is warming up after a failure */ #define SRV_MAINTAIN 0x0080 /* this server is in maintenance mode */ -/* unused: 0x0100, 0x0200, 0x0400 */ +#define SRV_DRAIN 0x0100 /* this server has been requested to drain its connections */ +/* unused: 0x0200, 0x0400 */ #define SRV_SEND_PROXY 0x0800 /* this server talks the PROXY protocol */ #define SRV_NON_STICK 0x1000 /* never add connections allocated to this server to a stick table */ diff --git a/src/checks.c b/src/checks.c index 5d893f8..a9a93ae 100644 --- a/src/checks.c +++ b/src/checks.c @@ -829,6 +829,7 @@ static void agent_expect(struct check *check, char *data) short status = HCHK_STATUS_L7RSP; const char *desc = "Unknown feedback string"; const char *down_cmd = NULL; + int drain = 0; cut_crlf(data); @@ -843,6 +844,7 @@ static void agent_expect(struct check *check, char *data) if (!desc) { desc = "drain"; status = HCHK_STATUS_L7OKD; + drain = 1; } } else if (!strncasecmp(data, "down", strlen("down"))) { down_cmd = "down"; @@ -852,6 +854,11 @@ static void agent_expect(struct check *check, char *data) down_cmd = "fail"; } + if (drain) + check->server->state |= SRV_DRAIN; + else + check->server->state &= ~SRV_DRAIN; + if (down_cmd) { const char *end = data + strlen(down_cmd); /* diff --git a/src/dumpstats.c b/src/dumpstats.c index 72ff726..78a304b 100644 --- a/src/dumpstats.c +++ b/src/dumpstats.c @@ -2104,13 +2104,15 @@ static int stats_dump_sv_stats(struct stream_interface *si, struct proxy *px, in int i; if (si->applet.ctx.stats.flags & STAT_FMT_HTML) { - static char *srv_hlt_st[7] = { + static char *srv_hlt_st[9] = { "DOWN", "DN %d/%d ↑", "UP %d/%d ↓", "UP", "NOLB %d/%d ↓", "NOLB", + "DRAIN %d/%d ↓", + "DRAIN", "<i>no check</i>" }; @@ -2328,13 +2330,15 @@ static int stats_dump_sv_stats(struct stream_interface *si, struct proxy *px, in chunk_appendf(&trash, "<td class=ac>-</td></tr>\n"); } else { /* CSV mode */ - static char *srv_hlt_st[7] = { + static char *srv_hlt_st[9] = { "DOWN,", "DOWN %d/%d,", "UP %d/%d,", "UP,", "NOLB %d/%d,", "NOLB,", + "DRAIN %d/%d,", + "DRAIN,", "no check," }; @@ -2940,7 +2944,7 @@ static int stats_dump_proxy_to_buffer(struct stream_interface *si, struct proxy /* FIXME: produce some small strings for "UP/DOWN x/y &#xxxx;" */ if (!(svs->state & SRV_CHECKED)) - sv_state = 6; + sv_state = 8; else if (svs->state & SRV_RUNNING) { if (svs->check.health == svs->rise + svs->fall - 1) sv_state = 3; /* UP */ @@ -2949,6 +2953,8 @@ static int stats_dump_proxy_to_buffer(struct stream_interface *si, struct proxy if (svs->state & SRV_GOINGDOWN) sv_state += 2; + else if (svs->state & SRV_DRAIN) + sv_state += 4; } else if (svs->check.health) -- 1.7.10.4