[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

ppptraf v0.1 Weinberger



Hello,

J'ai le plaisir de vous ennuyer encore une fois pour vous annoncer la premiere
ebauche de ppptraf. Comme son nom ne l'indique peut etre pas, ppptraf calcule,
sur base du fichier log de pppd, le nombre de Mb en sortie et en entree.

ppptraf dispose des memes options que ppptime (ce qui en facilite grandement
l'utilisation, n'est-ce pas... :)
Ce qui nous donne:

<poor ascii art>

		<sans preciser le mois -> mois courant>
		
		lanfeust:~/pppt # ./ppptraf -f /var/log/messages
traf in-> 	84.15 11.38 	<- traf out
		lanfeust:~/pppt #
		
		</sans preciser le mois -> mois courant>


		
		<en precisant le mois>

		lanfeust:~/pppt # ./ppptraf -f /var/log/messages -m Jun
		17.71 1.66
		lanfeust:~/pppt #

		</en precisant le mois>



		<verbose mode on>

		lanfeust:~/pppt # ./ppptraf -f /var/log/messages -m Jun -v
		traffic in/out: 17.71 1.66
		avg/connect (54): 0.33 0.03
		avg/day (10): 1.77 0.17
		lanfeust:~/pppt #

		</verbose mode on>



		<list mode on>
		Date			In	Out
		|			|	|
		V			V	V
		Jun 28 01:23:58         0.07    0.01
		Jun 28 01:31:04         0.01    0.00
		Jun 29 00:36:24         0.34    0.06
		Jun 29 00:58:05         0.00    0.01
		Jun 29 00:20:59         1.66    0.08
		Jun 29 01:42:19         0.05    0.01
		Jun 29 02:16:17         0.02    0.00
		Jun 29 02:43:08         0.04    0.01
		Jun 29 03:05:32         0.04    0.01
		Jun 30 20:04:58         0.19    0.02
		Jun 30 23:56:16         0.01    0.00
		=== == ========         ====    ====
# de jours->	10                      17.71   1.66 	<- total in/out
		lanfeust:~/pppt #

		</list mode on>



		<help message>
		
		lanfeust:~/pppt # ./ppptraf -h
		Usage: ppptraf [-h] | [-vl] [-f file] [-m month]
		  -f file       path to pppd log file
		  -h            display help message and exit successfully
		  -l            list detail for each connection
		  -m month      search file for month.
		  -v            verbose mode
		  if no file is given, ppptraf will read from stdin.
		  if no month is given, ppptraf will consider the entire log file
		lanfeust:~/pppt #

		</help message>

</poor ascii art>		
2 choses:
	- c'est une ebauche qui pourra etre amelioree. Cependant je pense
	qu'elle est fonctionnelle
	- Toutes les tailles sont exprimées en megabyte.
Voila. Des questions ? commentaires ? suggestions ? bugs ?


--
Life is hard but the root password helps.
		-- Anonymous

Gregoire Welraeds
<gregoire (at) welraeds (dot) be>
#!/bin/sh

# ppptraf by Grégoire Welraeds <gregoire@welraeds.be>
# v0.1  Weinberger
#
# calculate pppd in/out traffic
#
# Jully 2001

# thanks to Jacques L'helgoualc'h <lhh@free.fr> for this little tips about
# LOCALE and  grep.
# thanks also to many helpers from debian-french@lists.debian.org for
# new ideas.

# disable all locale.
LC_ALL=C

# Set default value
VERBOSE=0
LIST=0
FILE="-"

usage()
{
cat << _EOF_
Usage: ppptraf [-h] | [-vl] [-f file] [-m month]
Try 'ppptraf -h' for more information.
_EOF_
}

help()
{
cat << _EOF_
Usage: ppptraf [-h] | [-vl] [-f file] [-m month]
  -f file       path to pppd log file
  -h            display help message and exit successfully
  -l            list detail for each connection
  -m month      search file for month.
  -v            verbose mode
  if no file is given, ppptraf will read from stdin.
  if no month is given, ppptraf will consider the entire log file
_EOF_
}

TEMP=`getopt f:hlm:v "$@"`
if [ $? != 0 ] ; then usage >&2 ; exit 1 ; fi

eval set -- "$TEMP"

while test 1
do
        case $1 in
                -f) FILE=$2; shift 2;;
                -l) LIST=1; shift ;;
                -m) MONTH=$2; shift 2 ;;
                -v) VERBOSE=1; shift ;;
                -h) help ; exit 1 ;;
                --) shift ; test $1 || break ;;
                 *) echo "invalid option $1"; usage ; exit -1 ;;
        esac
done

# test if $FILE exist and is readable
if test ${FILE}; then
        if ! test -r ${FILE}; then
                echo Can\'t read ${FILE};
                usage;
                exit -1
        fi
fi

grep "^${MONTH}.*pppd.*Sent" ${FILE} | awk -v verbose=${VERBOSE} -v list=${LIST} '
BEGIN {
	totalin=0
	totalout=0
	connectcount= 0
	daycount= 0
	day=""
}
{
	if ( day != $2 )
	{
		day= $2
		daycount++
	}

	connectcount++

	trafin= $10/1048576
	trafout= $7/1048576

	totalin += trafin
	totalout += trafout

	if ( list )
		printf("%s %2s %s\t\t%.2f\t%.2f\n", $1, $2, $3, trafin, trafout)
}
END { 
	if ( list )
	{
		printf("=== == ========\t\t====\t====\n")
		printf("%2d             \t\t%.2f\t%.2f\n", daycount, 
			totalin,
			totalout)
		if ( verbose )
			print ""
	}
	if ( verbose )
		printf("traffic in/out: ")
	if ( verbose || ! list )
		printf("%.3f %.2f\n",  totalin, totalout)
	if ( verbose )
	{
		printf("avg/connect (%d): %.2f %.2f\n", 
			connectcount,
			totalin/connectcount, 
			totalout/connectcount) 
		printf("avg/day (%d): %.2f %.2f\n", 
			daycount,
			totalin/daycount,
			totalout/daycount) 
	}
}
'

Reply to: