varnishops 0.0.3 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -4,7 +4,9 @@ varnishops is a tool for analyzing and categorizing traffic on your varnish serv
4
4
 
5
5
  It gathers the output of varnishncsa and create statistics such as request rate, output bandwidth or hitratio.
6
6
 
7
- URLs from varnishncsa are categorized using custom regular expressions, based on your assets' paths and classification (example provided in **ext/**)
7
+ URLs from varnishncsa can be categorized in two ways:
8
+ * using custom regular expressions applied on URL, based on your assets' paths and classification (example provided in **ext/**)
9
+ * using host header, if you have several assets domains (with -H switch)
8
10
 
9
11
  varnishops is written in Ruby (tested with MRI 1.9.3 and MRI 1.8.7) and depends only on varnishncsa.
10
12
 
@@ -20,6 +20,11 @@ class CmdLine
20
20
  @config[:avg_period] = avg_period
21
21
  end
22
22
 
23
+ @config[:host_mode] = false
24
+ opt.on '-H', '--host-mode', "Categorize requests using hostnames instead of url regexps" do |host_mode|
25
+ @config[:host_mode] = true
26
+ end
27
+
23
28
  opt.on_tail '-h', '--help', 'Show usage info' do
24
29
  puts opts
25
30
  exit
data/lib/ui.rb CHANGED
@@ -50,7 +50,8 @@ class UI
50
50
 
51
51
  attrset(color_pair(1))
52
52
  setpos(0,0)
53
- addstr(sprintf "%-#{@key_col_width}s%-#{@url_col_width}s%s", "request pattern", "last url", @stat_cols.join)
53
+
54
+ addstr(sprintf "%-#{@key_col_width}s%-#{@url_col_width}s%s", (@config[:host_mode]) ? "hostname" : "request pattern", "last url", @stat_cols.join)
54
55
  end
55
56
 
56
57
  def footer
@@ -16,6 +16,7 @@ class VarnishPipe
16
16
 
17
17
  @semaphore = Mutex.new
18
18
  @avg_period = config[:avg_period]
19
+ @host_mode = config[:host_mode]
19
20
  @default_key = "other"
20
21
 
21
22
  @regexs = regexs
@@ -26,19 +27,23 @@ class VarnishPipe
26
27
  @start_time = Time.new.to_f
27
28
  @start_ts = @start_time.to_i
28
29
 
29
- IO.popen("varnishncsa -F '%U %{Varnish:hitmiss}x %b'").each_line do |line|
30
- if line =~ /^(\S+) (\w+) (\d+)$/
31
- url, status, bytes = $1, $2, $3
30
+ IO.popen("varnishncsa -F '%{Host}i %U %{Varnish:hitmiss}x %b'").each_line do |line|
31
+ if line =~ /^(\S+) (\S+) (\w+) (\d+)$/
32
+ host, url, status, bytes = $1, $2, $3, $4
32
33
  key = nil
33
34
 
34
- @regexs.each do |k,v|
35
- if k.match(url)
36
- key = v.map{|x| "#{$~[x]}" }.join(":")
37
- break
35
+ if (@host_mode)
36
+ key = host;
37
+ else
38
+ @regexs.each do |k,v|
39
+ if k.match(url)
40
+ key = v.map{|x| "#{$~[x]}" }.join(":")
41
+ break
42
+ end
38
43
  end
44
+ key = @default_key unless key
39
45
  end
40
46
 
41
- key = @default_key unless key
42
47
 
43
48
  @semaphore.synchronize do
44
49
  duration = (Time.now.to_i - @start_ts)
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |gem|
6
6
  gem.name = "varnishops"
7
- gem.version = "0.0.3"
7
+ gem.version = "0.1.0"
8
8
  gem.authors = ["Jonathan Amiez"]
9
9
  gem.email = ["jonathan.amiez@fotolia.com"]
10
10
  gem.description = %q{varnishops - a realtime varnish log analyzer}
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: varnishops
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-11 00:00:00.000000000 Z
12
+ date: 2013-05-28 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: varnishops - a realtime varnish log analyzer
15
15
  email: