3 # Command line utility for doing some trivial innd log analysis
5 # rrd-graphs/incoming-connections
6 # - part of rrd-graphs, a tool for online graphs
7 # Copyright 2010, 2012 Ian Jackson
9 # This program is free software: you can redistribute it and/or modify
10 # it under the terms of the GNU Affero General Public License as
11 # published by the Free Software Foundation, either version 3 of the
12 # License, or (at your option) any later version.
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU Affero General Public License for more details.
19 # You should have received a copy of the GNU Affero General Public License
20 # along with this program. If not, see <http://www.gnu.org/licenses/>.
23 use strict qw(refs vars);
35 my ($ts,$col,$how) = @_;
38 foreach (my $i=0; $i<@col2num; $i++) {
39 if (defined $col2num[$i]) {
41 $o .= $col==$i ? " $how" : " |";
46 printf "%s %3d %s\n", $ts, $n, $o or die $!;
51 my ($ts, $num, $how, $openclose) = @_;
52 my $col= $num2col{$num};
55 for ($col=0; defined $col2num[$col]; $col++) { }
58 report($ts, $col, $how);
60 event($ts, $num, '?', +1);
62 report($ts, $col, $how);
65 report($ts, $col, $how);
68 delete $num2col{$num};
69 $col2num[$col]= undef;
73 my $in= new IO::File '<& STDIN';
74 my $slp= Parse::Syslog->new($in);
75 while (my $sl= $slp->next) {
76 next unless $sl->{program} eq 'innd';
78 s/^([^ :]+)// or next;
79 #print STDERR ">$1<\n";
80 next unless $1 eq $site;
82 my $timestamp= strftime "%Y-%m-%d %H:%M:%S", localtime $sl->{timestamp};
84 #print STDERR "eventing\n";
85 if (m/^\:(\d+) inactive\b/) {
86 event($timestamp, $1, ':', 0);
87 } elsif (m/^\:(\d+) checkpoint\b/) {
88 event($timestamp, $1, 'I', 0);
89 } elsif (m/^\:(\d+) NCmode\b/) {
90 event($timestamp, $1, '#', 0);
91 } elsif (m/^\:(\d+) closed\b/) {
92 event($timestamp, $1, '^', -1);
93 } elsif (m/^ connected (\d+)\b/) {
94 event($timestamp, $1, 'v', +1);
96 #print STDERR "evented\n";