0

我正在尝试在 BASH 中编写我自己的跟踪,如附件所示。

在此处输入图像描述

特别是我需要跟踪网络历史接收和发送数据。我在哪里可以获得这些网络发送/接收值,它是在文件中还是来自 Linux 中的某些命令?

使用 BASH 我正在尝试实现类似如下的东西:

前任:

/* My 10 seconds timer */ 
t = new javax.swing.Timer(10000, new ActionListener() 
{
    public void actionPerformed(ActionEvent ae) 
    {
    }
}); 

跟进:(好网站: http: //www.debianhelp.co.uk/networktools1.htm

$ sudo apt-get install bwm-ng; 
yum -y install bwm; 

# Show me only plain mode 
$ bwm-ng -o plain

 bwm-ng v0.6 (delay 0.500s); press 'ctrl-c' to end this
 /proc/net/dev
 |         iface                    Rx                   Tx               Total
 ==============================================================================
              lo:       88803.53 KB/s        88803.53 KB/s        88803.53 KB/s
            eth0:           0.13 KB/s            0.13 KB/s            0.13 KB/s
 ------------------------------------------------------------------------------
           total:       88803.66 KB/s        88803.66 KB/s        88803.66 KB/s

# Show only the interface that i need to see
$ bwm-ng -o plain -I eth0

bwm-ng v0.6 (delay 0.500s); press 'ctrl-c' to end this
 /proc/net/dev
 |         iface                    Rx                   Tx               Total
 ==============================================================================
            eth0:           0.13 KB/s            0.13 KB/s            0.13 KB/s
 ------------------------------------------------------------------------------
           total:           0.13 KB/s            0.13 KB/s            0.13 KB/s

# Show only in MB format or KB format
# by skiping -d will default show as KB
$ bwm-ng -o plain -d

bwm-ng v0.6 (delay 0.500s); press 'ctrl-c' to end this
 /proc/net/dev
 /         iface                    Rx                   Tx               Total
 ==============================================================================
              lo:          85.79 MB/s           85.79 MB/s           85.79 MB/s
            eth0:         246.58  B/s          246.58  B/s          246.58  B/s
 ------------------------------------------------------------------------------
           total:          85.79 MB/s           85.79 MB/s           85.79 MB/s

 $ bwm-ng -o plain -N -d | grep total:
      total:           0.00  B/s            0.00  B/s            0.00  B/s
      total:           1.28 MB/s            1.28 MB/s            1.28 MB/s
      total:           1.19 MB/s            1.19 MB/s            1.19 MB/s
      total:           1.19 MB/s            1.19 MB/s            1.19 MB/s


 # another tool i used apt-get install vnstat
 # bwm-ng was doing wrong strange on other interfaces but this one 
 # now showing correct
 $ vnstat -u -i lo 
 $ vnstat -u -i eth0
 $ vnstat 
 $ iftop -i eth0
4

2 回答 2

0

Yon 可以编写自己的脚本来解析:

  • CPU 的top -b -n1输出
  • 内存/交换免费
  • ifconfig eth0 for the network # 用你的设备替换 eth0
于 2011-11-09T13:56:11.077 回答
0

编辑:简单的方法:你总是可以使用mrtgcacti而不是自己做。

否则...每 2 秒将字节输入和输出(按 ctrl+c 使其停止):

default_device=$(awk ' { if ($2 == '00000000') print $1 ; } ' < /proc/net/route)
while true
do
    bytesin=$(grep $default_device /proc/net/dev | cut -d':' -f2 | awk ' { print $1; } ')
    bytesout=$(grep $default_device /proc/net/dev | cut -d':' -f2 | awk ' { print $9; } ')
    echo bytesin=$bytesin bytesout=$bytesout
    sleep 2
done

你会得到这样的输出:

bytesin=622734605 bytesout=1249429296
bytesin=622735091 bytesout=1249429620
bytesin=622735523 bytesout=1249430120
bytesin=622736268 bytesout=1249430481
bytesin=622736874 bytesout=1249430535

这些值是为安装了默认路由的设备获取的。

于 2011-11-09T14:05:16.453 回答