static void dump_stat(struct rtnl_link *link, int id) { uint64_t st = rtnl_link_get_stat(link, id); char buf[64]; printf("%s.%s %" PRIu64 "\n", rtnl_link_get_name(link), rtnl_link_stat2str(id, buf, sizeof(buf)), st); }
static void list_stat_names(void) { char buf[64]; int i; for (i = 0; i < RTNL_LINK_STATS_MAX; i++) printf("%s\n", rtnl_link_stat2str(i, buf, sizeof(buf))); exit(0); }
Result<hashmap<string, uint64_t> > statistics(const string& _link) { Result<Netlink<struct rtnl_link> > link = internal::get(_link); if (link.isError()) { return Error(link.error()); } else if (link.isNone()) { return None(); } rtnl_link_stat_id_t stats[] = { // Statistics related to receiving. RTNL_LINK_RX_PACKETS, RTNL_LINK_RX_BYTES, RTNL_LINK_RX_ERRORS, RTNL_LINK_RX_DROPPED, RTNL_LINK_RX_COMPRESSED, RTNL_LINK_RX_FIFO_ERR, RTNL_LINK_RX_LEN_ERR, RTNL_LINK_RX_OVER_ERR, RTNL_LINK_RX_CRC_ERR, RTNL_LINK_RX_FRAME_ERR, RTNL_LINK_RX_MISSED_ERR, RTNL_LINK_MULTICAST, // Statistics related to sending. RTNL_LINK_TX_PACKETS, RTNL_LINK_TX_BYTES, RTNL_LINK_TX_ERRORS, RTNL_LINK_TX_DROPPED, RTNL_LINK_TX_COMPRESSED, RTNL_LINK_TX_FIFO_ERR, RTNL_LINK_TX_ABORT_ERR, RTNL_LINK_TX_CARRIER_ERR, RTNL_LINK_TX_HBEAT_ERR, RTNL_LINK_TX_WIN_ERR, RTNL_LINK_COLLISIONS, }; hashmap<string, uint64_t> results; char buf[32]; size_t size = sizeof(stats) / sizeof(stats[0]); for (size_t i = 0; i < size; i++) { rtnl_link_stat2str(stats[i], buf, 32); results[buf] = rtnl_link_get_stat(link.get().get(), stats[i]); } return results; }