如何使用shell脚本创建图形

时间:2014-12-19 13:16:05

标签: shell unix graph visualization

我通过运行脚本在下面的文本文件中写入数据。这些数据每秒更新一次。

eth0: Sent Bytes: 1 Kb/s | Received Bytes: 2 Kb/s | Sent Packets: 18 Pkts/s | Received Packets: 13 Pkts/s
eth0: Sent Bytes: 1 Kb/s | Received Bytes: 2 Kb/s | Sent Packets: 18 Pkts/s | Received Packets: 12 Pkts/s
eth0: Sent Bytes: 1 Kb/s | Received Bytes: 3 Kb/s | Sent Packets: 20 Pkts/s | Received Packets: 13 Pkts/s
eth0: Sent Bytes: 15 Kb/s | Received Bytes: 4 Kb/s | Sent Packets: 33 Pkts/s | Received Packets: 25 Pkts/s
eth0: Sent Bytes: 1 Kb/s | Received Bytes: 3 Kb/s | Sent Packets: 19 Pkts/s | Received Packets: 12 Pkts/s

我想制作一个发送字节数和接收字节数的图表。数据包也一样。

1 个答案:

答案 0 :(得分:2)

您可以使用https://github.com/holman/spark创建仅包含shell脚本的图表(尽管它仅适用于bash而不适用于POSIX sh)。您可以使用watch实时更新。

<强> graph.sh

!/bin/sh
field=1
tail "$1" | cut -d '|' -f $field | sed -e 's!.*: \([0-9]\+\) .*!\1!' | ./spark/spark

交互式控制台

git clone https://github.com/holman/spark
your-process > logfile &
watch sh graph.sh logfile

<强>输出

Every 2.0s: sh graph.sh logfile          Fri Dec 19 22:22:04 2014

▁▁▁█▁