[mrtg] how to have fix value in mrtg output

Nelson Serafica ntserafica at yahoo.com
Mon Nov 19 05:14:05 CET 2007


Actually, its a simple script. I'm not also a programmer.

#!/bin/sh
file=/usr/local/apache2/htdocs/mrtg/clients/Link/10.10.0.222.110.html
com2=`cat $file  | egrep "kb/s|b/s" | awk 'NR == 3 {print}' | awk -F\> '{print $2}'  |awk -F\( '{print $1}'` 
com3=`cat $file  | egrep "kb/s|b/s" | awk 'NR == 6 {print}' | awk -F\> '{print $2}'  |awk -F\( '{print $1}'` 
time=`date +%F\ %k:%M`
time1=`date +%F`

echo "TIME : $time Current IN  : $com2 | Current OUT : $com3" >> /home1/usr1/nelsonts/coloc_script/chatlink_$time1.txt

I cron the script every 5 minutes so it gets what you see in Current In/Out.

It would be much easier if I could have the value in kb/s or in b/s. It just could be the two of  them.

Any advise?




----- Original Message ----
From: Luis Carlos Solano <lsolano at racsa.co.cr>
To: mrtg at lists.oetiker.ch
Sent: Monday, November 19, 2007 11:48:21 AM
Subject: Re: [mrtg] how to have fix value in mrtg output



Nelson Serafica wrote:
> I need to dump the current in/out to a text file every 5 minutes. I 
> already create script but the problem is mrtg provide output in a 
> different value. Sometimes it is in kb/s. Sometimes it is in b/s. I 
> need it to be fix. I need to sort the traffic by kb/s/

I'd recommend do the "fix" in your script, not in MRTG.

I mean: if you're using -for example- php, you can "explode" the line 
you've just read and play with it. If the line you're getting is 
space-separated:

$string = "In 16.0 kb/s (0.0%) 2824.0 b/s (0.0%) 5640.0 b/s (0.0%)";
$exploded_line = explode(" ", $string);
print_r($exploded_line);

you get then:

Array
(
    [0] => In
    [1] => 16.0
    [2] => kb/s
    [3] => (0.0%)
    [4] => 2824.0
    [5] => b/s
    [6] => (0.0%)
    [7] => 5640.0
    [8] => b/s
    [9] => (0.0%)
)

so, the code continues

if($exploded_line[2] == 'b/s') {
    $exploded_line[4] = $exploded_line[4]/1000
}
...
...
...

then you write your file.

Luis Carlos.

PSs:

1. I'm not a good programmer.
2. I cheated: I fixed the line, so there is only 1 space between each 
chunk, you have to work on this :-)




_______________________________________________
mrtg mailing list
mrtg at lists.oetiker.ch
https://lists.oetiker.ch/cgi-bin/listinfo/mrtg






      
____________________________________________________ 
Tired of spam? Yahoo! Mail has the best spam protection around 
http://ph.mail.yahoo.com 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.oetiker.ch/pipermail/mrtg/attachments/20071118/dbcee166/attachment.html 


More information about the mrtg mailing list