mirror of
https://github.com/outbackdingo/udevmand.git
synced 2026-08-25 14:53:42 +00:00
make delta counters an opt-in property
Signed-off-by: John Crispin <[email protected]>
This commit is contained in:
@@ -146,7 +146,7 @@ static int get_counter_delta(__u32 new, __u32 old)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
iface_dump(void)
|
iface_dump(int delta)
|
||||||
{
|
{
|
||||||
struct iface *iface;
|
struct iface *iface;
|
||||||
|
|
||||||
@@ -176,28 +176,43 @@ iface_dump(void)
|
|||||||
blobmsg_close_array(&b, d);
|
blobmsg_close_array(&b, d);
|
||||||
}
|
}
|
||||||
|
|
||||||
d = blobmsg_open_table(&b, "stats");
|
d = blobmsg_open_table(&b, "counters");
|
||||||
blobmsg_add_u32(&b, "rx_packets",
|
blobmsg_add_u32(&b, "rx_packets", iface->stats.rx_packets);
|
||||||
get_counter_delta(iface->stats.rx_packets, iface->stats_old.rx_packets));
|
blobmsg_add_u32(&b, "tx_packets", iface->stats.tx_packets);
|
||||||
blobmsg_add_u32(&b, "tx_packets",
|
blobmsg_add_u32(&b, "rx_bytes", iface->stats.rx_bytes);
|
||||||
get_counter_delta(iface->stats.tx_packets, iface->stats_old.tx_packets));
|
blobmsg_add_u32(&b, "tx_bytes", iface->stats.tx_bytes);
|
||||||
blobmsg_add_u32(&b, "rx_bytes",
|
blobmsg_add_u32(&b, "rx_errors", iface->stats.rx_errors);
|
||||||
get_counter_delta(iface->stats.rx_bytes, iface->stats_old.rx_bytes));
|
blobmsg_add_u32(&b, "tx_errors", iface->stats.tx_errors);
|
||||||
blobmsg_add_u32(&b, "tx_bytes",
|
blobmsg_add_u32(&b, "rx_dropped", iface->stats.rx_dropped);
|
||||||
get_counter_delta(iface->stats.tx_bytes, iface->stats_old.tx_bytes));
|
blobmsg_add_u32(&b, "tx_dropped", iface->stats.tx_dropped);
|
||||||
blobmsg_add_u32(&b, "rx_errors",
|
blobmsg_add_u32(&b, "multicast", iface->stats.multicast);
|
||||||
get_counter_delta(iface->stats.rx_errors, iface->stats_old.rx_errors));
|
blobmsg_add_u32(&b, "collisions", iface->stats.collisions);
|
||||||
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);
|
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));
|
memcpy(&iface->stats_old, &iface->stats, sizeof(iface->stats));
|
||||||
|
|
||||||
bridge_dump_if(iface->name);
|
bridge_dump_if(iface->name);
|
||||||
|
|||||||
@@ -67,7 +67,24 @@ ubus_port_cb(struct ubus_context *ctx, struct ubus_object *obj,
|
|||||||
struct ubus_request_data *req, const char *method,
|
struct ubus_request_data *req, const char *method,
|
||||||
struct blob_attr *msg)
|
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);
|
ubus_send_reply(ctx, req, b.head);
|
||||||
|
|
||||||
return UBUS_STATUS_OK;
|
return UBUS_STATUS_OK;
|
||||||
|
|||||||
+1
-1
@@ -140,4 +140,4 @@ char *interface_resolve(char *device);
|
|||||||
|
|
||||||
void ethers_init(void);
|
void ethers_init(void);
|
||||||
|
|
||||||
void iface_dump(void);
|
void iface_dump(int delta);
|
||||||
|
|||||||
Reference in New Issue
Block a user