Skip to content
Snippets Groups Projects
Commit a1f4d772 authored by Vlad Kondratiev's avatar Vlad Kondratiev
Browse files

added new script to get info about volume usage on CEP4

parent 3c4f0199
Branches
No related tags found
No related merge requests found
#!/usr/bin/env python
#
#
import os, sys, re
import numpy as np
import matplotlib.pyplot as plt
import subprocess
import datetime
targetdir = "/data/projects"
globdir = "/data"
def human_size (size, f):
if (size/f < 1): return "%ldB" % (size)
if (size/f/f < 1): return "%.1fk" % (size/f)
if (size/f/f/f < 1): return "%.1fM" % (size/f/f)
if (size/f/f/f/f < 1): return "%.1fG" % (size/f/f/f)
if (size/f/f/f/f/f < 1): return "%.1fT" % (size/f/f/f/f)
def duh(path):
"""
disk usage in human readable format (e.g. '2.1GB')
"""
return subprocess.check_output(['du','-sh', path]).split()[0].decode('utf-8')
def duB(path):
"""
disk usage in bytes format
"""
return subprocess.check_output(['du','-sB 1', path]).split()[0].decode('utf-8')
text = ""
p=os.popen('df -H %s' % (globdir))
for line in p.readlines(): text += line
projects = {}
files = [f for f in os.listdir(targetdir) if os.path.isdir(os.path.join(targetdir, f)) and f[0] != "."]
text += "\n " + "-"*55
text += "\n %-30s %10s\n" % ("Project", "Size")
text += " " + "-"*55
text += "\n"
for f in files:
dirsize = duh(os.path.join(targetdir, f))
dirsize_in_bytes = duB(os.path.join(targetdir, f))
projects[f] = (dirsize, dirsize_in_bytes)
text += " %-30s %10s\n" % (f, dirsize)
text += " " + "-"*55
labels = np.array([str(ii) for ii in projects.keys()])
sizes=[float(s) for (d, s) in projects.values()]
total=np.sum(sizes)
sizes_percent=np.array([s*100./total for s in sizes])
text += "\n %-30s %10s" % ("Total", human_size(total, 1024))
now = datetime.datetime.utcnow()
updated = "Updated: %s UTC" % (now)
pie_labels=[]
pie_sizes=[]
rest_size = 0.
for (l,s) in zip(labels, sizes_percent):
if s<1.0: rest_size += s
else:
pie_labels.append(l)
pie_sizes.append(s)
pie_labels.append("others")
pie_sizes.append(rest_size)
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(10,5))
fig.suptitle("CEP4 /data volume usage")
ax1.annotate(text, xycoords="axes fraction", xy=(0.0, 0.99), bbox=dict(facecolor='0.95', boxstyle="round"), ha='left', va='top', multialignment="left", zorder=2, fontsize=10)
ax1.annotate(updated, xycoords="axes fraction", xy=(0.0, 0.0), ha='left', va='bottom', multialignment="left", zorder=2, fontsize=8)
ax1.axis('off')
ax2.pie(pie_sizes, labels=pie_labels, autopct='%1.1f%%')
#, pctdistance=1.25, labeldistance=.6)
plt.tight_layout()
plt.gcf().set_size_inches(10, 5) # Width=10in, Height=5in
plt.savefig("cep4-usage.png", bbox_inches='tight', dpi=100) # output figure size will be (10,5)x100 in pixels
plt.show()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment