Sha256: e07b3cc73630f692182226e2fbfaa418e57c1fbf340fd202df1dfab490cfbbcd

Contents?: true

Size: 1.08 KB

Versions: 38

Compression:

Stored size: 1.08 KB

Contents

class Riemann::Babbler::Nginx < Riemann::Babbler

  NGINX_STATUS_1 = %W(accepts handled requests)
  NGINX_STATUS_2 = %W(reading writing waiting)

  def init
    plugin.set_default(:service, 'nginx')
    plugin.set_default(:status_file, '/etc/nginx/sites-enabled/status')
    plugin.set_default(:status_url, 'http://127.0.0.1:11311/status')
    plugin.set_default(:interval, 60)
  end

  def run_plugin
    File.exists? plugin.status_file
  end

  def collect
    status = Array.new
    lines = rest_get(plugin.status_url).split("\n")
    lines[2].scan(/\d+/).each_with_index do |value, index|
      status << { :service => plugin.service + " #{NGINX_STATUS_1[index]}", :metric => value.to_i, :as_diff => true }
    end
    # line[0]: Active connections: XXXX
    status << { :service => plugin.service + ' active', :metric => lines[0].split(':')[1].strip.to_i }
    # lines[3]: Reading: 0 Writing: 1 Waiting: 0
    lines[3].scan(/\d+/).each_with_index do |value, index|
      status << { :service => plugin.service + " #{NGINX_STATUS_2[index]}", :metric => value.to_i }
    end
    status
  end

end

Version data entries

38 entries across 38 versions & 1 rubygems

Version Path
riemann-babbler-1.4.0 lib/riemann/babbler/plugins/nginx.rb
riemann-babbler-1.3.9.7 lib/riemann/babbler/plugins/nginx.rb
riemann-babbler-1.3.9.6 lib/riemann/babbler/plugins/nginx.rb
riemann-babbler-1.3.9.5 lib/riemann/babbler/plugins/nginx.rb
riemann-babbler-1.3.9.4 lib/riemann/babbler/plugins/nginx.rb
riemann-babbler-1.3.9.3 lib/riemann/babbler/plugins/nginx.rb
riemann-babbler-1.3.9.1 lib/riemann/babbler/plugins/nginx.rb
riemann-babbler-1.3.9 lib/riemann/babbler/plugins/nginx.rb
riemann-babbler-1.3.8 lib/riemann/babbler/plugins/nginx.rb
riemann-babbler-1.3.7 lib/riemann/babbler/plugins/nginx.rb
riemann-babbler-1.3.6 lib/riemann/babbler/plugins/nginx.rb
riemann-babbler-1.3.5 lib/riemann/babbler/plugins/nginx.rb
riemann-babbler-1.3.4 lib/riemann/babbler/plugins/nginx.rb
riemann-babbler-1.3.3 lib/riemann/babbler/plugins/nginx.rb
riemann-babbler-1.3.2 lib/riemann/babbler/plugins/nginx.rb
riemann-babbler-1.3.1 lib/riemann/babbler/plugins/nginx.rb
riemann-babbler-1.3.0 lib/riemann/babbler/plugins/nginx.rb
riemann-babbler-1.2.9 lib/riemann/babbler/plugins/nginx.rb
riemann-babbler-1.2.8 lib/riemann/babbler/plugins/nginx.rb
riemann-babbler-1.2.7 lib/riemann/babbler/plugins/nginx.rb