Merge "Added --top option to swift-recon -d"
This commit is contained in:
commit
4f617f49b6
@ -537,7 +537,7 @@ class SwiftRecon(object):
|
||||
print "No hosts returned valid data."
|
||||
print "=" * 79
|
||||
|
||||
def disk_usage(self, hosts):
|
||||
def disk_usage(self, hosts, top=0):
|
||||
"""
|
||||
Obtain and print disk usage statistics
|
||||
|
||||
@ -550,6 +550,7 @@ class SwiftRecon(object):
|
||||
raw_total_used = []
|
||||
raw_total_avail = []
|
||||
percents = {}
|
||||
top_percents = [(None, 0)] * top
|
||||
recon = Scout("diskusage", self.verbose, self.suppress_errors,
|
||||
self.timeout)
|
||||
print "[%s] Checking disk usage now" % self._ptime()
|
||||
@ -563,6 +564,13 @@ class SwiftRecon(object):
|
||||
raw_total_used.append(entry['used'])
|
||||
raw_total_avail.append(entry['avail'])
|
||||
hostusage.append(round(used, 2))
|
||||
for ident, oused in top_percents:
|
||||
if oused < used:
|
||||
top_percents.append(
|
||||
(url + ' ' + entry['device'], used))
|
||||
top_percents.sort(key=lambda x: -x[1])
|
||||
top_percents.pop()
|
||||
break
|
||||
stats[url] = hostusage
|
||||
|
||||
for url in stats:
|
||||
@ -597,6 +605,13 @@ class SwiftRecon(object):
|
||||
else:
|
||||
print "No hosts returned valid data."
|
||||
print "=" * 79
|
||||
if top_percents:
|
||||
print 'TOP %s' % top
|
||||
for ident, used in top_percents:
|
||||
if ident:
|
||||
url, device = ident.split()
|
||||
host = urlparse(url).netloc.split(':')[0]
|
||||
print '%.02f%% %s' % (used, '%-15s %s' % (host, device))
|
||||
|
||||
def main(self):
|
||||
"""
|
||||
@ -640,6 +655,8 @@ class SwiftRecon(object):
|
||||
"local copy")
|
||||
args.add_option('--sockstat', action="store_true",
|
||||
help="Get cluster socket usage stats")
|
||||
args.add_option('--top', type='int', metavar='COUNT', default=0,
|
||||
help='Also show the top COUNT entries in rank order.')
|
||||
args.add_option('--all', action="store_true",
|
||||
help="Perform all checks. Equal to -arudlq --md5 "
|
||||
"--sockstat")
|
||||
@ -731,7 +748,7 @@ class SwiftRecon(object):
|
||||
if options.loadstats:
|
||||
self.load_check(hosts)
|
||||
if options.diskusage:
|
||||
self.disk_usage(hosts)
|
||||
self.disk_usage(hosts, options.top)
|
||||
if options.md5:
|
||||
self.get_ringmd5(hosts, ring_file)
|
||||
if options.quarantined:
|
||||
|
Loading…
Reference in New Issue
Block a user