Class: UptimeMonitor

Inherits:
Rubix::Monitor show all
Defined in:
lib/rubix/examples/simple_uptime_monitor.rb

Instance Attribute Summary

Attributes inherited from Rubix::Monitor

#settings

Instance Method Summary collapse

Methods inherited from Rubix::Monitor

#close, default_settings, #fifo?, #file?, #format_measurement, #initialize, #loop?, #loop_period, #output, #output_path, run, #run, #sender?, #stdout?, #write

Constructor Details

This class inherits a constructor from Rubix::Monitor

Instance Method Details

#measureObject


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/rubix/examples/simple_uptime_monitor.rb', line 11

def measure
  return unless `uptime`.chomp =~ /(\d+) days.*(\d+) users.*load average: ([\d\.]+), ([\d\.]+), ([\d\.]+)/
  
  # can write one value at a time
  write ['uptime', $1.to_i]
  
  # or can use a block
  write do |data|
    # values can be arrays
    data << ['users', $2.to_i]    # or hashes

    data << { :key => 'load15', :value => $3.to_i }
    data << { :key => 'load5',  :value => $4.to_i }    # can even pass a different host

    data << { :key => 'load1',  :value => $5.to_i, :host => 'foobar-host' }
  end
end