Network interface counters: /proc/net/dev (or macOS's 64-bit if_data), wrap-safe totals, NIC records
$ sexc add @ajax/mesh-nic- total 3
- drwxr-xr-x-../
- drwxr-xr-x-Oct 27 05:24v/# 1 version
- drwxr-xr-x-Oct 27 05:24files/# the files of 0.1.0
- latest
- 0.1.0, published Oct 27 05:24 by ajax
- owners
- ajax
- license
- MIT
- dependencies
- @ajax/mesh-abi-host-nics ^0.1.0, @ajax/mesh-buf ^0.1.0, @ajax/mesh-check ^0.1.0
- dependents
- @ajax/mesh-samplers
- keywords
- mesh alphaos network interfaces proc
- homepage
- https://github.com/thomasdavis/alpha-c-mesh/tree/main/packages/mesh-nic
- repository
- https://github.com/thomasdavis/alpha-c-mesh
1# @ajax/mesh-nic 2 3Network interface counters: /proc/net/dev (or macOS's 64-bit if_data), wrap-safe totals, NIC records. 4 5The machine's network interfaces' counters (net.rs, "Network I/O"). 6 7Read once a second: Linux /proc/net/dev, macOS the routing sysctl's 64-bit if_data64. Each OS counter is extended to a monotonic u64 (a narrower one that went down wrapped; a 64-bit one that went down was reset), and a total sums every physical interface (mesh-abi NET_VIRTUAL prefixes left out) that never goes down. NIC records (NI_*) are what the host block publishes. 8 9```c 10#include "mesh/nic.h" 11``` 12 13## Ported from 14 15[alpha-rust-mesh](https://github.com/rsafier/alpha-rust-mesh) (Richard Safier, MIT): crates/mesh-host/src/net.rs: `NIC_COUNTERS`, `Raw`, `Ext`, `parse_proc_net_dev`, `read_interfaces` (Linux and macOS), `iface_of`, `Nics`, `nic_record`. 16 17## Tests 18 19- `tests/nic.c`: net.rs's `proc_net_dev`, `ext_wraps_and_resets`, `total_is_monotonic_and_skips_virtual`, `loopback_address_is_on_lo`, `this_machine_has_interfaces`, `nic_record_layout`. 20 21## Differences 22 23- The macOS reader (`NET_RT_IFLIST2`) is ported but untested: there is no Mac here. 24- `Nics::sample`'s map is returned as an array in the OS's order, looked up by name (`mesh_nic_lookup`); the Rust returns a `BTreeMap`. 25 26## Licence 27 28MIT. See the repository's LICENSE.