[Xfce4-commits] <xfce4-genmon-plugin:master> Add a new sample script to track bandwidth use
Florian Rivoal
noreply at xfce.org
Thu Feb 24 15:26:05 CET 2011
Updating branch refs/heads/master
to 597c9ed455deb5570e1b59d9e7a088e0862f4401 (commit)
from 5d9618659709b820c73b547b335a8c0c160264ca (commit)
commit 597c9ed455deb5570e1b59d9e7a088e0862f4401
Author: Mike Massonnet <mmassonnet at xfce.org>
Date: Thu Feb 24 09:05:00 2011 +0900
Add a new sample script to track bandwidth use
Addresses bug #5386.
scripts/monBandwidth | 44 ++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 44 insertions(+), 0 deletions(-)
diff --git a/scripts/monBandwidth b/scripts/monBandwidth
new file mode 100755
index 0000000..fec1ec4
--- /dev/null
+++ b/scripts/monBandwidth
@@ -0,0 +1,44 @@
+#!/bin/bash
+
+# An example script for the genmon plugin displaying the bandwidth
+# The first parameter passed to the script is the name of the interface
+
+if=${1:-eth0}
+test -d /sys/class/net/$if || echo "<txt>no $if</txt><tool>No statistics for $i</tool>"
+
+prx=$(cat /sys/class/net/$if/statistics/rx_bytes)
+ptx=$(cat /sys/class/net/$if/statistics/tx_bytes)
+sleep 1
+crx=$(cat /sys/class/net/$if/statistics/rx_bytes)
+ctx=$(cat /sys/class/net/$if/statistics/tx_bytes)
+
+brx=$(($crx - $prx))
+btx=$(($ctx - $ptx))
+
+human_bandwidth () {
+ bandwidth=$1
+ p=0
+ while [ "$bandwidth" -gt "1024" -a "$p" -le "3" ] ; do
+ bandwidth=$(($bandwidth/1024))
+ p=$(($p+1))
+ done
+ case $p in
+ 0)
+ bandwidth="$bandwidth B/s"
+ ;;
+ 1)
+ bandwidth="$bandwidth KB/s"
+ ;;
+ 2)
+ bandwidth="$bandwidth MB/s"
+ ;;
+ esac
+ echo $bandwidth
+}
+
+rx=$(human_bandwidth $brx)
+tx=$(human_bandwidth $btx)
+
+echo "<txt>Rx: $rx - Tx: $tx</txt>"
+echo "<tool>Bandwidth on interface $if</tool>"
+
More information about the Xfce4-commits
mailing list