Skip to content

Commit 905b114

Browse files
committed
JSON: rename globalSum to "stats" and avoid spaces in key names.
1 parent 5bfe33f commit 905b114

File tree

3 files changed

+23
-25
lines changed

3 files changed

+23
-25
lines changed

ci/test-16-json-output.pl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@
180180
my $cmd = Test::Command->new(cmd => "fping -J -s -q -c 2 127.0.0.1");
181181
$cmd->exit_is_num(0);
182182
$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+\}\}
183-
\{"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+\}\}?$/);
183+
\{"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+\}\}?$/);
184184
$cmd->stderr_is_eq("");
185185
}
186186

doc/fping-json.md

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ JSON object:
5353
- `timeout`: Timeout waiting for a packet response.
5454
- `summary`: Summary statistics for a host (used with `-c`).
5555
- `vSum`: Summary of all RTT values for a host (used with `-C`).
56-
- `globalSum`: Global statistics for the entire run (used with `-s`).
56+
- `stats`: Global statistics for the entire run (used with `-s`).
5757
- `intSum`: Interval summary statistics (used with `-Q`).
5858

5959
### `resp`: Response
@@ -163,27 +163,25 @@ Generated periodically when using `-Q` (quiet with interval reporting).
163163
- `time`: Unix timestamp of the report.
164164
- Other fields are similar to `summary`.
165165

166-
### `globalSum`: Global Summary
166+
### `stats`: Overall Statistics
167167

168168
Generated at end of execution when using `-s` (stats).
169169

170170
```json
171171
{
172-
"globalSum": {
172+
"stats": {
173173
"targets": 1,
174174
"alive": 1,
175175
"unreachable": 0,
176-
"unknown addresses": 0,
177-
"timeouts (waiting for response)": 0,
178-
"ICMP Echos sent": 5,
179-
"ICMP Echo Replies received": 5,
180-
"other ICMP received": 0,
181-
"ms (min round trip time)": 0.045,
182-
"ms (avg round trip time)": 0.062,
183-
"ms (max round trip time)": 0.081,
184-
"sec (elapsed real time)": 5.012
176+
"unknownAddresses": 0,
177+
"timeouts": 0,
178+
"icmpEchosSent": 5,
179+
"icmpEchoRepliesReceived": 5,
180+
"otherIcmpReceived": 0,
181+
"rttMin": 0.045,
182+
"rttAvg": 0.062,
183+
"rttMax": 0.081,
184+
"elapsed": 5.012
185185
}
186186
}
187187
```
188-
189-
Contains aggregate statistics for the entire fping run.

src/fping.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2608,15 +2608,15 @@ void print_global_stats(void)
26082608

26092609
void print_global_stats_json(void)
26102610
{
2611-
fprintf(stdout, "{\"globalSum\": {");
2611+
fprintf(stdout, "{\"stats\": {");
26122612
fprintf(stdout, "\"targets\": %d, ", num_hosts);
26132613
fprintf(stdout, "\"alive\": %d, ", num_alive);
26142614
fprintf(stdout, "\"unreachable\": %d, ", num_unreachable);
2615-
fprintf(stdout, "\"unknown addresses\": %d, ", num_noaddress);
2616-
fprintf(stdout, "\"timeouts (waiting for response)\": %d, ", num_timeout);
2617-
fprintf(stdout, "\"ICMP Echos sent\": %d, ", num_pingsent);
2618-
fprintf(stdout, "\"ICMP Echo Replies received\": %d, ", num_pingreceived);
2619-
fprintf(stdout, "\"other ICMP received\": %d, ", num_othericmprcvd);
2615+
fprintf(stdout, "\"unknownAddresses\": %d, ", num_noaddress);
2616+
fprintf(stdout, "\"timeouts\": %d, ", num_timeout);
2617+
fprintf(stdout, "\"icmpEchosSent\": %d, ", num_pingsent);
2618+
fprintf(stdout, "\"icmpEchoRepliesReceived\": %d, ", num_pingreceived);
2619+
fprintf(stdout, "\"otherIcmpReceived\": %d, ", num_othericmprcvd);
26202620

26212621
if (total_replies == 0) {
26222622
min_reply = 0;
@@ -2625,10 +2625,10 @@ void print_global_stats_json(void)
26252625
sum_replies = 0;
26262626
}
26272627

2628-
fprintf(stdout, "\"ms (min round trip time)\": %s, ", sprint_tm(min_reply));
2629-
fprintf(stdout, "\"ms (avg round trip time)\": %s, ", sprint_tm(sum_replies / total_replies));
2630-
fprintf(stdout, "\"ms (max round trip time)\": %s, ", sprint_tm(max_reply));
2631-
fprintf(stdout, "\"sec (elapsed real time)\": %.3f", (end_time - start_time) / 1e9);
2628+
fprintf(stdout, "\"rttMin\": %s, ", sprint_tm(min_reply));
2629+
fprintf(stdout, "\"rttAvg\": %s, ", sprint_tm(sum_replies / total_replies));
2630+
fprintf(stdout, "\"rttMax\": %s, ", sprint_tm(max_reply));
2631+
fprintf(stdout, "\"elapsed\": %.3f", (end_time - start_time) / 1e9);
26322632
fprintf(stdout, "}}\n");
26332633
}
26342634

0 commit comments

Comments
 (0)