forked from dbrgn/collectd-python-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcpu_temp.py
41 lines (29 loc) · 956 Bytes
/
cpu_temp.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
import collectd
PATH = '/sys/class/thermal/thermal_zone0/temp'
def config_func(config):
path_set = False
for node in config.children:
key = node.key.lower()
val = node.values[0]
if key == 'path':
global PATH
PATH = val
path_set = True
else:
collectd.info('cpu_temp plugin: Unknown config key "%s"' % key)
if path_set:
collectd.info('cpu_temp plugin: Using overridden path %s' % PATH)
else:
collectd.info('cpu_temp plugin: Using default path %s' % PATH)
def read_func():
# Read raw value
with open(PATH, 'rb') as f:
temp = f.read().strip()
# Convert to degrees celsius
deg = float(int(temp)) / 1000
# Dispatch value to collectd
val = collectd.Values(type='temperature')
val.plugin = 'cpu_temp'
val.dispatch(values=[deg])
collectd.register_config(config_func)
collectd.register_read(read_func)