Sha256: 50bcccf1d2618ed4b670307d0a52acbc0ad7a18520cb6d8caaece3ebca2b74dc

Contents?: true

Size: 871 Bytes

Versions: 12

Compression:

Stored size: 871 Bytes

Contents

require 'net/http'
require 'csv'

class Riemann::Babbler::Haproxy < Riemann::Babbler
  
  def init
    plugin.set_default(:service, 'haproxy')
    plugin.set_default(:interval, 60)
    plugin.set_default(:url, 'http://user:password@localhost/stats;csv')
  end

  def collect
    status = Array.new
    content = rest_get(plugin.url)
    csv = CSV.parse(content.split("# ")[1], { :headers => true })
    csv.each do |row|
      row = row.to_hash
      ns  = "haproxy #{row['pxname']} #{row['svname']}"
      row.each do |property, metric|
        unless (property.nil? || property == 'pxname' || property == 'svname')
          status << {
            :service => "#{ns} #{property}",
            :metric  => metric.to_f,
            :state   =>  (['UP', 'OPEN'].include?(row['status']) ? 'ok' : 'critical')
          }
        end
      end
    end
    status
  end

end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
riemann-babbler-1.4.0 lib/riemann/babbler/plugins/haproxy.rb
riemann-babbler-1.3.9.7 lib/riemann/babbler/plugins/haproxy.rb
riemann-babbler-1.3.9.6 lib/riemann/babbler/plugins/haproxy.rb
riemann-babbler-1.3.9.5 lib/riemann/babbler/plugins/haproxy.rb
riemann-babbler-1.3.9.4 lib/riemann/babbler/plugins/haproxy.rb
riemann-babbler-1.3.9.3 lib/riemann/babbler/plugins/haproxy.rb
riemann-babbler-1.3.9.1 lib/riemann/babbler/plugins/haproxy.rb
riemann-babbler-1.3.9 lib/riemann/babbler/plugins/haproxy.rb
riemann-babbler-1.3.8 lib/riemann/babbler/plugins/haproxy.rb
riemann-babbler-1.3.7 lib/riemann/babbler/plugins/haproxy.rb
riemann-babbler-1.3.6 lib/riemann/babbler/plugins/haproxy.rb
riemann-babbler-1.3.5 lib/riemann/babbler/plugins/haproxy.rb