Fix iftop experimental traffic fetcher, unify and improve output style
There were several problems with iftop fetcher.
Although it offered IPv6 unlike "rate" tool, its output is limited to approx. 10 lines of traffic source-destination pairs. If there are many slower connections from the same hosts, only a few are visible. The traffic is added up by same IP, but a lot of data could be omitted including showing less traffic the host uses. My change adds support for source and destination grouping for interfaces where you could expect local clients with many connections. It tries to recognize these interfaces by checking if the DHCP server is enabled for them. Other interfaces don't use grouping as it would hide relevant data.
This change needs to make current implementation somewhat more difficult regarding use of temp and pid files. Unfortunately there are no iftop arguments to do grouping without special configuration files.
Current implementation also has problems with response time. Each 3 seconds a new request to refresh data is made. PHP script launches bash script and waits for response. That blocks webserver slots and PHP-fpm slots as each request takes 6+ seconds to complete. Having the Traffic Graph page open makes more and more pending requests in browser, which could cause memory leaks and even crash. This was changed so the data is always taken quickly from file and bash script is launched in background if needed.
There is also a logic for killing old iftop processes on both sides, PHP script and bash script. This was left in bash script only as it is not needed elsewhere.The output view of the table also needs some care.
For better readability the following was changed:
- number columns are aligned to the right
- rounding to two decimals could result in 14 Mbit/s or 14.44 Mbit/s, now it's fixed to two decimals as function states
- letter k as in kilobits was capitalized in iftop's output unlike rate's, now it's lowercase k
- number before Mbits or Gbits is in bold font to be more visible on first sight
#2 Updated by Ashus CZ about 1 month ago
Rounding was fixed to display no decimals with bits or exactly one decimal when kilobits or larger units are used.
If any hosts fail to resolve its name and it is requested, there is an attempt to resolve the name of static route it goes through. This is useful mainly for IPv6 hosts who are on a different network and you would like to know where they are on first look. If Host Name is chosen to display, the name is composed of last two segments of IPv4 or last part of IPv6@RouteName. If FQDN is chosen, the name becomes full IP@RouteName.