Class: Bipbip::Plugin::Puppet

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

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



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/bipbip/plugin/puppet.rb', line 8

def metrics_schema
  [
      {:name => 'report_ok', :type => 'gauge', :unit => 'Boolean'},
      {:name => 'last_run_total_time', :type => 'gauge', :unit => 'Seconds'},
      {:name => 'last_run_age', :type => 'gauge', :unit => 'Seconds'},
      {:name => 'events_failure_count', :type => 'gauge', :unit => 'Events'},
      {:name => 'events_success_count', :type => 'gauge', :unit => 'Events'},
      {:name => 'events_total_count', :type => 'gauge', :unit => 'Events'},
      {:name => 'resources_failed_count', :type => 'gauge', :unit => 'Resources'},
      {:name => 'resources_skipped_count', :type => 'gauge', :unit => 'Resources'},
      {:name => 'resources_total_count', :type => 'gauge', :unit => 'Resources'},
      {:name => 'changes_total_count', :type => 'gauge', :unit => 'Changes'},
  ]
end

#monitorObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/bipbip/plugin/puppet.rb', line 23

def monitor
  puppet_report = last_run_summary

  report_age = Time.new.to_i - puppet_report['time']['last_run'].to_i
  has_events = puppet_report.has_key?('events')
  has_resources = puppet_report.has_key?('resources')
  has_changes = puppet_report.has_key?('changes')

  metrics = {
      'report_ok' => ((has_events and has_changes and has_resources) ? 1 : 0),
      'last_run_total_time' => puppet_report['time']['total'].to_i,
      'last_run_age' => report_age,
  }

  if has_events
    metrics['events_failure_count'] = puppet_report['events']['failure'].to_i
    metrics['events_success_count'] = puppet_report['events']['success'].to_i
    metrics['events_total_count'] = puppet_report['events']['total'].to_i
  end

  if has_resources
    metrics['resources_failed_count'] = puppet_report['resources']['failed'].to_i
    metrics['resources_skipped_count'] = puppet_report['resources']['skipped'].to_i
    metrics['resources_total_count'] = puppet_report['resources']['total'].to_i
  end

  if has_changes
    metrics['changes_total_count'] = puppet_report['changes']['total'].to_i
  end

  metrics
end