Skip to content
Snippets Groups Projects
Commit a6d54cd9 authored by Stéphane Diemer's avatar Stéphane Diemer
Browse files

Check available disk space and not free space (refs #22279).

parent 263ba714
No related branches found
No related tags found
No related merge requests found
......@@ -29,13 +29,13 @@ paths = [
'mount_point': '/',
'recommended_types': ('ext4',),
'min_size_gbytes': 14,
'min_free_size_gbytes': 5,
'min_available_gbytes': 5,
},
{
'mount_point': '/home/msuser/msinstance',
'recommended_types': ('ext4', 'nfsv4'),
'min_size_gbytes': 400,
'min_free_size_gbytes': 15,
'min_available_gbytes': 15,
},
{
'type': 'swap',
......@@ -59,12 +59,12 @@ def get_swap_gbytes():
def get_path(path):
# Filesystem Type 1B-blocks Used Available Use% Mounted on
# /dev/loop2 ext4 52710469632 38253940736 11755397120 77% /
status, output = subprocess.getstatusoutput('df --output="source,fstype,size,used" -B 1 %s | tail -n 1' % path)
status, output = subprocess.getstatusoutput('df --output="source,fstype,size,avail" -B 1 %s | tail -n 1' % path)
if status == 0:
dev, fstype, size, used = output.split()
dev, fstype, size, available = output.split()
else:
dev = fstype = size = used = None
return dev, fstype, to_gbytes(int(size)), to_gbytes(int(used))
dev = fstype = size = available = None
return dev, fstype, to_gbytes(int(size)), to_gbytes(int(available))
def check_allocation(dev):
......@@ -105,19 +105,18 @@ def check_path(p):
if os.path.exists(mount_point):
mount_point = os.path.realpath(mount_point)
name = mount_point
dev, fstype, psize, used = get_path(mount_point)
dev, fstype, psize, available = get_path(mount_point)
if fstype not in p.get('recommended_types'):
print('Warning, partition of %s fs type not recommended %s(current: %s, recommended: %s)%s' % (name, YELLOW, fstype, p['recommended_types'], DEF))
warning = True
if 'nfs' not in dev:
warning = not check_allocation(dev)
free_gb = psize - used
min_free_size_gbytes = p.get('min_free_size_gbytes')
if min_free_size_gbytes and free_gb < min_free_size_gbytes:
print('Partition of %s has less than %s GB free (%s GB free)' % (mount_point, min_free_size_gbytes, free_gb))
min_available_gbytes = p.get('min_available_gbytes')
if min_available_gbytes and available < min_available_gbytes:
print('Partition of %s has less than %s GB available (%s GB available)' % (mount_point, min_available_gbytes, available))
error = True
else:
print('Partition of %s is OK' % name)
print('Partition of %s is OK (%s GB available)' % (name, available))
else:
print('%s not found, cannot check' % mount_point)
elif p.get('type') == 'swap':
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment