Internal documentation only
This page has been marked as draft.
Network Plugin - Data Collection and Calculation (internal article)
Related to Copied
This article outlines how the ITRS Network plugin gathers interface data from Linux systems and the logic used to calculate critical performance metrics like error rates and collisions.
Data Collection Sources Copied
The plugin gathers data through the following methods:
-
getifaddrs() / freeifaddrs()
- Information obtained: interface name, IPv4 address, IPv6 address, total RX packets, RX errors, TX packets, TX errors, RX dropped, TX dropped, total collisions, TX bytes, RX bytes.
-
SIOCGIFFLAGS ioctl
- Information obtained:
isLoopback,isInsterfaceUp,isSlave.
- Information obtained:
-
proc/net/bonding
- Information obtained: The master interface and the slave interfaces are bonded together.
-
/sys/class/net/
/… - speed: Card speed (Kernel Version: 2.6.33).
- duplex: Full or Half duplex (Kernel Version: 2.6.33).
- carrier: Link state (Kernel Version: 2.6.12).
Reference: https://www.kernel.org/doc/Documentation/ABI/testing/sysfs-class-net
Note: If
/sys/class/net/<iface>/[speed/duplex/carrier]files are not present, the plugin will useSIOCETHTOOLorSIOCGMIIREGto get the speed, duplex, and link information, depending on the nicTool type specified in the GSE.
Physical Link Attributes (SysFS) Copied
For modern kernels, the plugin queries /sys/class/net/<iface>/ to retrieve hardware-level details:
- Speed: Obtained from
.../speed(Kernel 2.6.33+). - Duplex: Obtained from
.../duplex(Kernel 2.6.33+). - Carrier: Determines the Link state via
.../carrier(Kernel 2.6.12+).
Note: If these SysFS files are unavailable, the plugin falls back to
SIOCETHTOOLorSIOCGMIIREGbased on the nicTool type specified in the Gateway Setup Editor (GSE).
Sampling Logic and Overflow Handling Copied
-
The plugin calculates delta values between samples. To handle potential counter overflows, the following logic is applied:
- $$#define\ CATCH\_OVERFLOW(newValue, oldValue, cachedValue)\ (((newValue) \ge (oldValue))\ ?\ ((newValue) - (oldValue))\ :\ ((cachedValue)))$$
-
Using this macro, the plugin determines the change in packets:
- num_packets_sent = $CATCH\_OVERFLOW(current\to total\_sent\_packets, last\to total\_sent\_packets, last\to noSentPackets)$
- num_packets_recv = $CATCH\_OVERFLOW(current\to total\_recv\_packets, last\to total\_recv\_packets, last\to noRecvPackets)$
- num_collisions = $CATCH\_OVERFLOW(current\to total\_collisions, last\to total\_collisions, last\to noCollisions)$
Metric Computations Copied
Error Rates Copied
The computation for percentSendErrors and percentRecvErrors is the standard percentage computation based on the deltas between sampling.
- percentSendErrors:
- recv_error_rate = 100 * ((double) num_recv_errors / (double) (num_packets_recv + num_recv_errors));
- percentRecvErrors:
- recv_error_rate = 100 * ((double) num_recv_errors / (double) (num_packets_recv + num_recv_errors));
Collision Rates Copied
For percentCollisionsThe plugin computes the standard percentage per sampling and subsequently calculates a moving average based on the last average rate and the current computed rate.
- collision_rate = 100 * ((double) num_collisions / (double) (num_packets_sent + num_collisions));
- collision_rate = getMovingAverage( last->ptrCollisionAverage , collision_rate);