X-Git-Url: https://git.sesse.net/?p=remoteglot;a=blobdiff_plain;f=varnishcount.pl;h=35e1402d24085444c753b477d3e0d1240eadb525;hp=7411b054c0a1d010b790794fb1a569f8fc8d19b1;hb=a0290e9de747b7811e8403b6e7ea80ba5d96cd71;hpb=b1f81e7a5ced71f79b3d3b2212977c3901352b21 diff --git a/varnishcount.pl b/varnishcount.pl index 7411b05..35e1402 100755 --- a/varnishcount.pl +++ b/varnishcount.pl @@ -8,7 +8,10 @@ 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 = (); @@ -32,7 +35,7 @@ EV::run; sub handle_line { my $line = shift; - $line =~ m#(\d+) /analysis.pl \?ims=\d+&unique=(.*) tffb=(.*)# or return; + $line =~ m#(\d+) $url \?ims=\d+&unique=(.*) tffb=(.*)# or return; $uniques{$2} = { last_seen => $1 + $3, grace => undef, @@ -74,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); }