Skip to content

Commit 2db6d2f

Browse files
authored
Use ZFS information to show disk usage (#81)
As df is not able to show correct disk usage for delegate datasets we should use zfs list if ZFS is enabled.
1 parent 38b035f commit 2db6d2f

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

status/info.py

+17-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env python
22

3+
from django.conf import settings
34
from subprocess import check_output
45
import os
56
import json
@@ -39,13 +40,23 @@ def imageinfo():
3940
return {}
4041

4142
def diskinfo():
42-
out = check_output(["df", "-k", "/"]).strip().split(b'\n')
43-
vals = out[-1].split()
43+
if settings.KUMQUAT_USE_ZFS:
44+
vals = check_output(["zfs", "list", "-pH", "/"]).split(b'\t')
45+
size = int(vals[1]) + int(vals[2])
46+
used = int(vals[1])
47+
free = int(vals[2])
48+
else:
49+
out = check_output(["df", "-k", "/"]).strip().split(b'\n')
50+
vals = out[-1].split()
51+
size = int(vals[1]) * 1024
52+
used = int(vals[2]) * 1024
53+
free = int(vals[3]) * 1024
54+
4455
return {
45-
'size': int(vals[1]) * 1024,
46-
'used': int(vals[2]) * 1024,
47-
'free': int(vals[3]) * 1024,
48-
'use': int((int(vals[2]) / float(vals[1])) * 100),
56+
'size': size,
57+
'used': used,
58+
'free': free,
59+
'use': int((used / size) * 100)
4960
}
5061

5162
def info():

0 commit comments

Comments
 (0)