Thursday, July 12, 2007

How to generate network load diagrams

Yesterday, someone asked me how I generated the network load diagrams used in the post "SSHFS performance test".

My original idea was to search for a ready to use software, but surfing the web I didn't found anything simple to install a quick to use. So i decided to write some bash lines to generate raw data and OpenOffice (oocalc) to draw the diagrams.

This is the script used to generate raw data:



#!/bin/bash

###################################
#
# Wed Jul 11 11:38:54 CEST 2007
#
# This script is used to generate
# network traffic statistics
#
# Author: Davide Restivo (xgutter@yahoo.it)
#
# Released under GPLv2
#
####################################

E_BAD_ARGS=65

# The default interface
INTF="eth0"

# Default output filename
TMP_FILE=`tempfile`
FILE_OUT="netmon-`basename $TMP_FILE`.out"

# Default delay measurement
TICK="1"

# Usage
function usage () {
echo "Please invoke this script with zero or three arguments."
echo ""
echo "Example:"
echo " $0 "
echo ""
echo "where:"
echo " defaults to eth0"
echo " is automatically generated"
echo " is equal to 1 second"
}

# Let's check command line arguments
if [ $# -eq 0 ]
then
:
elif [ $# -eq 3 ]
then
# Setting parameters
INTF=$1
FILE_OUT=$2
TICK=$3
else
usage
exit $E_BAD_ARGS
fi

################
##### MAIN #####
################
echo "Seconds - Byte sent - Byte received" >> $FILE_OUT

SECONDS_COUNTER="0"
while true;
do
INITIAL_BYTE_SENT=`ifconfig eth0 |grep bytes|cut -d":" -f3|cut -d" " -f1`
INITIAL_BYTE_RECEIVED=`ifconfig eth0 |grep bytes|cut -d":" -f2|cut -d" " -f1`

sleep $TICK

BYTE_SENT=$((`ifconfig eth0 |grep bytes|cut -d":" -f3|cut -d" " -f1` - $INITIAL_BYTE_SENT ))
BYTE_RECEIVED=$((`ifconfig eth0 |grep bytes|cut -d":" -f2|cut -d" " -f1` - $INITIAL_BYTE_RECEIVED ))

TEMP_SECONDS_COUNTER=$(($SECONDS_COUNTER + $TICK))
SECONDS_COUNTER=$TEMP_SECONDS_COUNTER
echo "$SECONDS_COUNTER $BYTE_SENT $BYTE_RECEIVED" >> $FILE_OUT
done

No comments:

Post a Comment