MEDIUM: stats: report server's address in the CSV output
This new field "addr" presents the server's address:port if the client
is either enabled via "stats show legends" in case of HTTP dumps, or
has at least level operator on the CLI. The address formats might be :
- ipv4:port
- [ipv6]:port
- unix
- (error message)
diff --git a/doc/management.txt b/doc/management.txt
index 253dd0d..5ff45c0 100644
--- a/doc/management.txt
+++ b/doc/management.txt
@@ -1022,6 +1022,7 @@
70. agent_rise [...S]: agent's "rise" parameter, normally 1
71. agent_fall [...S]: agent's "fall" parameter, normally 1
72. agent_health [...S]: agent's health parameter, between 0 and rise+fall-1
+ 73. addr [...S]: server's address:port. IPv6 has brackets around the address.
9.2. Unix Socket commands
diff --git a/src/dumpstats.c b/src/dumpstats.c
index 90b1b11..b6145a7 100644
--- a/src/dumpstats.c
+++ b/src/dumpstats.c
@@ -333,6 +333,7 @@
ST_F_AGENT_RISE,
ST_F_AGENT_FALL,
ST_F_AGENT_HEALTH,
+ ST_F_ADDR,
/* must always be the last one */
ST_F_TOTAL_FIELDS
@@ -416,6 +417,7 @@
[ST_F_AGENT_RISE] = "agent_rise",
[ST_F_AGENT_FALL] = "agent_fall",
[ST_F_AGENT_HEALTH] = "agent_health",
+ [ST_F_ADDR] = "addr",
};
/* one line of stats */
@@ -3819,6 +3821,28 @@
stats[ST_F_RTIME] = mkf_u32(FN_AVG, swrate_avg(sv->counters.d_time, TIME_STATS_SAMPLES));
stats[ST_F_TTIME] = mkf_u32(FN_AVG, swrate_avg(sv->counters.t_time, TIME_STATS_SAMPLES));
+ if (flags & ST_SHLGNDS) {
+ switch (addr_to_str(&sv->addr, str, sizeof(str))) {
+ case AF_INET:
+ stats[ST_F_ADDR] = mkf_str(FO_CONFIG|FS_SERVICE, chunk_newstr(out));
+ chunk_appendf(out, "%s:%d", str, get_host_port(&sv->addr));
+ break;
+ case AF_INET6:
+ stats[ST_F_ADDR] = mkf_str(FO_CONFIG|FS_SERVICE, chunk_newstr(out));
+ chunk_appendf(out, "[%s]:%d", str, get_host_port(&sv->addr));
+ break;
+ case AF_UNIX:
+ stats[ST_F_ADDR] = mkf_str(FO_CONFIG|FS_SERVICE, "unix");
+ break;
+ case -1:
+ stats[ST_F_ADDR] = mkf_str(FO_CONFIG|FS_SERVICE, chunk_newstr(out));
+ chunk_strcat(out, strerror(errno));
+ break;
+ default: /* address family not supported */
+ break;
+ }
+ }
+
if (appctx->ctx.stats.flags & STAT_FMT_HTML) {
if (memcmp(field_str(stats, ST_F_STATUS), "MAINT", 5) == 0)
chunk_appendf(&trash, "<tr class=\"maintain\">");
@@ -3843,22 +3867,12 @@
if (flags & ST_SHLGNDS) {
chunk_appendf(&trash, "<div class=tips>");
- switch (addr_to_str(&sv->addr, str, sizeof(str))) {
- case AF_INET:
- chunk_appendf(&trash, "IPv4: %s:%d, ", str, get_host_port(&sv->addr));
- break;
- case AF_INET6:
- chunk_appendf(&trash, "IPv6: [%s]:%d, ", str, get_host_port(&sv->addr));
- break;
- case AF_UNIX:
- chunk_appendf(&trash, "unix, ");
- break;
- case -1:
- chunk_appendf(&trash, "(%s), ", strerror(errno));
- break;
- default: /* address family not supported */
- break;
- }
+ if (isdigit(*field_str(stats, ST_F_ADDR)))
+ chunk_appendf(&trash, "IPv4: %s, ", field_str(stats, ST_F_ADDR));
+ else if (*field_str(stats, ST_F_ADDR) == '[')
+ chunk_appendf(&trash, "IPv6: %s, ", field_str(stats, ST_F_ADDR));
+ else if (*field_str(stats, ST_F_ADDR))
+ chunk_appendf(&trash, "%s, ", field_str(stats, ST_F_ADDR));
/* id */
chunk_appendf(&trash, "id: %d", stats[ST_F_SID].u.u32);