[mrtg] Re: log files

Yozo TODA yozo at ipc.chiba-u.ac.jp
Thu Jun 1 02:28:31 MEST 2000


> >In the .log file I can see at the start of every line a big number, I
> >suppose that is information about the time, day... the info was gathered.
> >
> >How can I understand them? because they don't seem to be human readable.

based on the information of mrtg-2.8.12/doc/logfile-format.txt
I wrote a perl script to convert log file to somewhat "readable" format.
see (http://aohakobe.ipc.chiba-u.ac.jp/misc/docs/NET/mrtg/showlog.pl)

#!/opt/perl/bin/perl
## showlog.pl: show MRTG log data in human-readable format
## -- yozo.  Sun Aug 15 00:48:13 JST 1999

## print "program: $0 -- max arg index($#ARGV)\n";
## $argnum=0;
## foreach $i ( @ARGV ){
##   print "ARG[$argnum]: $i\n";
##   $argnum ++;
## }

if ($#ARGV < 0){
  print "usage: $0 mrtg_logfile ...\n";
  exit 1;
}

foreach $file ( @ARGV ){
  open(FILE,$file) or die "$file not found\n";

  $firstline = <FILE>;
  ## print "firstline: $firstline";
  $firstline =~ /^(\d+)\s+(\d+)\s+(\d+)/;
  print "==== $file ====\n";
  ## $date = localtime($1);
  ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($1);
  $year = (1900 + $year);  $mon = (1 + $mon);
  ## print "$year $mon $mday $hour:$min:$sec: in($2 B) out($3 B)\n";
  printf "[%02d/%02d/%02d %02d:%02d:%02d] in(%d B) out(%d B)\n",
             $year, $mon, $mday, $hour, $min, $sec, $2, $3;

  ## 5 minutes average
  for(2..600){
    $_ = <FILE>;
    /^(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)/;
    ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($1);
    $year = (1900 + $year);  $mon = (1 + $mon);
    ## print "$year $mon $mday $hour:$min:$sec: avg(in:$2 B, out:$3 B) max(in:$4 B out:$5 B)\n";
    printf "[%02d/%02d/%02d %02d:%02d:%02d] avg(in:%d B, out:%d B) max(in:%d B, out:%d B)\n",
             $year,$mon,$mday,$hour,$min,$sec, $2,$3,$4,$5;
  }

  ## 30 minutes average
  for(601..1200){
    $_ = <FILE>;
    /^(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)/;
    ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($1);
    $year = (1900 + $year);  $mon = (1 + $mon);
    ## print "$year $mon $mday $hour:$min:$sec: avg(in:$2 B, out:$3 B) max(in:$4 B out:$5 B)\n";
    printf "[%02d/%02d/%02d %02d:%02d:%02d]_ avg(in:%d B, out:%d B) max(in:%d B, out:%d B)\n",
             $year,$mon,$mday,$hour,$min,$sec, $2,$3,$4,$5;
  }

  ## 120 minutes average
  for(1201..1800){
    $_ = <FILE>;
    /^(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)/;
    ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($1);
    $year = (1900 + $year);  $mon = (1 + $mon);
    ## print "$year $mon $mday $hour:$min:$sec: avg(in:$2 B, out:$3 B) max(in:$4 B out:$5 B)\n";
    printf "[%02d/%02d/%02d %02d:%02d:%02d]~ avg(in:%d B, out:%d B) max(in:%d B, out:%d B)\n",
             $year,$mon,$mday,$hour,$min,$sec, $2,$3,$4,$5;
  }

  ## 24 hours average
  while(<FILE>){
    /^(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)/;
    ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($1);
    $year = (1900 + $year);  $mon = (1 + $mon);
    ## print "$year $mon $mday $hour:$min:$sec: avg(in:$2 B, out:$3 B) max(in:$4 B out:$5 B)\n";
    printf "[%02d/%02d/%02d %02d:%02d:%02d]^ avg(in:%d B, out:%d B) max(in:%d B, out:%d B)\n",
             $year,$mon,$mday,$hour,$min,$sec, $2,$3,$4,$5;
  }
}

-- yozo.


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



More information about the mrtg mailing list