Class: Riemann::Tools::Hwmon

Inherits:
Object
  • Object
show all
Includes:
Riemann::Tools
Defined in:
lib/riemann/tools/hwmon.rb

Defined Under Namespace

Classes: Device

Constant Summary

Constants included from Riemann::Tools

VERSION

Instance Attribute Summary collapse

Attributes included from Riemann::Tools

#argv

Instance Method Summary collapse

Methods included from Riemann::Tools

#attributes, #endpoint_name, included, #options, #report, #riemann, #run

Constructor Details

#initializeHwmon

Returns a new instance of Hwmon.



87
88
89
90
91
# File 'lib/riemann/tools/hwmon.rb', line 87

def initialize
  super

  @devices = poll_devices
end

Instance Attribute Details

#devicesObject (readonly)

Returns the value of attribute devices.



85
86
87
# File 'lib/riemann/tools/hwmon.rb', line 85

def devices
  @devices
end

Instance Method Details

#poll_devicesObject



93
94
95
96
97
98
99
100
101
102
# File 'lib/riemann/tools/hwmon.rb', line 93

def poll_devices
  res = []

  Dir['/sys/class/hwmon/hwmon[0-9]*/{in,fan,temp,curr,power,energy,humidity}[0-9]*_input'].each do |filename|
    m = filename.match(%r{/sys/class/hwmon/hwmon(\d+)/([[:alpha:]]+)(\d+)_input})
    res << Device.new(m[1].to_i, m[2].to_sym, m[3].to_i)
  end

  res
end

#tickObject



104
105
106
107
108
# File 'lib/riemann/tools/hwmon.rb', line 104

def tick
  devices.each do |device|
    report(device.report)
  end
end