Created
January 30, 2019 09:39
-
-
Save marcinhlybin/6c997177f0f9354f7383c58957b3cfa9 to your computer and use it in GitHub Desktop.
Check dir size growth in time
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import yaml | |
import os | |
import sys | |
from shell import shell | |
path = '/Users/ahes/Workspace' | |
growth_threshold_percent = 1 | |
def run_du(path): | |
data = {} | |
du = shell('du -d1 ' + path) | |
for line in du.output(): | |
size, file = line.split() | |
data[file] = size | |
return data | |
def get_size(): | |
with open('du.yml', 'r') as f: | |
data = yaml.safe_load(f) | |
#print(data) | |
return data | |
if not os.path.isfile('du.yml'): | |
data = run_du(path) | |
with open('du.yml', 'w') as f: | |
yaml.dump(data, f) | |
print('Initial du.yml file saved') | |
sys.exit(0) | |
last_data = get_size() | |
current_data = run_du(path) | |
for file, size in current_data.items(): | |
if file in last_data: | |
growth_percent = (int(size) - int(last_data[file])) / float(last_data[file]) * 100 | |
if growth_percent >= growth_threshold_percent: | |
print('Size increase of {}% for file {}'.format(int(growth_percent), file)) | |
else: | |
print('File {} not found in previous du run'.format(file)) |
Author
marcinhlybin
commented
Jan 30, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment