forked from disqus/porkchop-plugins
/
df.py
61 lines (51 loc) · 1.34 KB
/
df.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
import re
from subprocess import Popen, PIPE
from porkchop.plugin import PorkchopPlugin
def df(cmd):
data = {}
r1 = re.compile('^/(dev/|)')
output = Popen([cmd], stdout=PIPE, shell=True).communicate()[0].splitlines()
output.pop(0)
for line in output:
fields = line.split()
key = r1.sub('', fields[0]).replace('/', '_')
data[key] = {
'total': fields[1],
'used': fields[2],
'available': fields[3],
'percent_used': fields[4].replace('-', '0').replace('%', ''),
'mountpoint': fields[5]
}
return data
class DfPlugin(PorkchopPlugin):
def get_data(self):
data = {}
cmd = 'df -l'
excludefs = [
'debugfs',
'devtmpfs',
'ecryptfs',
'iso9660',
'none',
'ramfs',
'romfs',
'squashfs',
'simfs'
'udf',
'unknown',
'tmpfs'
]
blocks_cmd = '%s -x %s' % (cmd, ' -x '.join(excludefs))
inodes_cmd = '%s -i -x %s' % (cmd, ' -x '.join(excludefs))
blocks = df(blocks_cmd)
for key in blocks:
data.setdefault(key, {})
data[key]['mountpoint'] = blocks[key]['mountpoint']
del blocks[key]['mountpoint']
data[key]['blocks'] = blocks[key]
inodes = df(inodes_cmd)
for key in inodes:
data.setdefault(key, {})
del inodes[key]['mountpoint']
data[key]['inodes'] = inodes[key]
return data