From 6b19b142e8b3a40c452c32099f3a3071dbdfe43a Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Wed, 9 Oct 2019 15:44:21 +0200 Subject: [PATCH] MINOR: stats: make "show stat" and "show info" Now "show info" supports "desc" after the default and "typed" formats, and "show stat" supports this after the typed format. In both cases this appends the description for the represented metric between double quotes. The same could be done for JSON output but would possibly require to update the schema first. --- doc/management.txt | 12 ++++++++++-- src/stats.c | 6 ++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/doc/management.txt b/doc/management.txt index 73fda8974..d56a031a0 100644 --- a/doc/management.txt +++ b/doc/management.txt @@ -1994,7 +1994,7 @@ show fd [] that the output format may evolve over time so this output must not be parsed by tools designed to be durable. -show info [typed|json] +show info [typed|json] [desc] Dump info about haproxy status on current process. If "typed" is passed as an optional argument, field numbers, names and types are emitted as well so that external monitoring products can easily retrieve, possibly aggregate, then @@ -2026,6 +2026,10 @@ show info [typed|json] ..::: + When "desc" is appended to the command, one extra colon followed by a quoted + string is appended with a description for the metric. At the time of writing, + this is only supported for the "typed" and default output formats. + Example : > show info @@ -2285,7 +2289,7 @@ show sess The special id "all" dumps the states of all sessions, which must be avoided as much as possible as it is highly CPU intensive and can take a lot of time. -show stat [{|} ] [typed|json] +show stat [{|} ] [typed|json] [desc] Dump statistics using the CSV format; using the extended typed output format described in the section above if "typed" is passed after the other arguments; or in JSON if "json" is passed after the other arguments @@ -2359,6 +2363,10 @@ show stat [{|} ] [typed|json] "str". Then the fourth column is the value itself, which the consumer knows how to parse thanks to column 3 and how to process thanks to column 2. + When "desc" is appended to the command, one extra colon followed by a quoted + string is appended with a description for the metric. At the time of writing, + this is only supported for the "typed" output format. + Thus the overall line format in typed mode is : .....::: diff --git a/src/stats.c b/src/stats.c index e9cbb9684..69fe9a8eb 100644 --- a/src/stats.c +++ b/src/stats.c @@ -544,6 +544,8 @@ static int stats_dump_fields_typed(struct buffer *out, return 0; if (!stats_emit_typed_data_field(out, &stats[field])) return 0; + if ((flags & STAT_SHOW_FDESC) && !chunk_appendf(out, ":\"%s\"", stat_fields[field].desc)) + return 0; if (!chunk_strcat(out, "\n")) return 0; } @@ -3327,6 +3329,8 @@ static int stats_dump_info_fields(struct buffer *out, return 0; if (!stats_emit_raw_data_field(out, &info[field])) return 0; + if ((flags & STAT_SHOW_FDESC) && !chunk_appendf(out, ":\"%s\"", info_fields[field].desc)) + return 0; if (!chunk_strcat(out, "\n")) return 0; } @@ -3349,6 +3353,8 @@ static int stats_dump_typed_info_fields(struct buffer *out, return 0; if (!stats_emit_typed_data_field(out, &info[field])) return 0; + if ((flags & STAT_SHOW_FDESC) && !chunk_appendf(out, ":\"%s\"", info_fields[field].desc)) + return 0; if (!chunk_strcat(out, "\n")) return 0; }