Sha256: 0c1a4c31063ba35f74ad43c5e6a0d9cc87072360732e3d1361b6aae540e94237

Contents?: true

Size: 1.39 KB

Versions: 19

Compression:

Stored size: 1.39 KB

Contents

#!/usr/bin/env ruby

# Gathers haproxy CSV statistics and submits them to Riemann.

require File.expand_path('../../lib/riemann/tools', __FILE__)

class Riemann::Tools::Haproxy
  include Riemann::Tools
  require 'net/http'
  require 'csv'

  opt :stats_url, "Full url to haproxy stats (eg: https://user:password@host.com:9999/stats)", :required => true, :type => :string

  def initialize
    @uri = URI(opts[:stats_url]+';csv')
  end

  def tick
    csv = CSV.parse(get_csv.body.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')
          report(
            :host    => @uri.host,
            :service => "#{ns} #{property}",
            :metric  => metric.to_f,
            :state   =>  (['UP', 'OPEN'].include?(row['status']) ? 'ok' : 'critical'),
            :tags    => ['haproxy']
          )
        end
      end
    end
  end

  def get_csv
    http = Net::HTTP.new(@uri.host, @uri.port)
    http.use_ssl = true if @uri.scheme == 'https'
    http.start do |h|
      get = Net::HTTP::Get.new(@uri.request_uri)
      unless @uri.userinfo.nil?
        userinfo = @uri.userinfo.split(":")
        get.basic_auth userinfo[0], userinfo[1]
      end
      h.request get
    end
  end

end

Riemann::Tools::Haproxy.run

Version data entries

19 entries across 19 versions & 3 rubygems

Version Path
riemann-tools-0.2.7 bin/riemann-haproxy
riemann-tools-0.2.6 bin/riemann-haproxy
riemann-tools-0.2.5 bin/riemann-haproxy
riemann-tools-0.2.4 bin/riemann-haproxy
riemann-tools-0.2.3 bin/riemann-haproxy
riemann-tools-dgvz-0.2.2.3 bin/riemann-haproxy
riemann-tools-dgvz-0.2.2.2 bin/riemann-haproxy
riemann-tools-dgvz-0.2.2.1 bin/riemann-haproxy
riemann-tools-0.2.2 bin/riemann-haproxy
riemann-tools-0.2.1 bin/riemann-haproxy
riemann-tools-0.2.0 bin/riemann-haproxy
riemann-tools-0.1.9 bin/riemann-haproxy
riemann-tools.haf-0.1.9 bin/riemann-haproxy
riemann-tools-0.1.8 bin/riemann-haproxy
riemann-tools-0.1.7 bin/riemann-haproxy
riemann-tools-0.1.6 bin/riemann-haproxy
riemann-tools-0.1.5 bin/riemann-haproxy
riemann-tools-0.1.4 bin/riemann-haproxy
riemann-tools-0.1.3 bin/riemann-haproxy