Class: Bipbip::Plugin::Monit

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

Constant Summary collapse

STATE_FAILED =

See bitbucket.org/tildeslash/monit/src/d60968cf7972cc902e5b6e2961d44456e1d9b736/src/monit.h?at=master#cl-135

https://bitbucket.org/tildeslash/monit/src/d60968cf7972cc902e5b6e2961d44456e1d9b736/src/monit.h?at=master#cl-146
'1'
MONITOR_NOT =
'0'

Instance Attribute Summary

Attributes inherited from Bipbip::Plugin

#config, #metric_group, #name, #pid

Instance Method Summary collapse

Methods inherited from Bipbip::Plugin

factory, #frequency, #initialize, #interrupt, #interrupted?, #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



12
13
14
15
16
17
# File 'lib/bipbip/plugin/monit.rb', line 12

def metrics_schema
  [
      {:name => 'Running', :type => 'gauge', :unit => 'Boolean'},
      {:name => 'All_Services_ok', :type => 'gauge', :unit => 'Boolean'},
  ]
end

#monitorObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/bipbip/plugin/monit.rb', line 19

def monitor
  status =  ::Monit::Status.new({
    :host => 'localhost',
    :port => 2812,
    :ssl => false,
    :auth => false,
    :username => nil,
    :password => nil,
  }.merge(config))

  data = Hash.new(0)

  begin
    data['Running'] = status.get ? 1 : 0
    data['All_Services_ok'] = status.services.any? { |service|
      service.monitor == MONITOR_NOT || service.status == STATE_FAILED } ? 0 : 1
  rescue
    data['Running'] = 0
    data['All_Services_ok'] = 0
  end
  data
end