-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtemp
executable file
·145 lines (124 loc) · 4.03 KB
/
temp
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Monitor Temperatures
#
# Author: Mathias Ertl <[email protected]>
#
# Configuration
#
# [temp]
# user root
#
# # these harddiscs will be monitored using hddtemp:
# env.discs /dev/sda /dev/sdb
#
# # Configure verious values for the "Core 0" value on the
# # coretemp-isa-0000 chip:
# env.coretemp_isa_0000_core_0_label CPU0/Core0
# env.coretemp_isa_0000_core_0_info Interesting sensor
# env.coretemp_isa_0000_core_0_warning 30:50
# env.coretemp_isa_0000_core_0_critical 25:55
# env.coretemp_isa_0000_core_0_critical 25:55
#
# # Ignore a chip and an individual value:
# env.ignore adt7470_i2c_0_2e i5k_amb_isa_0000_ch__1_dimm_9
#
# 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()
discs = os.environ.get('discs', '').split()
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 Temperatures
graph_args --base 1000 -l 0
graph_vlabel Temperature in °C
graph_scale no
graph_info Monitor temperatures as captured by lm-sensors and SMART.""")
for disc in discs:
if not os.path.exists(disc):
print("Warning: %s: No such disc." % disc)
continue
fieldname = sanitize_name(disc)
print("%s.label %s" % (fieldname, disc))
p = Popen(['hddtemp', disc], text=True, stdout=PIPE, stderr=PIPE)
info = p.communicate()[0].split(':')[1]
print("%s.info %s" % (fieldname, info))
for limit in ['warning', 'critical']:
"""get additional info from environment variables"""
var = os.environ.get("%s_%s" % (fieldname, limit))
if var:
print("%s.%s %s" % (fieldname, limit, var))
else:
for disc in discs:
if not os.path.exists(disc):
print("Warning: %s: No such disc." % disc)
continue
fieldname = sanitize_name(disc)
p = Popen(['hddtemp', disc], text=True, stdout=PIPE, stderr=PIPE)
stdout = p.communicate()[0]
value = stdout.split(': ')[2].strip()[:-2]
print("%s.value %s" % (fieldname, value))
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 ' C' 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))