forked from innogames/igcollect
-
Notifications
You must be signed in to change notification settings - Fork 0
/
smartmontools.py
executable file
·40 lines (31 loc) · 1 KB
/
smartmontools.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
#!/usr/bin/env python
#
# igcollect - smartmontools
#
# Copyright (c) 2016, InnoGames GmbH
#
import glob
import time
import socket
def main():
for filename in glob.glob('/var/lib/smartmontools/*.state'):
template = (
'servers.{0}.hardware.smart.{1}.{{0}}.{{1}} {{2}} {2}'.format(
socket.gethostname().replace('.', '_'),
filename.split('.', 2)[1],
int(time.time()),
)
)
with open(filename, 'r') as fd:
metric_id = None
for line in fd.readlines():
if line.startswith('ata-smart-attribute'):
desc, value = line.split('=', 1)
value_type = desc.split('.', 2)[2].strip()
value = value.strip()
if value_type == 'id':
metric_id = value
continue
print(template.format(metric_id, value_type, value))
if __name__ == '__main__':
main()