-
Notifications
You must be signed in to change notification settings - Fork 31
Description
The way that hetrixtools_agent, as of today, parses network interfaces to read network usage is essentially:
cat /proc/net/dev | grep -w "$NIC:" | ...
Suppose that there exists a network interface called eth0, and a second one called not-eth0. Because a hyphen - is not considered to be part of a word by grep, when the agent searches for eth0, the grep matches both eth0 and not-eth0. As a result of the calculations that follow, a very erroneous network usage may then be reported, differing from the accurate values by orders of magnitude.
A proposed trivial fix is to replace the pertinent calls to grep - grep -w "$NIC:" - with awk: awk -v nic="$NIC:" '$1 == nic'. This may be a worthwhile replacement also for the reason that network interfaces are technically allowed to contain a wide variety of characters in their names, including those that have a special meaning to grep - although I have not looked into whether this change is sufficient to make the agent work with networks so unusually named.
This issue was discovered in the course of my employment, and I would like to express gratitude to my employer, Anurit Krzysztof Anczurowski, for allowing this solution to be shared with the community.