X-Git-Url: https://git.sesse.net/?p=remoteglot;a=blobdiff_plain;f=varnishcount.pl;h=94203bbe287ee7cdb2e0fbe6a317e6409a5e28fc;hp=1aa0e6f8f487659940355e95f96e9ec0a0b7df4d;hb=1678a9e9c9c0189dfdbbf68ab11cbcc178c5bf97;hpb=7341e76ca62acf3b1d33a3d12cd4aefd1471fec9 diff --git a/varnishcount.pl b/varnishcount.pl index 1aa0e6f..94203bb 100755 --- a/varnishcount.pl +++ b/varnishcount.pl @@ -8,17 +8,24 @@ use strict; use warnings; no warnings qw(once); -open my $fh, "-|", "varnishncsa -F '%{%s}t %U %q tffb=%{Varnish:time_firstbyte}x' -q 'ReqURL ~ \"^/analysis.pl\"'" +my $url = $ARGV[0] // "/analysis.pl"; # Technically an URL regex, not an URL. +my $port = $ARGV[1] // 5000; + +open my $fh, "-|", "varnishncsa -F '%{%s}t %U %q tffb=%{Varnish:time_firstbyte}x' -q 'ReqURL ~ \"^$url\"'" or die "varnishncsa: $!"; my %uniques = (); -my $ev = AnyEvent->io( +my $ev = AnyEvent::Handle->new( fh => $fh, - poll => 'r', - cb => sub { - chomp (my $input = <$fh>); - handle_line($input); - } + on_read => sub { + my ($hdl) = @_; + $hdl->push_read( + line => sub { + my ($hdl, $line, $eof) = @_; + handle_line($line); + } + ); + }, ); my $ev2 = AnyEvent->timer( interval => 1.0, @@ -70,5 +77,5 @@ sub output { my $num_viewers = scalar keys %uniques; printf "%d entries in hash, mtime=$mtime\n", scalar keys %uniques; - LWP::Simple::get('http://127.0.0.1:5000/override-num-viewers?num=' . $num_viewers); + LWP::Simple::get('http://127.0.0.1:' . $port . '/override-num-viewers?num=' . $num_viewers); }