[mrtg] how to have fix value in mrtg output

Luis Carlos Solano lsolano at racsa.co.cr
Mon Nov 19 04:48:21 CET 2007



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 :-)






More information about the mrtg mailing list