#!/usr/bin/perl use strict; use DBI; my $workdir = shift || die "usage: $0 workdir [infile]\n"; my $dsn = "DBI:mysql:database=$ENV{DBNAME};host=$ENV{DBHOST}"; my $dbh = DBI->connect ($dsn, $ENV{DBUSER}, $ENV{DBPASS}); die DBI->errstr if !$dbh->do ("show tables"); my $t = time; my $sth = $dbh->prepare ("select traffic_ip, traffic_in_current+traffic_in_archive, traffic_out_current+traffic_out_archive from traffic"); $sth->execute; while (my $row = $sth->fetchrow_arrayref) { my ($ip, $in, $out) = @$row; if (!-f "$workdir/$ip.rrd") { my $cmd = qq{rrdtool create $workdir/$ip.rrd --step 60 DS:in:DERIVE:600:0:1000000000 DS:out:DERIVE:600:0:1000000000 RRA:AVERAGE:0.5:1:1440 RRA:AVERAGE:0.5:5:600 RRA:AVERAGE:0.5:30:700 RRA:AVERAGE:0.5:120:775 RRA:AVERAGE:0.5:1440:797 RRA:MAX:0.5:1:1440 RRA:MAX:0.5:5:600 RRA:MAX:0.5:30:700 RRA:MAX:0.5:120:775 RRA:MAX:0.5:1440:797 }; $cmd =~ s/\n/ /gs; system $cmd; print STDERR "+" if -t STDERR; } system (qq{rrdtool update $workdir/$ip.rrd -t in:out $t:$in:$out}); print STDERR "." if -t STDERR; } print STDERR "\n" if -t STDERR;