Class: Bipbip::Plugin::Apache2

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

Instance Attribute Summary

Attributes inherited from Bipbip::Plugin

#config, #frequency, #metric_group, #name, #tags

Instance Method Summary collapse

Methods inherited from Bipbip::Plugin

factory, factory_from_plugin, #initialize, #metrics_names, #run, #source_identifier

Methods included from InterruptibleSleep

#interrupt_sleep, #interruptible_sleep

Constructor Details

This class inherits a constructor from Bipbip::Plugin

Instance Method Details

#metrics_schemaObject



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

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

#monitorObject



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

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

  raise "Invalid response from server at #{config['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