-
Notifications
You must be signed in to change notification settings - Fork 2
/
fans
executable file
·95 lines (80 loc) · 2.36 KB
/
fans
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Monitor fan speeds
#
# Author: Mathias Ertl <[email protected]>
#
# Changelog:
#
# 2012-07-01
# * Add ability to override label via env variable
# * No longer limit length of field names
#
#%# family=auto
#%# capabilities=autoconf
import os
import re
import sys
from subprocess import PIPE
from subprocess import Popen
if len(sys.argv) > 1 and sys.argv[1] == 'autoconf':
"""
We support autoconf. Please see:
http://munin.projects.linpro.no/wiki/ConcisePlugins#autoconf
"""
p = Popen(['which', 'sensors'], text=True, stdout=PIPE)
p.communicate()
if p.returncode == 0:
print('yes')
sys.exit(0)
else:
print('no (sensors not found)')
sys.exit(1)
def sanitize_name(string):
for regexp in ['^[^A-Za-z_]', '[^A-Za-z0-9_]']:
string = re.compile(regexp).sub('_', string)
return string.lower()
config = False
if len(sys.argv) > 1 and sys.argv[1] == 'config':
"""
Print the config-header. Note that field labels are printed in the loop
below.
"""
config = True
print ("""graph_category sensors
graph_title Fan speeds
graph_args --base 1000 -l 0
graph_vlabel U/min
graph_scale no
graph_info Monitor fan-speed""")
p = Popen(['sensors'], text=True, stdout=PIPE, stderr=PIPE)
stdout, stderr = p.communicate()
retval = p.returncode
# Various fields may be excluded with the "ignore" environment variable.
ignores = os.environ.get('ignore', '').split()
for line in stdout.split("\n"):
"""
Actually print the fields
"""
if not line.strip(): # filter empty lines
continue
if ':' not in line: # "detected" a chip
chip = line
continue
if 'RPM' not in line or chip in ignores:
continue
label, rest = line.split(':', 1)
fieldname = sanitize_name("%s_%s" % (chip, label))
if fieldname in ignores: # field is ignored
continue
if config:
label = os.environ.get('%s_label' % fieldname, label)
print("%s.label %s" % (fieldname, label))
# Get additional field values:
for limit in ['warning', 'critical', 'info']:
var = os.environ.get("%s_%s" % (fieldname, limit), '')
if var:
print("%s.%s %s" % (fieldname, limit, var))
else:
value = rest.strip().split()[0]
print("%s.value %s" % (fieldname, value))