--- flow2rrd.pl 2004/12/27 16:11:47 1.14
+++ flow2rrd.pl 2004/12/29 12:03:13 1.15
@@ -207,15 +207,20 @@
#print Data::Dumper->Dump([$cfg]);
# hostname/target/service to 15 chars RRD DS name mapping
+my $rrd_ds_name_cache = {};
sub make_rrd_ds_name {
my ($host, $target, $service) = @_;
- $host =~ s|[^a-zA-Z0-9_-]||sg;
- $host = substr($host . ("_"x5), 0, 5);
- $target =~ s|[^a-zA-Z0-9_-]||sg;
- $target = substr($target . ("_"x5), 0, 5);
- $service =~ s|[^a-zA-Z0-9_-]||sg;
- $service = substr($service . ("_"x5), 0, 5);
- my $ds_name = sprintf("%s_%s_%s", $host, $target, $service);
+ my $ds_name = $rrd_ds_name_cache->{$host.$target.$service};
+ if (not defined($ds_name)) {
+ $host =~ s|[^a-zA-Z0-9_-]||sg;
+ $host = substr($host . ("_"x5), 0, 5);
+ $target =~ s|[^a-zA-Z0-9_-]||sg;
+ $target = substr($target . ("_"x5), 0, 5);
+ $service =~ s|[^a-zA-Z0-9_-]||sg;
+ $service = substr($service . ("_"x5), 0, 5);
+ $ds_name = sprintf("%s_%s_%s", $host, $target, $service);
+ $rrd_ds_name_cache->{$host.$target.$service} = $ds_name;
+ }
return $ds_name;
}
@@ -224,7 +229,7 @@
##
if ($opt->{-store}) {
- my $step = 5*60; # 5 min
+ my $step = 1*60; # 1 min
# initialize data
my $ctx = &data_init($cfg);
@@ -316,13 +321,14 @@
my $rra = sprintf('RRA:LAST:0:%d:%d', $steps, $rows);
push(@rra, $rra);
}
- &mkrra($step, 5*60, 7*24*60*60); # 5 min res. for 1 week
- &mkrra($step, 10*60, 14*24*60*60); # 10 min res. for 2 weeks
- &mkrra($step, 30*60, 30*24*60*60); # 30 min res. for 1 month
- &mkrra($step, 60*60, 3*30*24*60*60); # 1 hour res. for 3 months
- &mkrra($step, 3*60*60, 6*30*24*60*60); # 3 hour res. for 6 months
- &mkrra($step, 6*60*60, 365*24*60*60); # 6 hour res. for 1 year
- &mkrra($step, 24*60*60, 4*365*24*60*60); # 1 days res. for 4 year
+ &mkrra($step, 1*60, 7*24*60*60); # 1 min res. for 1 week
+ &mkrra($step, 2*60, 14*24*60*60); # 2 min res. for 2 weeks
+ &mkrra($step, 5*60, 30*24*60*60); # 5 min res. for 1 month
+ &mkrra($step, 15*60, 3*30*24*60*60); # 15 min res. for 3 months
+ &mkrra($step, 1*60*60, 6*30*24*60*60); # 1 hour res. for 6 months
+ &mkrra($step, 2*60*60, 365*24*60*60); # 2 hour res. for 1 year
+ &mkrra($step, 6*60*60, 2*365*24*60*60); # 6 hour res. for 2 years
+ &mkrra($step, 12*60*60, 4*365*24*60*60); # 12 hour res. for 4 years
# create RRD database
RRDs::create($cfg->{'Database'}, '--start', $time, '--step', $step, @ds, @rra);
@@ -362,13 +368,14 @@
# iterate over all target and services to see whether
# the flow matches them...
my $matched_total = 0;
- LOOP: foreach my $host (@{$cfg->{'Host'}}) {
+ LOOP:
+ foreach my $host (@{$cfg->{'Host'}}) {
foreach my $target (@{$host->{-target}->{-order}}) {
my $matched = 0;
my $inbound; $inbound = undef;
my $np = $ctx->{-network}->{$host->{-name}.":".$target};
- if ($np->match_string($Cflow::srcip)) { $inbound = 0; }
- if ($np->match_string($Cflow::dstip)) { $inbound = 1; }
+ if ($np->match_string($Cflow::srcip)) { $inbound = 0; }
+ elsif ($np->match_string($Cflow::dstip)) { $inbound = 1; }
if (defined($inbound)) {
foreach my $service (@{$host->{-target}->{$target}->{-service}}) {
my $services = $cfg->{'Service'}->{$service};
@@ -457,7 +464,7 @@
elsif ($t =~ m|(\d{2})-([A-Za-z]{3})-(\d{4})|) {
$t = str2time($t);
}
- elsif ($t =~ m|^(\d+)([smhdwMY])$|) {
+ elsif ($t =~ m|^([\d.]+)([smhdwMY])$|) {
$t = $1;
if ($2 eq 's') { $t *= 1; }
elsif ($2 eq 'm') { $t *= 60; }
@@ -467,6 +474,9 @@
elsif ($2 eq 'M') { $t *= 30*24*60*60; }
elsif ($2 eq 'Y') { $t *= 365*24*60*60; }
}
+ elsif ($t =~ m|^([\d.]+)$|) {
+ $t = $1;
+ }
else {
$t = 0;
}
|