0

I would like to capture the bandwidth usage to and from one specific remote machine across time on my system. iftop command is definitely one option, which gives the network usage, and has filtering , but I need to parse the text output to get the incoming bandwidth usage and outgoing bandwidth usage.

sudo iftop -t -s 2 -f "src host <remote_machine_ip>"

My current plan is to run the above command in a loop, parse the text output each time and append to a csv file (current_time, transmitted, received).

Is there a better alternative ?

Akheel K M
  • 11
  • 1
  • 1
    Possible duplicate of https://unix.stackexchange.com/questions/327577/how-to-gather-full-network-usage-statistics-on-a-freebsd-router/327585#327585 – Rui F Ribeiro Aug 30 '19 at 14:19

1 Answers1

0

Have you considered using the "sar" tool, which periodically collects network, cpu, memory, and other resource data and stores it for later use? I believe most distributions have a 10-minute delay between polls to avoid being to intrusive, and storing too much data.

On my RHEL box I simply installed the "sysstat" RPM which provides the /usr/bin/sar command and waited a few minutes for data to be collected. Then I could review the data like this:

P.S. You can reconfigure the polling frequency by adjusting the crontab file in /etc/cron.d/sysstat

P.P.S. The sar data is kept for 30 days by default. You can review older data by telling sar what file to use with the "-f /var/log/sa/saXY" argument where XY is the two-digit day you're interested in (e.g. 12)

[jcall@nas ~]$ sar -n DEV | grep enp4s0
12:10:01 AM    enp4s0      4.86      2.33      1.06      0.25      0.00      0.00      1.11
12:20:01 AM    enp4s0      4.70      2.32      1.05      0.26      0.00      0.00      1.07
12:30:01 AM    enp4s0      4.73      2.25      1.06      0.27      0.00      0.00      1.01
12:40:01 AM    enp4s0      5.32      2.76      1.49      0.39      0.00      0.00      0.97
12:50:01 AM    enp4s0      4.57      2.22      1.01      0.25      0.00      0.00      0.90
01:00:01 AM    enp4s0      4.71      2.32      1.02      0.27      0.00      0.00      1.08
01:10:01 AM    enp4s0      4.60      2.29      1.03      0.28      0.00      0.00      0.97
01:20:01 AM    enp4s0      4.63      2.21      1.04      0.26      0.00      0.00      0.94
01:30:01 AM    enp4s0      4.68      2.18      1.07      0.25      0.00      0.00      0.97
01:40:01 AM    enp4s0      4.70      2.20      1.08      0.25      0.00      0.00      0.99
01:50:01 AM    enp4s0     10.28      2.72      1.43      0.35      0.00      0.00      0.88
02:00:01 AM    enp4s0      4.69      2.29      1.02      0.27      0.00      0.00      1.05
02:10:01 AM    enp4s0      4.80      2.26      1.08      0.25      0.00      0.00      1.03
02:20:01 AM    enp4s0      4.77      2.26      1.08      0.26      0.00      0.00      0.96
02:30:01 AM    enp4s0      4.96      2.42      1.09      0.33      0.00      0.00      0.97
02:40:01 AM    enp4s0      4.99      2.37      1.06      0.32      0.00      0.00      1.08
Average:       enp4s0      5.13      2.34      1.10      0.28      0.00      0.00      1.00
John Call
  • 166
  • 6