-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcoretemp.py
executable file
·61 lines (51 loc) · 1.54 KB
/
coretemp.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Module: sensors
#
# Author: Michael L. Martin ([email protected])
import sensors
descriptors = list()
def coretemp_handler(name):
sensors.init()
value = 0
try:
for chip in sensors.iter_detected_chips():
if chip.prefix.startswith('coretemp'):
for feature in chip:
if feature.label == name:
value = feature.get_value()
break
except:
print "WTF?!?"
finally:
sensors.cleanup()
return value
def metric_init(params):
global descriptors
metric_group = params.get('metric_group', 'coretemp')
sensors.init()
for chip in sensors.iter_detected_chips():
for feature in chip:
if chip.prefix.startswith('coretemp'):
descriptors.append({
'name': feature.label,
'call_back' : coretemp_handler,
'time_max' : 60,
'units': 'C',
'format' : '%.2f',
'slope' : 'both',
'description' : 'CPU Core Temperature',
'groups' : metric_group,
})
sensors.cleanup()
return descriptors
def metric_cleanup():
pass
#This code is for debugging and unit testing
if __name__ == '__main__':
metric_init({})
for d in descriptors:
v = d['call_back'](d['name'])
print 'value for %s is %u' % (d['name'], v)
print 'Descriptor: %s' % d