Learn and Discover Open Source with Daily Genuine Experience. From Coding, Design, Package Management Tweak to Desktop Customization.
 
   
code  

Somebody asked in Debian group about speed monitoring application. There is a good application for this called conky or watch.

Conky is good for desktop decoration. And watch is pretty in Console. For a lightweight portable script, you need to consider to remove any conky/watch dependency.

Actually we can simplified the process for our own use. Using bash script only, and get rid of conky, to make our monitoring script more transparent.


Monitor in loop

The basic of monitoring is pool a data result for each monitoring interval.

 $ watch date

You can do this from bash with this simple while loop.

 $ while sleep 1; do date; done

I know it is weird to have a date while sleeping.


Sample Script, Net Speed

I remember two months ago I have found bash script, combined with answer from stackoverflow, I have rewritten this script for my own purpose.

This script utilize statistic form /sys/class/net/ for dzen2 feed.

Original Source

Rewrite

With slight modification. I remove the dzen stuff. And change the echo to printf. And prepend carriage return.

printf "\r[$RX_text] [$TX_text]"

Complete Script

#!/bin/bash

interface=$(iw dev | grep Interface | awk '{print $2}')

if [ "$interface" ]; then 

  # Read first datapoint
  read TX_prev < /sys/class/net/$interface/statistics/tx_bytes
  read RX_prev < /sys/class/net/$interface/statistics/rx_bytes

  sleep 1

  # Read second datapoint

  read TX_curr < /sys/class/net/$interface/statistics/tx_bytes
  read RX_curr < /sys/class/net/$interface/statistics/rx_bytes

  # compute 
  TX_diff=$((TX_curr-TX_prev))
  RX_diff=$((RX_curr-RX_prev))

  # printout var
  TX_text=$(echo "scale=1; $TX_diff/1024" | bc | awk '{printf "%.1f", $0}')
  RX_text=$(echo "scale=1; $RX_diff/1024" | bc | awk '{printf "%.1f", $0}')

  printf "\r[$RX_text] [$TX_text]      "

fi; 

exit 0

You can see the result in figure below

BASH Monitoring Script


Now you can use, modify, and extend this script for your own purpose.

Thank you for reading


Epsi Nurwijayadi bio photo
By Epsi Nurwijayadi