Internal documentation only
This page has been marked as draft.
[INTERNAL] Where does the Network plugin (Linux) get its data from?
The Network plugin uses APIs and Sys FS files to get the Network interface information.
-
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
-
/proc/net/bonding Information obtained: Master interface the slave interfaces are bonded to
-
/sys/class/net/
/… - speed - card speed (KernelVersion: 2.6.33)
- duplex - Full or Half duplex (KernelVersion: 2.6.33)
- carrier - Link state (KernelVersion: 2.6.12)Reference: https://www.kernel.org/doc/Documentation/ABI/testing/sysfs-class-net
-
If /sys/class/net/
/[speed/duplex/carrier] files are not present, the plugin will use SIOCETHTOOL or SIOCGMIIREG to get the speed, duplex, and link information, depending on the nicTool type specified in the GSE -
The plugin gets delta values between samples
#define CATCH_OVERFLOW(newValue, oldValue, cachedValue) (((newValue) >= (oldValue)) ? ((newValue) - (oldValue)) : ((cachedValue)))
num_packets_sent = CATCH_OVERFLOW(current->total_sent_packets, last->total_sent_packets, last->noSentPackets);
num_packets_recv = CATCH_OVERFLOW(current->total_recv_packets, last->total_recv_packets, last->noRecvPackets);
num_collisions = CATCH_OVERFLOW(current->total_collisions, last->total_collisions, last->noCollisions);
To get these metrics: // percentSendErrors
sent_error_rate = 100 * ((double) num_send_errors / (double) (num_packets_sent + num_send_errors));
// percentRecvErrors
recv_error_rate = 100 * ((double) num_recv_errors / (double) (num_packets_recv + num_recv_errors));
// percentCollisions
collision_rate = 100 * ((double) num_collisions / (double) (num_packets_sent + num_collisions));
collision_rate = getMovingAverage( last->ptrCollisionAverage , collision_rate);
The computation for percentSendErrors and percentRecvErrors is the standard percentage computation based on the deltas between sampling. While for percentCollisions, the plugin computes for the standard percentage per sampling, and subsequently gets the moving average based on the last average rate of collision and the current computed rate.
In case you’re interested, below are the debug flags to use:
<debug> <debug> <module module="NETWORK" sampler=""> <setting>packets</setting> </module> <module module="NETWORK"> <setting>\*</setting> </module> </debug> </debug>
These flags will show debug entries similar to below for each host’s interface in each plugin’s sampling.
2020-11-04 14:00:01.009+0800 DEBUG: NETWORK[Network Plugin]:list Updating stats for ens32 in list.
2020-11-04 14:00:01.009+0800 DEBUG: NETWORK[Network Plugin]:NETWORK[Network Plugin] [ens32] UPDATING NETWORK STATISTICS…
2020-11-04 14:00:01.009+0800 DEBUG: NETWORK[Network Plugin]:NETWORK[Network Plugin] sendPackets = 82
2020-11-04 14:00:01.009+0800 DEBUG: NETWORK[Network Plugin]:NETWORK[Network Plugin] recvPackets = 215
2020-11-04 14:00:01.009+0800 DEBUG: NETWORK[Network Plugin]:NETWORK[Network Plugin] collisions = 0
2020-11-04 14:00:01.009+0800 DEBUG: NETWORK[Network Plugin]:NETWORK[Network Plugin] recvErrors = 0
2020-11-04 14:00:01.009+0800 DEBUG: NETWORK[Network Plugin]:NETWORK[Network Plugin] sendErrors = 0
2020-11-04 14:00:01.009+0800 DEBUG: NETWORK[Network Plugin]:NETWORK[Network Plugin] crcErrors = 0
2020-11-04 14:00:01.009+0800 DEBUG: NETWORK[Network Plugin]:NETWORK[Network Plugin] framingErrors = 0
2020-11-04 14:00:01.009+0800 DEBUG: NETWORK[Network Plugin]:NETWORK[Network Plugin] sentBytes = 15118
2020-11-04 14:00:01.009+0800 DEBUG: NETWORK[Network Plugin]:NETWORK[Network Plugin] recvBytes = 19213
2020-11-04 14:00:01.009+0800 DEBUG: NETWORK[Network Plugin]:packets Card Name: ens32
Total Packets Sent: 45249754 Last Total Packets Sent: 45249672 Send Rate: 8.200000 = Packets Sent This Sample: 82.000000 / Time Difference: 10.000000 Total Packets Recv: 160868402 Last Total Packets Recv: 160868187 Recv Rate: 21.500000 = Packets Recv This Sample: 215.000000 / Time Difference: 10.000000The debug flag might show useful logs as well especially while parsing the system files such as /sys/class/net/
/ and /proc/net/bonding. 2021-03-26 14:05:41.101+0800 DEBUG: NETWORK[Network Plugin Custom Name]:list Adding docker0 to list.
2021-03-26 14:05:41.101+0800 DEBUG: NETWORK[Network Plugin Custom Name]:list Adding ens32 to list.
2021-03-26 14:05:41.101+0800 DEBUG: NETWORK[Network Plugin Custom Name]:list Cannot read /sys/class/net/lo/speed.
![]()
The link below contains further information.
http://man7.org/linux/man-pages/man3/getifaddrs.3.html