-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhddtemp.py
executable file
·69 lines (61 loc) · 2.01 KB
/
hddtemp.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
62
63
64
65
66
67
68
69
#!/usr/bin/env python
import socket
BLKSIZE = 4096
HOST = 'localhost'
PORT = 7634
descriptors = []
def temp_handler(name):
#import pydevd; pydevd.settrace(host='hypercat')
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((HOST, PORT))
data = sock.recv(BLKSIZE)
drives = data.split('||')
temp = 0.0
try:
for entry in drives:
if entry.startswith('|'):
entry = entry[1:]
if entry.endswith('|'):
entry = entry[:-1]
drive, dname, temp, unit = entry.split('|')
if drive == 'Drive %s Temperature' % name:
break
except:
pass
finally:
sock.close()
return float(temp)
def metric_init(params):
global descriptors
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((HOST, PORT))
data = sock.recv(BLKSIZE)
drives = data.split('||')
drivelist = []
for entry in drives:
if entry.startswith('|'):
entry = entry[1:]
if entry.endswith('|'):
entry = entry[:-1]
drivelist.append(entry.split('|')[0])
sock.close()
for drive in drivelist:
descriptors.append({'name': 'Drive %s Temperature' % drive.split('/')[-1],
'call_back': temp_handler,
'time_max': 90,
'value_type': 'float',
'units': 'Celsius',
'slope': 'both',
'format': '%.2f',
'description': 'Temperature of %s' % drive,
'groups': 'Drive Health'})
return descriptors
def metric_cleanup():
'''Clean up the metric module.'''
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 %s' % (d['name'], v)