Class: Riemann::Tools::Varnish
- Inherits:
-
Object
- Object
- Riemann::Tools::Varnish
- Includes:
- Riemann::Tools
- Defined in:
- lib/riemann/tools/varnish.rb
Constant Summary
Constants included from Riemann::Tools
Instance Attribute Summary
Attributes included from Riemann::Tools
Instance Method Summary collapse
-
#initialize ⇒ Varnish
constructor
A new instance of Varnish.
- #tick ⇒ Object
Methods included from Riemann::Tools
#attributes, #endpoint_name, included, #options, #report, #riemann, #run
Constructor Details
#initialize ⇒ Varnish
Returns a new instance of Varnish.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/riemann/tools/varnish.rb', line 14 def initialize super cmd = 'varnishstat -V' Open3.popen3(cmd) do |_stdin, _stdout, stderr, _wait_thr| @ver = /varnishstat \(varnish-(\d+)/.match(stderr.read)[1].to_i end @vstats = if @ver >= 4 ['MAIN.sess_conn', 'MAIN.sess_drop ', 'MAIN.client_req', 'MAIN.cache_hit', 'MAIN.cache_miss',] else %w[client_conn client_drop client_req cache_hit cache_miss] end end |
Instance Method Details
#tick ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/riemann/tools/varnish.rb', line 37 def tick stats = if @ver >= 4 `varnishstat -1 -f #{@vstats.join(' -f ')}` else `varnishstat -1 -f #{@vstats.join(',')}` end stats.each_line do |stat| m = stat.split report( host: opts[:varnish_host].dup, service: "varnish #{m[0]}", metric: m[1].to_f, state: 'ok', description: m[3..].join(' ').to_s, tags: ['varnish'], ) end end |