Commit 7bfb27e4 authored by Lisa Casino's avatar Lisa Casino

slapos.collect: snapshot.py command is now gdu -n

parent 01e74ae5
......@@ -33,11 +33,6 @@ from slapos.collect.snapshot import FolderSizeSnapshot
from time import strftime, gmtime
def _get_time():
# add by Lisa to print
return strftime("%Y-%m-%d -- %H:%M:%S", gmtime()).split(" -- ")
def get_user_list(config):
nb_user = int(config.get("slapformat", "partition_amount"))
name_prefix = config.get("slapformat", "user_base_name")
......@@ -47,7 +42,7 @@ def get_user_list(config):
# By default, enable disk snapshot,
# and set time_cycle to 24hours after the first disk snapshot run
pid_folder_tmp = instance_root+"/var/run/"
disk_snapshot_params = {'enable': True, 'time_cycle': 86400, \
disk_snapshot_params = {'enable': True, 'time_cycle': 10, \
'pid_folder': pid_folder_tmp, 'use_quota': False}
if config.has_section('collect'):
......@@ -102,11 +97,11 @@ class User(object):
pid_file = self.disk_snapshot_params.get('pid_folder', None)
if pid_file is not None:
pid_file = os.path.join(pid_file, '%s_disk_size.pid' % self.name)
#print("path", self.path)
print("pid_file", pid_file)
disk_snapshot = FolderSizeSnapshot(self.path, pid_file)
disk_snapshot.update_folder_size()
print("pid_file", pid_file, disk_snapshot.disk_usage)
# Skeep insert empty partition: size <= 1Mb
if disk_snapshot.disk_usage <= 1024.0 and \
not self.disk_snapshot_params.get('testing', False):
......
......@@ -112,18 +112,30 @@ class FolderSizeSnapshot(_Snapshot):
def _getSize(self, file_path):
size = 0
command = 'du -s %s' % file_path
command = 'gdu -n %s' % file_path
process = subprocess.Popen(command, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, shell=True)
# write pid process : du -s /srv/slapgrid/slappart[i]
if self.pid_file:
with open(self.pid_file, 'w') as fpid:
pid = fpid.write(str(process.pid))
result = process.communicate()[0]
output = process.communicate()[0]
if process.returncode == 0:
size, _ = result.strip().split() # retourne la taille + path
result = output.strip().split()
unwanted_char = {'@', 'e', '!', '.', 'H'}
result = [ele for ele in result if ele not in unwanted_char]
for item in range(0,len(result),3):
if(result[item+1]=="MiB"):
result[item] = float(result[item])*1024
elif(result[item+1]=="GiB"):
result[item] = float(result[item])*1024*1024
elif(result[item+1]=="TiB"):
result[item] = float(result[item])*1024*1024*1024
#print("Taille : %s \tfolder/file : %s" % (float(result[item]), result[item+2]))
size += float(result[item])
return float(size)
class SystemSnapshot(_Snapshot):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment