chiark / gitweb /
input seems to work liberator
authorIan Jackson <ian@liberator.relativity.greenend.org.uk>
Sun, 27 Jun 2010 17:28:06 +0000 (18:28 +0100)
committerIan Jackson <ian@liberator.relativity.greenend.org.uk>
Sun, 27 Jun 2010 17:28:06 +0000 (18:28 +0100)
newstailer

index 5a4f7e9ab3bbbf7c7fc0864c015e65086c8e7843..e3aba619cd8763b4d7b486af55e1ec5f53c3b04d 100755 (executable)
@@ -39,33 +39,48 @@ if (!keys %dohosts) {
 die unless @ARGV;
 my $totail= pop @ARGV;
 
-if ($debug) { open DEBUG, ">& STDERR" or die $!; }
+if ($debug) { open DEBUG, ">& STDOUT" or die $!; }
+
+our %details;
+
+
+our @detail_defaults=
+    (
+     Step => 60,
+     DstArguments => "7200:0:U",
+     Xff => 0.5,
+     Archives => [ [ 3600*4,           60 ],   # 4hr, 1min resolution
+                  [ 3600*25,         180 ],   # 25h, 3min resolution
+                  [ 86400*14*5,      3600 ],  # 14wks, 1hr resolution
+                  [ 86400*370*2, 3600*24 ] ], # 2yr+, 1day resolution
+     );
 
 our @fields_in= qw(seconds accepted refused rejected duplicate
                   accepted_size duplicate_size);
-our $tmpl_in= join ':',@fields_in;
-our %details= (
-    'in' => {
-       Step => 60,
-       DstArguments => "7200:0:U",
-       Xff => 0.5,
-       Archives => [ [ 3600*4,           60 ],   # 4hr, 1min resolution
-                     [ 3600*25,         180 ],   # 25h, 3min resolution
-                     [ 86400*14*5,      3600 ],  # 14wks, 1hr resolution
-                     [ 86400*370*2, 3600*24 ] ], # 2yr+, 1day resolution
-    }
-);
+$details{'in'}= {
+    Fields => \@fields_in,
+    @detail_defaults
+};
+
+our @fields_out= qw(missing offered deferred
+                   accepted unwanted rejected body_missing);
+$details{'out'}= {
+    Fields => \@fields_out,
+    @detail_defaults
+};
+
 
 our ($time,$host,$peer,$conn,$stats);
 
-sub create_rrd ($$$) {
-    my ($inout, $path, $fields) = @_;
+sub create_rrd ($$) {
+    my ($inout, $path) = @_;
 
     my $details= $details{$inout};
 
     my @sargs= ($path, '--start','now-1y', '--step',$details->{Step});
     my @largs;
-    push @largs, "DS:$_:ABSOLUTE:$details->{DstArguments}" foreach @$fields;
+    push @largs, "DS:$_:ABSOLUTE:$details->{DstArguments}"
+       foreach @{ $details{$inout}{Fields} };
     foreach (@{ $details->{Archives} }) {
        my ($whole,$reso) = @$_;
        my $steps= $reso / $details->{Step};
@@ -86,8 +101,8 @@ sub get_rrd_info ($$) {
     $rrdupdate->{DoneUpto}= $h->{'last_update'};
 }
 
-sub find_or_create_rrd ($$) {
-    my ($inout, $fields) = @_;
+sub find_or_create_rrd ($) {
+    my ($inout) = @_;
     my $rrd= {
        Path => "${outpfx}${host}${sep}${peer}_${inout}.rrd",
     };
@@ -95,7 +110,7 @@ sub find_or_create_rrd ($$) {
        get_rrd_info($rrd, $rrd->{Path});
     } else {
        $!==&ENOENT or die "$rrd->{Path} $!";
-       create_rrd($inout, $rrd->{Path}, $fields);
+       create_rrd($inout, $rrd->{Path});
        $rrd->{DoneUpto}= 0;
     }
     return $rrd;
@@ -105,13 +120,13 @@ our %rrds;
 our @rrd_blockedupdates;
 our $rrd_blockedupdate_time;
 
-sub update_rrd ($$$$) {
-    my ($inout,$tmpl,$vals,$fields) = @_;
+sub update_rrd ($$) {
+    my ($inout,$vals) = @_;
 
     my $rrd= $rrds{$host,$peer,$inout};
     if (!$rrd) {
-       $rrd= $rrds{$host,$peer,$inout}= find_or_create_rrd($inout, $fields);
-       $rrd->{Template}= $tmpl;
+       $rrd= $rrds{$host,$peer,$inout}= find_or_create_rrd($inout);
+       $rrd->{Template}= join ':', @{ $details{$inout}{Fields} };
     }
     return if $time <= $rrd->{DoneUpto};
 
@@ -152,24 +167,25 @@ sub actually_update_rrds () {
 our %in_conns;
 
 sub inbound_connected () {
-    print DEBUG "inbound connected $host $peer $conn\n" if $debug>=2;
+    print DEBUG "inbound $time connected $host $peer $conn\n" if $debug>=2;
     $in_conns{$host,$peer,$conn} = [ (0) x @fields_in ];
 }
 sub inbound_closed () {
-    print DEBUG "inbound closed $host $peer $conn\n" if $debug>=2;
+    print DEBUG "inbound $time closed $host $peer $conn\n" if $debug>=2;
     delete $in_conns{$host,$peer,$conn};
 }
 sub inbound_stats () {
     $_= $stats.' ';
-    my %s;
     s/(?<=[a-z]) (?=[a-z])/_/g;
     my $hpc= $in_conns{$host,$peer,$conn};
     if (!$hpc) {
-       print DEBUG "inbound UNKNOWN $host $peer $conn $stats\n";
+       print DEBUG "inbound $time UNKNOWN $host $peer $conn $stats\n";
        $in_conns{$host,$peer,$conn}= $hpc= [ (undef) x @fields_in ];
     } else {
-       print DEBUG "inbound stats $host $peer $conn $stats\n" if $debug>=2;
+       print DEBUG "inbound $time stats $host $peer $conn $stats\n"
+           if $debug>=2;
     }
+    my %s;
     while (s/^([a-z_]+) (\d+)\s//) { $s{$1}= $2; }
     my @v;
     foreach my $f (@fields_in) {
@@ -183,11 +199,22 @@ sub inbound_stats () {
        $hpc->[@v]= $this;
        push @v, defined($last) ? $this - $last : 'U';
     }
-    update_rrd('in',$tmpl_in,\@v,\@fields_in);
+    update_rrd('in',\@v);
 }
 
 sub outbound_stats () {
-    print "$host $peer OUT $stats\n";
+    print DEBUG "outbound $time stats $host $peer $stats\n" if $debug>=2;
+    $_= " $stats ";
+    s/missing(?=\=\d+ \()/body_missing/;
+    s/\([^()]*\)/ /;
+    my %s;
+    while (s/ ([a-z]\w+)\=(\d+) / /) { $s{$1}= $2; }
+    my @v;
+    foreach my $f (@fields_out) {
+       my $this= $s{$f};
+       push @v, defined($this) ? $this : 'U';
+    }
+    update_rrd('out',\@v);
 }
 
 sub run ($) {
@@ -200,19 +227,21 @@ sub run ($) {
        ($time,$host,$process,$pid,$msg) = @$sl;
        actually_update_rrds();
        next unless exists $dohosts{$host};
-       #print join("|", map { defined($_) ? $_ : "<undef>" } @$sl), "\n";
+       print DEBUG "logfile ",
+           join("|", map { defined($_) ? $_ : "<undef>" } @$sl), "\n"
+               if $debug>=3;
        if ($process eq 'innd' && !defined $pid) {
            if (($peer,$conn) = $msg =~
                m/^($host_re) connected ($conn_re)(?: streaming allowed)?$/) {
                inbound_connected()
            } elsif (($peer,$conn,$cc,$stats) = $msg =~
-            m/^($host_re):($conn_re) (closed|checkpoint) (seconds .*)$/) {
+     m/^($host_re):($conn_re) (closed|checkpoint) (seconds .*)$/) {
                inbound_stats();
                inbound_closed() if $cc eq 'closed';
            }
        } elsif ($process eq 'innduct') {
            if (($peer,$stats) = $msg =~
-               m/^($host_re)\| (?:completed|processed) \S+ (read=.*)$/) {
+     m/^($host_re)\| notice: (?:completed|processed) \S+ (read=.*)$/) {
                outbound_stats();
            }
        }