Class: Riemann::Tools::Hwmon::Device

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hwmon, type, number) ⇒ Device

Returns a new instance of Device.



14
15
16
17
18
19
20
21
22
23
# File 'lib/riemann/tools/hwmon.rb', line 14

def initialize(hwmon, type, number)
  @hwmon = hwmon
  @type = type
  @number = number

  @crit = scale(read_hwmon_i('crit'))
  @crit = nil if @crit&.zero? # Some buggy drivers report a zero critical value.  Ignore these
  @lcrit = scale(read_hwmon_i('lcrit'))
  @service = ['hwmon', name, read_hwmon_s('label')].compact.join(' ')
end

Instance Attribute Details

#critObject (readonly)

Returns the value of attribute crit.



12
13
14
# File 'lib/riemann/tools/hwmon.rb', line 12

def crit
  @crit
end

#hwmonObject (readonly)

Returns the value of attribute hwmon.



12
13
14
# File 'lib/riemann/tools/hwmon.rb', line 12

def hwmon
  @hwmon
end

#lcritObject (readonly)

Returns the value of attribute lcrit.



12
13
14
# File 'lib/riemann/tools/hwmon.rb', line 12

def lcrit
  @lcrit
end

#numberObject (readonly)

Returns the value of attribute number.



12
13
14
# File 'lib/riemann/tools/hwmon.rb', line 12

def number
  @number
end

#serviceObject (readonly)

Returns the value of attribute service.



12
13
14
# File 'lib/riemann/tools/hwmon.rb', line 12

def service
  @service
end

#typeObject (readonly)

Returns the value of attribute type.



12
13
14
# File 'lib/riemann/tools/hwmon.rb', line 12

def type
  @type
end

Instance Method Details

#inputObject



32
33
34
# File 'lib/riemann/tools/hwmon.rb', line 32

def input
  read_hwmon_i('input')
end

#nameObject



25
26
27
28
29
30
# File 'lib/riemann/tools/hwmon.rb', line 25

def name
  result = read_hwmon_file('name')
  filename = File.realpath(hwmon_file_path('name'))
  result.concat(' at ', Regexp.last_match[1]) if filename.match(%r{/(i2c-\d+/\d+-[[:xdigit:]]+)/hwmon/})
  result
end

#reportObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/riemann/tools/hwmon.rb', line 36

def report
  value = scale(input)

  state = nil
  if crit || lcrit
    state = :ok
    state = :critical if crit && value >= crit
    state = :critical if lcrit && value <= lcrit
  end
  {
    service: service,
    state: state,
    metric: value,
    description: format_input(value),
  }
end