Add lowest option to swift-recon disk usage output

Currently there is a "--top" option when running swift-recon for
disk usage stats. This option lists the x disks with the highest
disk usage in descending order.

This feature adds a "--lowest" option which does the opposite and
lists the y disks with lowest disk usage in ascending order.

Have also updated the docs section with --top and --lowest options

Change-Id: Ic15d407fe010a31995c2bdd9fb88548a1057f569
This commit is contained in:
Lorcan 2015-03-24 13:54:00 +00:00 committed by John Dickinson
parent b76d8c5156
commit 66fb207fcb
2 changed files with 27 additions and 3 deletions

View File

@ -62,6 +62,10 @@ Get replication stats
Check cluster for unmounted devices
.IP "\fB-d, --diskusage\fR"
Get disk usage stats
.IP "\fB--top=COUNT\fR"
Also show the top COUNT entries in rank order
.IP "\fB--lowest=COUNT\fR"
Also show the lowest COUNT entries in rank order
.IP "\fB-l, --loadstats\fR"
Get cluster load average stats
.IP "\fB-q, --quarantined\fR"

View File

@ -821,7 +821,7 @@ class SwiftRecon(object):
print("No hosts returned valid data.")
print("=" * 79)
def disk_usage(self, hosts, top=0, human_readable=False):
def disk_usage(self, hosts, top=0, lowest=0, human_readable=False):
"""
Obtain and print disk usage statistics
@ -835,6 +835,7 @@ class SwiftRecon(object):
raw_total_avail = []
percents = {}
top_percents = [(None, 0)] * top
low_percents = [(None, 100)] * lowest
recon = Scout("diskusage", self.verbose, self.suppress_errors,
self.timeout)
print("[%s] Checking disk usage now" % self._ptime())
@ -858,6 +859,13 @@ class SwiftRecon(object):
top_percents.sort(key=lambda x: -x[1])
top_percents.pop()
break
for ident, oused in low_percents:
if oused > used:
low_percents.append(
(url + ' ' + entry['device'], used))
low_percents.sort(key=lambda x: x[1])
low_percents.pop()
break
stats[url] = hostusage
for url in stats:
@ -903,6 +911,13 @@ class SwiftRecon(object):
url, device = ident.split()
host = urlparse(url).netloc.split(':')[0]
print('%.02f%% %s' % (used, '%-15s %s' % (host, device)))
if low_percents:
print('LOWEST %s' % lowest)
for ident, used in low_percents:
if ident:
url, device = ident.split()
host = urlparse(url).netloc.split(':')[0]
print('%.02f%% %s' % (used, '%-15s %s' % (host, device)))
def main(self):
"""
@ -955,6 +970,9 @@ class SwiftRecon(object):
help="Get drive audit error stats")
args.add_option('--top', type='int', metavar='COUNT', default=0,
help='Also show the top COUNT entries in rank order.')
args.add_option('--lowest', type='int', metavar='COUNT', default=0,
help='Also show the lowest COUNT entries in rank \
order.')
args.add_option('--all', action="store_true",
help="Perform all checks. Equal to \t\t\t-arudlq "
"--md5 --sockstat --auditor --updater --expirer")
@ -1010,7 +1028,8 @@ class SwiftRecon(object):
self.auditor_check(hosts)
self.umount_check(hosts)
self.load_check(hosts)
self.disk_usage(hosts, options.top, options.human_readable)
self.disk_usage(hosts, options.top, options.lowest,
options.human_readable)
self.get_ringmd5(hosts, swift_dir)
self.quarantine_check(hosts)
self.socket_usage(hosts)
@ -1049,7 +1068,8 @@ class SwiftRecon(object):
if options.loadstats:
self.load_check(hosts)
if options.diskusage:
self.disk_usage(hosts, options.top, options.human_readable)
self.disk_usage(hosts, options.top, options.lowest,
options.human_readable)
if options.md5:
self.get_ringmd5(hosts, swift_dir)
self.get_swiftconfmd5(hosts)