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);

19
ubus.c
View File

@@ -67,7 +67,24 @@ ubus_port_cb(struct ubus_context *ctx, struct ubus_object *obj,
struct ubus_request_data *req, const char *method,
struct blob_attr *msg)
{
iface_dump();
enum {
DUMP_DELTA,
__DUMP_MAX
};
static const struct blobmsg_policy dump_policy[__DUMP_MAX] = {
[DUMP_DELTA] = { .name = "delta", .type = BLOBMSG_TYPE_INT32 },
};
struct blob_attr *tb[__DUMP_MAX];
int delta = 0;
blobmsg_parse(dump_policy, __DUMP_MAX, tb, blob_data(msg), blob_len(msg));
if (tb[DUMP_DELTA])
delta = blobmsg_get_u32(tb[DUMP_DELTA]);
iface_dump(delta);
ubus_send_reply(ctx, req, b.head);
return UBUS_STATUS_OK;

View File

@@ -140,4 +140,4 @@ char *interface_resolve(char *device);
void ethers_init(void);
void iface_dump(void);
void iface_dump(int delta);