class VarnishLog
VarnishLog::Request
- This class is used to create objects that represent HTTP
requests from Varnish's perspective.
VarnishLog::Response
- This class is used to create objects that represent HTTP
responses from Varnish's perspective.
VarnishLog
- A class to define objects that contain a transaction captured
by `varnishlog`.
Attributes
request[R]
response[R]
Public Class Methods
new()
click to toggle source
Create a new VarnishLog
object.
Returns a VarnishLog
object with two attributes that are request and response objects.
# File lib/varnishlog/varnishlog.rb, line 17 def initialize @request = VarnishLog::Request.new @response = VarnishLog::Response.new end
Public Instance Methods
parse(transaction)
click to toggle source
Parses the output of a transaction captured by ‘varnishlog` into attributes that are assigned to a VarnishLog
object.
# File lib/varnishlog/varnishlog.rb, line 36 def parse(transaction) items = transaction.split("\n") # Requests ## Request headers. request_headers = items.grep(/ReqHeader/) request_headers.each do |header| if match = /-\s+ReqHeader\s+(?<header_name>.*): (?<header_value>.*)/.match(header) @request.add_header(match['header_name'], match['header_value']) end end ## Match ReqMethod. if method_match = /-\s+ReqMethod\s+(?<method>.*)/.match(items.grep(/ReqMethod/)[0]) @request.method = method_match['method'] end ## Match ReqURL. if url_match = /-\s+ReqURL\s+(?<url>\/.*)/.match(items.grep(/ReqURL/)[0]) @request.url = url_match['url'] end ## Match ReqProtocol. if protocol_match = /-\s+ReqProtocol\s+(?<protocol>.*)/.match(items.grep(/ReqProtocol/)[0]) @request.protocol = protocol_match['protocol'] end # Response. ## Response headers. response_headers = items.grep(/RespHeader/) response_headers.each do |header| if match = /-\s+RespHeader\s+(?<header_name>.*): (?<header_value>.*)/.match(header) @response.add_header(match['header_name'], match['header_value']) end end end
reap_thread()
click to toggle source
# File lib/varnishlog/varnishlog.rb, line 29 def reap_thread transaction = @varnishlog_thread.value parse(transaction) end
start_varnishlog_thread(user_agent="shellac")
click to toggle source
# File lib/varnishlog/varnishlog.rb, line 22 def start_varnishlog_thread(user_agent="shellac") @varnishlog_thread = Thread.new { output = `varnishlog -q 'ReqHeader:User-Agent eq "#{user_agent}"' -k 1` } @varnishlog_thread end