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.



102
103
104
105
106
# File 'lib/riemann/tools/hwmon.rb', line 102

def initialize
  super

  @devices = poll_devices
end

Instance Attribute Details

#devicesObject (readonly)

Returns the value of attribute devices.



100
101
102
# File 'lib/riemann/tools/hwmon.rb', line 100

def devices
  @devices
end

Instance Method Details

#poll_devicesObject



108
109
110
111
112
113
114
115
116
117
# File 'lib/riemann/tools/hwmon.rb', line 108

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



119
120
121
122
123
124
125
# File 'lib/riemann/tools/hwmon.rb', line 119

def tick
  devices.each do |device|
    report(device.report)
  rescue Errno::ENODATA
    # Some sensors are buggy and cannot report properly
  end
end