Class: Bipbip::Plugin::Apache2

Inherits:
Bipbip::Plugin show all
Defined in:
lib/bipbip/plugin/apache2.rb

Instance Method Summary collapse

Methods inherited from Bipbip::Plugin

#initialize, #interrupt, #interrupted?, #metric_identifier, #metrics_names, #name, #run

Methods included from InterruptibleSleep

#interrupt_sleep, #interruptible_sleep

Constructor Details

This class inherits a constructor from Bipbip::Plugin

Instance Method Details

#metrics_schemaObject



5
6
7
8
9
10
# File 'lib/bipbip/plugin/apache2.rb', line 5

def metrics_schema
  [
      {:name => 'request_per_sec', :type => 'ce_gauge', :unit => 'Requests'},
      {:name => 'busy_workers', :type => 'ce_gauge', :unit => 'Workers'},
  ]
end

#monitor(server) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/bipbip/plugin/apache2.rb', line 12

def monitor(server)
  uri = URI.parse(server['url'])
  response = Net::HTTP.get_response(uri)

  raise "Invalid response from server at #{server['url']}" unless response.code == '200'

  astats = response.body.split(/\r*\n/)

  ainfo = {}
  astats.each do |row|
    name, value = row.split(': ')
    ainfo[name] = value
  end

  {:request_per_sec => ainfo['ReqPerSec'].to_f, :busy_workers => ainfo['BusyWorkers'].to_i}
end