Class: Bipbip::Plugin::CommandStatus

Inherits:
Bipbip::Plugin show all
Defined in:
lib/bipbip/plugin/command_status.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



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

def metrics_schema
  [
    { name: 'status', type: 'gauge', unit: '' }
  ]
end

#monitorObject



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

def monitor
  command = config['command'].to_s
  output_stdout = output_stderr = exit_code = nil
  Open3.popen3(command) do |_stdin, stdout, stderr, wait_thr|
    output_stdout = stdout.read.chomp
    output_stderr = stderr.read.chomp
    exit_code = wait_thr.value
  end

  log(Logger::INFO, output_stdout) unless output_stdout.empty?
  log(Logger::ERROR, output_stderr) unless output_stderr.empty?
  {
    status: exit_code.exitstatus
  }
end