class Riemann::Tools::ApacheStatus

Public Class Methods

new() click to toggle source
Calls superclass method Riemann::Tools::new
# File lib/riemann/tools/apache_status.rb, line 20
def initialize
  super

  @uri = URI.parse("#{opts[:uri]}?auto")
  # Sample Response with ExtendedStatus On
  # Total Accesses: 20643
  # Total kBytes: 36831
  # CPULoad: .0180314
  # Uptime: 43868
  # ReqPerSec: .470571
  # BytesPerSec: 859.737
  # BytesPerReq: 1827.01
  # BusyWorkers: 6
  # IdleWorkers: 94
  # Scoreboard: ___K_____K____________W_

  @scoreboard_map = {
    '_' => 'waiting',
    'S' => 'starting',
    'R' => 'reading',
    'W' => 'sending',
    'K' => 'keepalive',
    'D' => 'dns',
    'C' => 'closing',
    'L' => 'logging',
    'G' => 'graceful',
    'I' => 'idle',
    '.' => 'open',
  }
end

Public Instance Methods

connection() click to toggle source
# File lib/riemann/tools/apache_status.rb, line 72
def connection
  response = nil
  begin
    response = ::Net::HTTP.new(@uri.host, @uri.port).get(@uri, { 'user-agent' => opts[:user_agent] }).body
  rescue StandardError => e
    report(
      service: 'httpd health',
      state: 'critical',
      description: "Httpd connection error: #{e.class} - #{e.message}",
      tags: ['httpd'],
    )
  else
    report(
      service: 'httpd health',
      state: 'ok',
      description: 'Httpd connection status ok',
      tags: ['httpd'],
    )
  end
  response
end
get_scoreboard_metrics(response) click to toggle source
# File lib/riemann/tools/apache_status.rb, line 51
def get_scoreboard_metrics(response)
  results = Hash.new(0)

  response.slice! 'Scoreboard: '
  response.each_char do |char|
    results[char] += 1
  end
  results.transform_keys { |k| @scoreboard_map[k] }
end
report_metrics(metrics) click to toggle source
# File lib/riemann/tools/apache_status.rb, line 61
def report_metrics(metrics)
  metrics.each do |k, v|
    report(
      service: "httpd #{k}",
      metric: v.to_f,
      state: 'ok',
      tags: ['httpd'],
    )
  end
end
tick() click to toggle source
# File lib/riemann/tools/apache_status.rb, line 94
def tick
  return if (response = connection).nil?

  response.each_line do |line|
    metrics = {}

    if line =~ /Scoreboard/
      metrics = get_scoreboard_metrics(line.strip)
    else
      key, value = line.strip.split(':')
      metrics[key.gsub(/\s/, '')] = value
    end
    report_metrics(metrics)
  end
end