Last active
November 18, 2019 15:22
-
-
Save noqqe/0eb9321ce9da4ec7acccb7b5833a117e to your computer and use it in GitHub Desktop.
Nexus Repository Storage Space Analyzer - Takes json result from https://support.sonatype.com/hc/en-us/articles/115009519847
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 python3 | |
import sys | |
import json | |
import math | |
space = [] | |
def convert_size(size_bytes): | |
if size_bytes == 0: | |
return "0B" | |
size_name = ("B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB") | |
i = int(math.floor(math.log(size_bytes, 1024))) | |
p = math.pow(1024, i) | |
s = round(size_bytes / p, 2) | |
return "%s %s" % (s, size_name[i]) | |
with open(sys.argv[1]) as json_file: | |
data = json.load(json_file) | |
for repotype in data: | |
for repo in data[repotype]['repositories']: | |
space.append([data[repotype]['repositories'][repo]["totalBytes"], data[repotype]['repositories'][repo]["reclaimableBytes"], repo, repotype]) | |
for entry in sorted(space, key=lambda x: float(x[0]), reverse=True): | |
print('{} ({} reclaimable) {} ({})'.format(convert_size(entry[0]), convert_size(entry[1]), entry[2], entry[3])) |
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
885.06 GB (33.5 MB reclaimable) xxx (docker) | |
250.43 GB (186.65 GB reclaimable) xxx (docker) | |
106.78 GB (337.36 MB reclaimable) xxx (default) | |
72.73 GB (19.36 MB reclaimable) xxx (default) | |
[...] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment