Skip to content

Commit dc434e8

Browse files
committed
hwmon reads /sys/class/hwmon and reports temperatures
It automatically figures out what sensors exist and names them with either the provided label or with a stable name based on the path to the sensor. Tested on Ubuntu 12.04, Gentoo, kernel versions 3.2.0 and 3.10.7
1 parent 5260659 commit dc434e8

3 files changed

Lines changed: 90 additions & 0 deletions

File tree

system/hwmon/README.mkdn

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
hwmon
2+
=====
3+
4+
Python module for ganglia 3.1.
5+
6+
This module collects system temperature data (and anything else)
7+
from the devices in `/sys/class/hwmon`.
8+
9+
Install
10+
=======
11+
12+
1. Copy `hwmon.py` to your python modules directory (often `/usr/lib/ganglia/python_modules`).
13+
2. Copy `hwmon.pyconf` to your ganglia config directory (often `/etc/ganglia/conf.d`).
14+
3. Restart gmond.
15+
16+
## AUTHOR
17+
18+
Author: Adam Compton <[email protected]>

system/hwmon/conf.d/hwmon.pyconf

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
modules {
2+
module {
3+
name = "hwmon"
4+
language = "python"
5+
}
6+
}
7+
8+
collection_group {
9+
collect_every = 10
10+
time_threshold = 50
11+
metric {
12+
name_match = "hwmon_(.+)"
13+
}
14+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/usr/bin/env python
2+
3+
root = '/sys/class/hwmon'
4+
descriptors = []
5+
mapping = {}
6+
7+
import os, glob, re
8+
9+
def temp_finder(name):
10+
val = open(mapping[name]).read().strip()
11+
return int(val) / 1000.0
12+
13+
def metric_init(params):
14+
global descriptors
15+
16+
sensors = sorted(glob.glob(os.path.join(root, 'hwmon*')))
17+
18+
for s in sensors:
19+
temps = glob.glob(os.path.join(s, 'device/temp*_input'))
20+
# dict values are default labels if no label files exist
21+
probes = dict(zip(temps, [os.path.basename(x) for x in temps]))
22+
23+
for i in probes.keys():
24+
try:
25+
fname = i.replace('input', 'label')
26+
fhandle = open(fname, 'r')
27+
probes[i] = fhandle.read().strip().replace(' ', '_').lower()
28+
fhandle.close()
29+
except (IOError, OSError):
30+
pass
31+
32+
for i, l in probes.iteritems():
33+
num = re.search('\d+', i)
34+
device = i[num.start():num.end()]
35+
name = 'hwmon_dev%s_%s' % (device, l)
36+
item = {'name': name,
37+
'call_back': temp_finder,
38+
'time_max': 90,
39+
'value_type': 'float',
40+
'units': 'C',
41+
'slope': 'both',
42+
'format': '%0.2f',
43+
'description': 'Temperature for hwmon probe %s' % l,
44+
'groups': 'hwmon'}
45+
descriptors.append(item)
46+
mapping[name] = i
47+
48+
return descriptors
49+
50+
def metric_cleanup():
51+
'''Clean up the metric module.'''
52+
pass
53+
54+
if __name__ == '__main__':
55+
metric_init(None)
56+
for d in descriptors:
57+
v = d['call_back'](d['name'])
58+
print 'value for %s: %s' % (d['name'], str(v))

0 commit comments

Comments
 (0)