From 905b114f121889dbf3f137dc6716ebcffc4765a0 Mon Sep 17 00:00:00 2001 From: David Schweikert Date: Mon, 22 Dec 2025 15:42:11 +0100 Subject: [PATCH] JSON: rename globalSum to "stats" and avoid spaces in key names. --- ci/test-16-json-output.pl | 2 +- doc/fping-json.md | 26 ++++++++++++-------------- src/fping.c | 20 ++++++++++---------- 3 files changed, 23 insertions(+), 25 deletions(-) diff --git a/ci/test-16-json-output.pl b/ci/test-16-json-output.pl index 849102a..02e9fc6 100644 --- a/ci/test-16-json-output.pl +++ b/ci/test-16-json-output.pl @@ -180,7 +180,7 @@ $cmd->stderr_is_eq(""); my $cmd = Test::Command->new(cmd => "fping -J -s -q -c 2 127.0.0.1"); $cmd->exit_is_num(0); $cmd->stdout_like(qr/^\{"summary":\s\{"host":\s"127\.0\.0\.1",\s"xmt":\s\d+,\s"rcv":\s\d+,\s"loss":\s\d+,\s"rttMin":\s\d+\.\d+,\s"rttAvg":\s\d+\.\d+,\s"rttMax":\s\d+\.\d+\}\} -\{"globalSum":\s\{"targets":\s\d+,\s"alive":\s\d+,\s"unreachable":\s\d+,\s"unknown\saddresses":\s\d+,\s"timeouts\s\(waiting\sfor\sresponse\)":\s\d+,\s"ICMP\sEchos\ssent":\s\d+,\s"ICMP\sEcho\sReplies\sreceived":\s\d+,\s"other\sICMP\sreceived":\s0,\s"ms\s\(min\sround\strip\stime\)":\s\d+\.\d+,\s"ms\s\(avg\sround\strip\stime\)":\s\d+\.\d+,\s"ms\s\(max\sround\strip\stime\)":\s\d+\.\d+,\s"sec\s\(elapsed\sreal\stime\)":\s\d+\.\d+\}\}?$/); +\{"stats":\s\{"targets":\s\d+,\s"alive":\s\d+,\s"unreachable":\s\d+,\s"unknownAddresses":\s\d+,\s"timeouts":\s\d+,\s"icmpEchosSent":\s\d+,\s"icmpEchoRepliesReceived":\s\d+,\s"otherIcmpReceived":\s0,\s"rttMin":\s\d+\.\d+,\s"rttAvg":\s\d+\.\d+,\s"rttMax":\s\d+\.\d+,\s"elapsed":\s\d+\.\d+\}\}?$/); $cmd->stderr_is_eq(""); } diff --git a/doc/fping-json.md b/doc/fping-json.md index 7bc9682..aa156cb 100644 --- a/doc/fping-json.md +++ b/doc/fping-json.md @@ -53,7 +53,7 @@ JSON object: - `timeout`: Timeout waiting for a packet response. - `summary`: Summary statistics for a host (used with `-c`). - `vSum`: Summary of all RTT values for a host (used with `-C`). -- `globalSum`: Global statistics for the entire run (used with `-s`). +- `stats`: Global statistics for the entire run (used with `-s`). - `intSum`: Interval summary statistics (used with `-Q`). ### `resp`: Response @@ -163,27 +163,25 @@ Generated periodically when using `-Q` (quiet with interval reporting). - `time`: Unix timestamp of the report. - Other fields are similar to `summary`. -### `globalSum`: Global Summary +### `stats`: Overall Statistics Generated at end of execution when using `-s` (stats). ```json { - "globalSum": { + "stats": { "targets": 1, "alive": 1, "unreachable": 0, - "unknown addresses": 0, - "timeouts (waiting for response)": 0, - "ICMP Echos sent": 5, - "ICMP Echo Replies received": 5, - "other ICMP received": 0, - "ms (min round trip time)": 0.045, - "ms (avg round trip time)": 0.062, - "ms (max round trip time)": 0.081, - "sec (elapsed real time)": 5.012 + "unknownAddresses": 0, + "timeouts": 0, + "icmpEchosSent": 5, + "icmpEchoRepliesReceived": 5, + "otherIcmpReceived": 0, + "rttMin": 0.045, + "rttAvg": 0.062, + "rttMax": 0.081, + "elapsed": 5.012 } } ``` - -Contains aggregate statistics for the entire fping run. diff --git a/src/fping.c b/src/fping.c index 5ca1ec9..965b946 100644 --- a/src/fping.c +++ b/src/fping.c @@ -2608,15 +2608,15 @@ void print_global_stats(void) void print_global_stats_json(void) { - fprintf(stdout, "{\"globalSum\": {"); + fprintf(stdout, "{\"stats\": {"); fprintf(stdout, "\"targets\": %d, ", num_hosts); fprintf(stdout, "\"alive\": %d, ", num_alive); fprintf(stdout, "\"unreachable\": %d, ", num_unreachable); - fprintf(stdout, "\"unknown addresses\": %d, ", num_noaddress); - fprintf(stdout, "\"timeouts (waiting for response)\": %d, ", num_timeout); - fprintf(stdout, "\"ICMP Echos sent\": %d, ", num_pingsent); - fprintf(stdout, "\"ICMP Echo Replies received\": %d, ", num_pingreceived); - fprintf(stdout, "\"other ICMP received\": %d, ", num_othericmprcvd); + fprintf(stdout, "\"unknownAddresses\": %d, ", num_noaddress); + fprintf(stdout, "\"timeouts\": %d, ", num_timeout); + fprintf(stdout, "\"icmpEchosSent\": %d, ", num_pingsent); + fprintf(stdout, "\"icmpEchoRepliesReceived\": %d, ", num_pingreceived); + fprintf(stdout, "\"otherIcmpReceived\": %d, ", num_othericmprcvd); if (total_replies == 0) { min_reply = 0; @@ -2625,10 +2625,10 @@ void print_global_stats_json(void) sum_replies = 0; } - fprintf(stdout, "\"ms (min round trip time)\": %s, ", sprint_tm(min_reply)); - fprintf(stdout, "\"ms (avg round trip time)\": %s, ", sprint_tm(sum_replies / total_replies)); - fprintf(stdout, "\"ms (max round trip time)\": %s, ", sprint_tm(max_reply)); - fprintf(stdout, "\"sec (elapsed real time)\": %.3f", (end_time - start_time) / 1e9); + fprintf(stdout, "\"rttMin\": %s, ", sprint_tm(min_reply)); + fprintf(stdout, "\"rttAvg\": %s, ", sprint_tm(sum_replies / total_replies)); + fprintf(stdout, "\"rttMax\": %s, ", sprint_tm(max_reply)); + fprintf(stdout, "\"elapsed\": %.3f", (end_time - start_time) / 1e9); fprintf(stdout, "}}\n"); } -- 2.43.0