[mrtg] Reading config files -- FAST

Bjorn Nordbo bn at nextra.com
Tue Sep 12 13:59:21 MEST 2000


Does anyone have routines for reading MRTG config files very fast?

My problem is that several of mye configs exceed 10k lines. This is
not a problem for MRTG itself, but my display scripts, which has to
parse the config up to 9 times to display a full MRTG compatible
page, are bogging down seriously.

I have managed to get a very fast config reading routing (thanks to
the guys at no.it.programmering.perl btw!) by optimizing the code
from 14all.cgi and skipping everything that does not start with
\w+\[$the_target_to_display|_|^|$\] or \w+: (eg. eiher a target
option of the target I'm looking for or a global option), however
this routine misses line continuation:

sub read_mrtg_config_file
{
    my $file = shift;
    my $target = shift;
    my @lines = ();
    my @buf = ();

    open(CFG, $file) or do {warn "Can't open config file $file: $!"; return ()};    while (<CFG>) {
    	next unless (/^\w+:/o or /^\w+\[[_\$\^]\]:/o or /^\w+\[$target\]:/o);
    	s/\s+/ /g;                 # collapse white space to one space
        s/ \z//;                   # remove trailing space and newline
        if (/^ /) {                # continuation lines
            $lines[$#lines] .= $_;
        } else {
            push @lines, $_;
    	}
    }
    close CFG;

    return \@lines;
}

The trick here is the 'next unless' line; without this line, it takes
something like two seconds to read the config. However, this also weeds
out the continuation lines, and I can't find any way around this.

As far as I can see, I have three options:

1. Continue to search for a faster way to read configs
2. Extract every target config to another medium than one big, flat file
   and write a config backend to read that for the display scripts.
3. As for (2), but use this backend for MRTG (2.9) too.

Any suggestions? Solutions? Corrections?

-- 
Bjørn Nordbø  -  IP Development  -  Nextra Norway

--
Unsubscribe mailto:mrtg-request at list.ee.ethz.ch?subject=unsubscribe
Archive     http://www.ee.ethz.ch/~slist/mrtg
FAQ         http://faq.mrtg.org    Homepage     http://www.mrtg.org
WebAdmin    http://www.ee.ethz.ch/~slist/lsg2.cgi



More information about the mrtg mailing list