[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20180709194856.18922-4-stephen@networkplumber.org>
Date: Mon, 9 Jul 2018 12:48:50 -0700
From: Stephen Hemminger <stephen@...workplumber.org>
To: netdev@...r.kernel.org
Cc: Stephen Hemminger <sthemmin@...rosoft.com>
Subject: [PATCH iproute2-next 3/9] tc: convert stats print to json
From: Stephen Hemminger <sthemmin@...rosoft.com>
Convert compatiablity statistics to print in JSON.
Signed-off-by: Stephen Hemminger <sthemmin@...rosoft.com>
---
tc/tc_util.c | 32 ++++++++++++++++++++++----------
1 file changed, 22 insertions(+), 10 deletions(-)
diff --git a/tc/tc_util.c b/tc/tc_util.c
index e8e1241d083d..05b6c97563b3 100644
--- a/tc/tc_util.c
+++ b/tc/tc_util.c
@@ -887,25 +887,37 @@ void print_tcstats_attr(FILE *fp, struct rtattr *tb[],
/* handle case where kernel returns more/less than we know about */
memcpy(&st, RTA_DATA(tb[TCA_STATS]), MIN(RTA_PAYLOAD(tb[TCA_STATS]), sizeof(st)));
- fprintf(fp, "%sSent %llu bytes %u pkts (dropped %u, overlimits %u) ",
- prefix, (unsigned long long)st.bytes, st.packets, st.drops,
- st.overlimits);
+ print_string(PRINT_FP, NULL, "%sSent ", prefix);
+ print_u64(PRINT_ANY, "bytes", "%llu bytes ", (unsigned long long)st.bytes);
+ print_uint(PRINT_ANY, "packets", "%u pkts ", st.packets);
+ print_uint(PRINT_ANY, "dropped", "(dropped %u, ", st.drops);
+ print_uint(PRINT_ANY, "overlimits", "overlimits %u) ", st.overlimits);
if (st.bps || st.pps || st.qlen || st.backlog) {
- fprintf(fp, "\n%s", prefix);
+ print_string(PRINT_FP, "%s%s", _SL_, prefix);
+
if (st.bps || st.pps) {
- fprintf(fp, "rate ");
+ print_string(PRINT_FP, NULL, "%s", "rate ");
+ print_uint(PRINT_JSON, "rate", NULL, st.bps);
if (st.bps)
- fprintf(fp, "%s ", sprint_rate(st.bps, b1));
+ print_string(PRINT_FP, NULL, "%s ",
+ sprint_rate(st.bps, b1));
+
+ print_uint(PRINT_JSON, "pps", NULL, st.pps);
if (st.pps)
- fprintf(fp, "%upps ", st.pps);
+ print_uint(PRINT_FP, NULL, "%upps ", st.pps);
}
if (st.qlen || st.backlog) {
- fprintf(fp, "backlog ");
+ print_string(PRINT_FP, NULL, "%s", "backlog ");
+
+ print_uint(PRINT_JSON, "backlog", NULL, st.backlog);
+ print_uint(PRINT_JSON, "qlen", NULL, st.qlen);
if (st.backlog)
- fprintf(fp, "%s ", sprint_size(st.backlog, b1));
+ print_string(PRINT_FP, NULL,
+ "%s ", sprint_size(st.backlog, b1));
if (st.qlen)
- fprintf(fp, "%up ", st.qlen);
+ print_uint(PRINT_FP, NULL,
+ "%up ", st.qlen);
}
}
}
--
2.18.0
Powered by blists - more mailing lists