make delta counters an opt-in property

Signed-off-by: John Crispin <john@phrozen.org>
This commit is contained in:
John Crispin
2022-01-12 07:44:15 +01:00
parent b5a68ca17b
commit 065f75cb88
3 changed files with 56 additions and 24 deletions

View File

@@ -146,7 +146,7 @@ static int get_counter_delta(__u32 new, __u32 old)
}
void
iface_dump(void)
iface_dump(int delta)
{
struct iface *iface;
@@ -176,28 +176,43 @@ iface_dump(void)
blobmsg_close_array(&b, d);
}
d = blobmsg_open_table(&b, "stats");
blobmsg_add_u32(&b, "rx_packets",
get_counter_delta(iface->stats.rx_packets, iface->stats_old.rx_packets));
blobmsg_add_u32(&b, "tx_packets",
get_counter_delta(iface->stats.tx_packets, iface->stats_old.tx_packets));
blobmsg_add_u32(&b, "rx_bytes",
get_counter_delta(iface->stats.rx_bytes, iface->stats_old.rx_bytes));
blobmsg_add_u32(&b, "tx_bytes",
get_counter_delta(iface->stats.tx_bytes, iface->stats_old.tx_bytes));
blobmsg_add_u32(&b, "rx_errors",
get_counter_delta(iface->stats.rx_errors, iface->stats_old.rx_errors));
blobmsg_add_u32(&b, "tx_errors",
get_counter_delta(iface->stats.tx_errors, iface->stats_old.tx_errors));
blobmsg_add_u32(&b, "rx_dropped",
get_counter_delta(iface->stats.rx_dropped, iface->stats_old.rx_dropped));
blobmsg_add_u32(&b, "tx_dropped",
get_counter_delta(iface->stats.tx_dropped, iface->stats_old.tx_dropped));
blobmsg_add_u32(&b, "multicast",
get_counter_delta(iface->stats.multicast, iface->stats_old.multicast));
blobmsg_add_u32(&b, "collisions",
get_counter_delta(iface->stats.collisions, iface->stats_old.collisions));
d = blobmsg_open_table(&b, "counters");
blobmsg_add_u32(&b, "rx_packets", iface->stats.rx_packets);
blobmsg_add_u32(&b, "tx_packets", iface->stats.tx_packets);
blobmsg_add_u32(&b, "rx_bytes", iface->stats.rx_bytes);
blobmsg_add_u32(&b, "tx_bytes", iface->stats.tx_bytes);
blobmsg_add_u32(&b, "rx_errors", iface->stats.rx_errors);
blobmsg_add_u32(&b, "tx_errors", iface->stats.tx_errors);
blobmsg_add_u32(&b, "rx_dropped", iface->stats.rx_dropped);
blobmsg_add_u32(&b, "tx_dropped", iface->stats.tx_dropped);
blobmsg_add_u32(&b, "multicast", iface->stats.multicast);
blobmsg_add_u32(&b, "collisions", iface->stats.collisions);
blobmsg_close_table(&b, d);
if (delta) {
d = blobmsg_open_table(&b, "deltas");
blobmsg_add_u32(&b, "rx_packets",
get_counter_delta(iface->stats.rx_packets, iface->stats_old.rx_packets));
blobmsg_add_u32(&b, "tx_packets",
get_counter_delta(iface->stats.tx_packets, iface->stats_old.tx_packets));
blobmsg_add_u32(&b, "rx_bytes",
get_counter_delta(iface->stats.rx_bytes, iface->stats_old.rx_bytes));
blobmsg_add_u32(&b, "tx_bytes",
get_counter_delta(iface->stats.tx_bytes, iface->stats_old.tx_bytes));
blobmsg_add_u32(&b, "rx_errors",
get_counter_delta(iface->stats.rx_errors, iface->stats_old.rx_errors));
blobmsg_add_u32(&b, "tx_errors",
get_counter_delta(iface->stats.tx_errors, iface->stats_old.tx_errors));
blobmsg_add_u32(&b, "rx_dropped",
get_counter_delta(iface->stats.rx_dropped, iface->stats_old.rx_dropped));
blobmsg_add_u32(&b, "tx_dropped",
get_counter_delta(iface->stats.tx_dropped, iface->stats_old.tx_dropped));
blobmsg_add_u32(&b, "multicast",
get_counter_delta(iface->stats.multicast, iface->stats_old.multicast));
blobmsg_add_u32(&b, "collisions",
get_counter_delta(iface->stats.collisions, iface->stats_old.collisions));
blobmsg_close_table(&b, d);
}
memcpy(&iface->stats_old, &iface->stats, sizeof(iface->stats));
bridge_dump_if(iface->name);