From: Willy Tarreau Date: Fri, 8 Jan 2016 10:40:03 +0000 (+0100) Subject: MINOR: stats: add agent_status, agent_code, agent_duration to output X-Git-Tag: v1.7-dev2~33 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7f6188462003b4e4c12e2447a8837172aeccc9b4;p=thirdparty%2Fhaproxy.git MINOR: stats: add agent_status, agent_code, agent_duration to output The agent check status is now reported : - agent_status : status of last agent check - agent_code : numeric code reported by agent if any (unused for now) - agent_duration : time in ms taken to finish last check --- diff --git a/doc/management.txt b/doc/management.txt index 1b677be9b3..46b03aa8f1 100644 --- a/doc/management.txt +++ b/doc/management.txt @@ -1002,6 +1002,18 @@ S (Servers). (0 for TCP) 61. ttime [..BS]: the average total session time in ms over the 1024 last requests + 62. agent_status [...S]: status of last agent check, one of: + UNK -> unknown + INI -> initializing + SOCKERR -> socket error + L4OK -> check passed on layer 4, no upper layers testing enabled + L4TOUT -> layer 1-4 timeout + L4CON -> layer 1-4 connection problem, for example + "Connection refused" (tcp rst) or "No route to host" (icmp) + L7OK -> agent reported "up" + L7STS -> agent reported "fail", "stop", or "down" + 63. agent_code [...S]: numeric code reported by agent if any (unused for now) + 64. agent_duration [...S]: time in ms taken to finish last check 9.2. Unix Socket commands diff --git a/src/dumpstats.c b/src/dumpstats.c index b7b568062b..f3c2beb530 100644 --- a/src/dumpstats.c +++ b/src/dumpstats.c @@ -322,6 +322,9 @@ enum stat_field { ST_F_CTIME, ST_F_RTIME, ST_F_TTIME, + ST_F_AGENT_STATUS, + ST_F_AGENT_CODE, + ST_F_AGENT_DURATION, /* must always be the last one */ ST_F_TOTAL_FIELDS @@ -394,6 +397,9 @@ const char *stat_field_names[ST_F_TOTAL_FIELDS] = { [ST_F_CTIME] = "ctime", [ST_F_RTIME] = "rtime", [ST_F_TTIME] = "ttime", + [ST_F_AGENT_STATUS] = "agent_status", + [ST_F_AGENT_CODE] = "agent_code", + [ST_F_AGENT_DURATION] = "agent_duration", }; /* one line of stats */ @@ -3746,6 +3752,23 @@ static int stats_dump_sv_stats(struct stream_interface *si, struct proxy *px, in stats[ST_F_CHECK_DURATION] = mkf_u64(FN_DURATION, sv->check.duration); } + if ((sv->agent.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) { + const char *fld_chksts; + + fld_chksts = chunk_newstr(out); + chunk_strcat(out, "* "); // for check in progress + chunk_strcat(out, get_check_status_info(sv->agent.status)); + if (!(sv->agent.state & CHK_ST_INPROGRESS)) + fld_chksts += 2; // skip "* " + stats[ST_F_AGENT_STATUS] = mkf_str(FN_OUTPUT, fld_chksts); + + if (sv->agent.status >= HCHK_STATUS_L57DATA) + stats[ST_F_AGENT_CODE] = mkf_u32(FN_OUTPUT, sv->agent.code); + + if (sv->agent.status >= HCHK_STATUS_CHECKED) + stats[ST_F_AGENT_DURATION] = mkf_u64(FN_DURATION, sv->agent.duration); + } + /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ if (px->mode == PR_MODE_HTTP) { stats[ST_F_HRSP_1XX] = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[1]); @@ -3941,7 +3964,7 @@ static int stats_dump_sv_stats(struct stream_interface *si, struct proxy *px, in chunk_appendf(&trash, "%s MAINT", human_time(stats[ST_F_LASTCHG].u.u32, 1)); } else if (memcmp(field_str(stats, ST_F_STATUS), "DOWN", 4) == 0 && - (ref->agent.state & CHK_ST_ENABLED) && !(sv->agent.health)) { + stats[ST_F_AGENT_STATUS].type && !(sv->agent.health)) { /* DOWN (agent) */ chunk_appendf(&trash, "%s ", human_time(stats[ST_F_LASTCHG].u.u32, 1)); chunk_appendf(&trash, srv_hlt_st[1], "GCC: your -Werror=format-security is bogus, annoying, and hides real bugs, I don't thank you, really!"); @@ -3955,17 +3978,16 @@ static int stats_dump_sv_stats(struct stream_interface *si, struct proxy *px, in } if (memcmp(field_str(stats, ST_F_STATUS), "DOWN", 4) == 0 && - ((sv->agent.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) && !(sv->agent.health)) { + stats[ST_F_AGENT_STATUS].type && !(sv->agent.health)) { chunk_appendf(&trash, - " %s%s", - (sv->agent.state & CHK_ST_INPROGRESS) ? "* " : "", - get_check_status_info(sv->agent.status)); + " %s", + field_str(stats, ST_F_AGENT_STATUS)); - if (sv->agent.status >= HCHK_STATUS_L57DATA) - chunk_appendf(&trash, "/%d", sv->agent.code); + if (stats[ST_F_AGENT_CODE].type) + chunk_appendf(&trash, "/%d", stats[ST_F_AGENT_CODE].u.u32); - if (sv->agent.status >= HCHK_STATUS_CHECKED && sv->agent.duration >= 0) - chunk_appendf(&trash, " in %lums", sv->agent.duration); + if (stats[ST_F_AGENT_DURATION].type && stats[ST_F_AGENT_DURATION].u.u64 >= 0) + chunk_appendf(&trash, " in %lums", (long)stats[ST_F_AGENT_DURATION].u.u64); chunk_appendf(&trash, "
%s", get_check_status_description(sv->agent.status));