* [linux-lvm] [PATCH 0/2] JSON output for dmstats
@ 2020-01-24 19:58 Todd Gill
2020-01-24 19:58 ` [linux-lvm] [PATCH 1/2] Add JSON output support to dmstats for list and report subcommands Todd Gill
2020-01-24 19:58 ` [linux-lvm] [PATCH 2/2] Update man page to include --reportformat " Todd Gill
0 siblings, 2 replies; 3+ messages in thread
From: Todd Gill @ 2020-01-24 19:58 UTC (permalink / raw)
To: linux-lvm; +Cc: tgill
This set of patches adds "--reportformat basic|json" options for the
dmstats list and report commands.
In the case where --count is specified with the JSON reportformat, the
output will be <count> consecutive JSON documents.
Example output of a single iteration of "report" in JSON:
{
"report": [{
"stats_name": "mirrorvg-mirrorlv",
"group_id": "-",
"region_id": "0",
"obj_type": "area",
"area_id": "0",
"area_start": "0",
"area_len": "1.00g",
"reads_merged_per_sec": "0.00",
"writes_merged_per_sec": "0.00",
"reads_per_sec": "0.00",
"writes_per_sec": "0.00",
"read_size_per_sec": "0",
"write_size_per_sec": "0",
"avg_request_size": "0",
"queue_size": "0.00",
"util": "0.00",
"await": "0.00",
"read_await": "0.00",
"write_await": "0.00"
}]
}
The above JSON has been reformatted for line length, but the content
is from dmstats using this change.
Example output of "list" in JSON:
{
"list": [{
"stats_name": "mirrorvg-mirrorlv",
"group_id": "-",
"region_id": "0",
"obj_type": "region",
"region_start": "0",
"region_len": "1.00g",
"area_count": "1",
"area_len": "1.00g",
"program_id": "dmstats"
}]
}
Todd Gill (2):
Add JSON output support to dmstats for list and report subcommands
Update man page to include --reportformat for list and report
subcommands
libdm/dm-tools/dmsetup.c | 45 +++++++++++++++++++++++++++++++++-------
man/dmstats.8_main | 11 ++++++++++
2 files changed, 48 insertions(+), 8 deletions(-)
--
2.21.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* [linux-lvm] [PATCH 1/2] Add JSON output support to dmstats for list and report subcommands
2020-01-24 19:58 [linux-lvm] [PATCH 0/2] JSON output for dmstats Todd Gill
@ 2020-01-24 19:58 ` Todd Gill
2020-01-24 19:58 ` [linux-lvm] [PATCH 2/2] Update man page to include --reportformat " Todd Gill
1 sibling, 0 replies; 3+ messages in thread
From: Todd Gill @ 2020-01-24 19:58 UTC (permalink / raw)
To: linux-lvm; +Cc: tgill
Reuse the dm_report_group[create|push|destroy] framework to create a JSON
formatted output.
Signed-off-by: Todd Gill <tgill@redhat.com>
---
libdm/dm-tools/dmsetup.c | 45 +++++++++++++++++++++++++++++++++-------
1 file changed, 37 insertions(+), 8 deletions(-)
diff --git a/libdm/dm-tools/dmsetup.c b/libdm/dm-tools/dmsetup.c
index 269f86c9b..cab0c85c8 100644
--- a/libdm/dm-tools/dmsetup.c
+++ b/libdm/dm-tools/dmsetup.c
@@ -182,6 +182,7 @@ enum {
HISTOGRAM_ARG,
INACTIVE_ARG,
INTERVAL_ARG,
+ REPORT_FORMAT_ARG,
LENGTH_ARG,
MANGLENAME_ARG,
MAJOR_ARG,
@@ -6153,7 +6154,7 @@ static int _stats_help(CMD_ARGS);
* [--units <u>] [--programid <id>] [--regionid <id>]
* [-o <fields>] [-O|--sort <sort_fields>]
* [-S|--select <selection>] [--nameprefixes]
- * [--noheadings] [--separator <separator>]
+ * [--reportformat basic|json] [--noheadings] [--separator <separator>]
* [--allprograms|--programid id] [<device>...]
* ungroup --groupid <id> [--allprograms|--programid id]
* [--alldevices|<device>...]
@@ -6177,12 +6178,12 @@ static int _stats_help(CMD_ARGS);
#define ALL_PROGS_REGIONS_DEVICES ALL_PROGS_OPT INDENT ALL_REGIONS_OPT INDENT ALL_DEVICES_OPT
#define FIELD_OPTS "[-o <fields>] [-O|--sort <sort_fields>]"
#define DM_REPORT_OPTS FIELD_OPTS INDENT "[-S|--select <selection>] [--nameprefixes]" INDENT \
-"[--noheadings] [--separator <separator>]"
+"[--noheadings] [--reportformat basic|json] [--separator <separator>]"
/* command options */
#define CREATE_OPTS REGION_OPTS INDENT ID_OPTS INDENT EXTRA_OPTS INDENT SEGMENTS_OPT
#define FILEMAP_OPTS "--filemap [--nogroup] " FILE_MONITOR_OPTS INDENT ID_OPTS INDENT EXTRA_OPTS
-#define PRINT_OPTS "[--clear] " ALL_PROGS_REGIONS_DEVICES
+#define PRINT_OPTS "[--clear] [--reportformat basic|json]" ALL_PROGS_REGIONS_DEVICES
#define REPORT_OPTS "[--interval <seconds>] [--count <cnt>]" INDENT \
"[--units <u>] " SELECT_OPTS INDENT DM_REPORT_OPTS INDENT ALL_PROGS_OPT
#define GROUP_OPTS "[--alias NAME] --regions <regions>" INDENT ALL_PROGS_OPT ALL_DEVICES_OPT
@@ -6875,6 +6876,7 @@ static int _process_switches(int *argcp, char ***argvp, const char *dev_dir)
{"regions", 1, &ind, REGIONS_ARG},
{"regionid", 1, &ind, REGION_ID_ARG},
{"relative", 0, &ind, RELATIVE_ARG},
+ {"reportformat", 1, &ind, REPORT_FORMAT_ARG},
{"retry", 0, &ind, RETRY_ARG},
{"rows", 0, &ind, ROWS_ARG},
{"segments", 0, &ind, SEGMENTS_ARG},
@@ -7164,6 +7166,17 @@ static int _process_switches(int *argcp, char ***argvp, const char *dev_dir)
return 0;
}
}
+ if (ind == REPORT_FORMAT_ARG) {
+ _switches[REPORT_FORMAT_ARG]++;
+ if (!strcasecmp(optarg, "basic"))
+ _int_args[REPORT_FORMAT_ARG] = DM_REPORT_GROUP_BASIC;
+ else if (!strcasecmp(optarg, "json"))
+ _int_args[REPORT_FORMAT_ARG] = DM_REPORT_GROUP_JSON;
+ else {
+ log_error("Unknown report format.");
+ return 0;
+ }
+ }
if (ind == MANGLENAME_ARG) {
_switches[MANGLENAME_ARG]++;
if (!strcasecmp(optarg, "none"))
@@ -7307,6 +7320,7 @@ int main(int argc, char **argv)
const struct command *cmd;
const char *subcommand = "";
int multiple_devices;
+ struct dm_report_group *new_report_group = NULL;
(void) setlocale(LC_ALL, "");
@@ -7455,11 +7469,26 @@ doit:
fflush(stdout);
}
if (_report) {
- /* only output headings for repeating reports */
- if (_int_args[COUNT_ARG] != 1 && !dm_report_is_empty(_report))
- dm_report_column_headings(_report);
- dm_report_output(_report);
-
+ if (_switches[REPORT_FORMAT_ARG] &&
+ _int_args[REPORT_FORMAT_ARG] == DM_REPORT_GROUP_JSON &&
+ strcmp(cmd->name, "stats") == 0) {
+ if (!(new_report_group = dm_report_group_create(DM_REPORT_GROUP_JSON, NULL))) {
+ log_error("Failed to create stats report group.");
+ return 0;
+ }
+ if (!(dm_report_group_push(new_report_group, _report, (void *) subcommand))) {
+ log_error("Failed to add stats report to report group.");
+ return 0;
+ }
+ dm_report_output(_report);
+ if (!dm_report_group_destroy(new_report_group))
+ return 0;
+ } else {
+ /* only output headings for repeating reports */
+ if (_int_args[COUNT_ARG] != 1 && !dm_report_is_empty(_report))
+ dm_report_column_headings(_report);
+ dm_report_output(_report);
+ }
if (_count > 1 && r) {
putchar('\n');
fflush(stdout);
--
2.21.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [linux-lvm] [PATCH 2/2] Update man page to include --reportformat for list and report subcommands
2020-01-24 19:58 [linux-lvm] [PATCH 0/2] JSON output for dmstats Todd Gill
2020-01-24 19:58 ` [linux-lvm] [PATCH 1/2] Add JSON output support to dmstats for list and report subcommands Todd Gill
@ 2020-01-24 19:58 ` Todd Gill
1 sibling, 0 replies; 3+ messages in thread
From: Todd Gill @ 2020-01-24 19:58 UTC (permalink / raw)
To: linux-lvm; +Cc: tgill
Add text to explain the use of new --reportformat option.
Signed-off-by: Todd Gill <tgill@redhat.com>
---
man/dmstats.8_main | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/man/dmstats.8_main b/man/dmstats.8_main
index da9d93490..81bd2408d 100644
--- a/man/dmstats.8_main
+++ b/man/dmstats.8_main
@@ -156,6 +156,8 @@ dmstats \(em device-mapper statistics management
. RB [ --units
. IR units ]
. OPT_OBJECTS
+. RB [ --reportformat
+. IR basic | json ]
. RB \%[ --nosuffix ]
. RB [ --notimesuffix ]
. RB \%[ -v | --verbose]
@@ -192,6 +194,8 @@ dmstats \(em device-mapper statistics management
. OPT_PROGRAMS
. OPT_REGIONS
. OPT_OBJECTS
+. RB [ --reportformat
+. IR basic | json ]
. RB [ -O | --sort
. IR sort_fields ]
. RB [ -S | --select
@@ -506,6 +510,13 @@ If displaying the histogram report show relative (percentage) values
instead of absolute counts.
.
.HP
+.BR \-\-reportformat
+.RB [ basic | json ]
+.br
+Specify the output format for list and report subcommands. The \fBjson\fP
+option produces report output in JSON format.
+.
+.HP
.BR -S | --select
.IR selection
.br
--
2.21.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-01-24 19:58 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-24 19:58 [linux-lvm] [PATCH 0/2] JSON output for dmstats Todd Gill
2020-01-24 19:58 ` [linux-lvm] [PATCH 1/2] Add JSON output support to dmstats for list and report subcommands Todd Gill
2020-01-24 19:58 ` [linux-lvm] [PATCH 2/2] Update man page to include --reportformat " Todd Gill
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).