-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdstat_cputemp.py
More file actions
53 lines (46 loc) · 1.39 KB
/
dstat_cputemp.py
File metadata and controls
53 lines (46 loc) · 1.39 KB
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
### Displays the CPU temperature
### Author: marcelo.veiga@gmail.com
class dstat_plugin(dstat):
"""
CPU temperature in Celsius as reported by lm_sensors.
"""
def __init__(self):
self.name = 'temperature'
self.type = 'f'
self.width = 5
self.scale = 20
def check(self):
if not os.access('/usr/bin/sensors', os.R_OK):
raise Exception, 'Cannot access lm_sensors.'
def vars(self):
ret = []
n = 0
ret.append("total")
for line in os.popen('/usr/bin/sensors'):
if len(line) < 2:
continue
fields = line.split()
if fields[0] == "Core":
cpu = "cpu" + str(n)
ret.append(cpu)
n = n + 1
return ret
def nick(self):
return [name.lower() for name in self.vars]
def extract(self):
n = 0
total = 0.0
for line in os.popen('/usr/bin/sensors'):
if len(line) < 2:
continue
fields = line.split()
if fields[0] == "Core":
temp = fields[2].replace('+','')
temp = temp[:4]
cpu = "cpu" + str(n)
self.val[cpu] = float(temp)
total = total + float(temp)
n = n + 1
total = total/n
self.val["total"] = total
# vim:ts=4:sw=4:et