Operating System - HP-UX
1834404 Members
2772 Online
110067 Solutions
New Discussion

Re: MRTG and scripting issue

 
Geoff Wild
Honored Contributor

MRTG and scripting issue

Okay - I'm generating stats for lp requests and ftp requests.

Every now and then - the numbers are skewed - way to large...

My script:

#!/bin/sh
# generate mrtg file for stats
SERVER=`uname -n`
MRTGLP=/tmp/iprprt.lp.stats.mrtg
mv /tmp/LPSTATCUR /tmp/LPSTATOLD
LPSTATOLD=`cat /tmp/LPSTATOLD`
LPSTATCUR=`/usr/bin/grep ^End /var/adm/lp/log |wc -l'`

echo $LPSTATCUR>/tmp/LPSTATCUR

LPSTATNEW=`expr $LPSTATCUR - $LPSTATOLD`

echo $LPSTATNEW > $MRTGLP
echo 0 >> $MRTGLP
uptime | awk '{print $3,$4,$5}' |sed s/,//g >>$MRTGLP
echo $SERVER >>$MRTGLP


MRTGFTP=/tmp/iprdbci.ftp.stats.mrtg
mv /tmp/FTPSTATCUR /tmp/FTPSTATOLD
FTPSTATOLD=`cat /tmp/FTPSTATOLD`
FTPSTATCUR=`/usr/bin/grep FTP /var/adm/syslog/syslog.log |wc -l`

echo $FTPSTATCUR>/tmp/FTPSTATCUR

FTPSTATNEW=`expr $FTPSTATCUR - $FTPSTATOLD`

echo $FTPSTATNEW > $MRTGFTP
echo 0 >> $MRTGFTP
uptime | awk '{print $3,$4,$5}' |sed s/,//g >>$MRTGFTP
echo $SERVER >>$MRTGFTP


That create 2 files which are uploaded to the MRTG server every 5 minutes.

Contents look like this - most of the time:

# cat /tmp/iprprt.lp.stats.mrtg
18
0
74 days 3:51
svr004

root@pc0004 [ /var/adm/lp ]
# cat /tmp/iprdbci.ftp.stats.mrtg
147
0
74 days 3:51
svr004

On the MRTG server - looking in the log (stat) files, I see numbers like this:


1187041800 344746669 0 51711980689 0
1187041500 51711980689 0 51711980689 0
1187041200 51711980689 0 51711980689 0
1187040900 51711980689 0 51711980689 0
1187040600 51194860884 0 51711980689 0
1187040300 228 0 228 0
1187040000 227 0 228 0


Well - it is pretty obvious that I didn't have 51194860884 ftp connections in 1 5 minute period...

So, I have to manually edit thos files later in order for the graph to look right...

Question is - where did that number come from?

In other words - is my script flawed?
Can it be improved?

No matter how many times I run it manually - I can not duplicate the error...

Rgds...Geoff

Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
2 REPLIES 2
Geoff Wild
Honored Contributor

Re: MRTG and scripting issue

Okay - turns out it was my mrtg.cfg file - not the incoming date.

I was using options: nopercent,growright,perhour

Well, the data was already being supplied as the difference between the last 5 minute snapshot.

Mrtg by default treats variable as a counter and calculates the difference between the current and the previous value and divides that by the elapsed time between the last two readings to get the value to be plotted.

With the perhour, it was also multiplying that result by 3600!

So, I changed it to: nopercent, growright, gauge

And from the host I do my own calculation to get a "per hour"

LPSTATNEW=`expr \( $LPSTATCUR - $LPSTATOLD \) \* 12`

Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
Geoff Wild
Honored Contributor

Re: MRTG and scripting issue

See above...
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.