#!/usr/bin/perl use strict; my @log; open(FH, "varnishlog -u -i ReqStart,RxRequest,RxURL,RxProtocol,TxStatus,RxHeader,Length,SessionClose,ReqEnd,Hit|") or die "cannot varnishlog: $!"; while( ) { chomp; my(undef, $tid, $tag, $comm, $keyword) = split /\s+/; $log[$tid]{$tag} = $keyword; if( $tag eq "ReqEnd" ) { if( exists $log[$tid]{Hit} ) { printf("%4d: %-4s %3d %s\n", $tid, exists $log[$tid]{Hit} ? "hit" : "miss", $log[$tid]{RxStatus}, $log[$tid]{RxURL}); undef $log[$tid]; } else { printf("%4d: %-4s %3d %s\n", $tid, "pass", $log[$tid]{RxStatus}, $log[$tid]{RxURL}); undef $log[$tid]; } } } close(FH); # Obtain log data from the shared memory log, order it by session ID, and # display it in Apache / NCSA combined log format: # # %h %l %u %t "%r" %>s %b "%{Referer}i" "%{User-agent}i" # # where the fields are defined as follows: # # %h Client host name or IP address (always the latter) # %l Client user ID as reported by identd (always "-") # %u User ID if using HTTP authentication, or "-" # %t Date and time of request # %r Request line # %s Status code # %b Length of reply body, or "-" # %{Referer}i Contents of "Referer" request header # %{User-agent}i Contents of "User-agent" request header # # Actually, we cheat a little and replace "%r" with something close to # "%m http://%{Host}i%U%q %H", where the additional fields are: # # %m Request method # %{Host}i Contents of "Host" request header # %U URL path # %q Query string # %H Protocol version # ReqStart = %h # RxRequest = %m # RxURL = %U%q # RxProtocol = %H # TxStatus = %s # RxHeader = %{User-agent}i (ただし user-agent: より) # RxHeader = %{Referer}i (ただし referer: より) # RxHeader = %u (ただし authorization: より) # RxHeader = %{Host}i (ただし host: より) # Length = %b # SessionClose = pipe または error 以外 # ReqEnd = %t (ただしフォーマット)