aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPavel Moravec <pmoravec@redhat.com>2019-04-10 22:35:20 +0200
committerBryn M. Reeves <bmr@redhat.com>2019-05-14 11:27:12 +0100
commit2be4511097a770cc5ea6967422912e38121fe1d4 (patch)
treeca15fabc1665faadce02b2c676614ce3335a1625
parent4263edec9ce6eeb67524e43033b6fae6608aa931 (diff)
downloadsos-2be4511097a770cc5ea6967422912e38121fe1d4.tar.gz
[pulp] collect db and collection sizes
Collect basic db stats and also collection sizes of mongo pulp_database Resolves: #1645 Signed-off-by: Pavel Moravec <pmoravec@redhat.com>
-rw-r--r--sos/plugins/pulp.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/sos/plugins/pulp.py b/sos/plugins/pulp.py
index e947c174..4faa4f0d 100644
--- a/sos/plugins/pulp.py
+++ b/sos/plugins/pulp.py
@@ -53,9 +53,38 @@ class Pulp(Plugin, RedHatPlugin):
r'.shellPrint()"' % num_tasks
)
+ # prints mongo collection sizes sorted from biggest and in human
+ # readable output
+ csizes = self.build_mongo_cmd(
+ '\"function humanReadable(bytes) {'
+ ' var i = -1;'
+ ' var byteUnits = [\'kB\', \'MB\', \'GB\', \'TB\', \'PB\', '
+ ' \'EB\', \'ZB\', \'YB\'];'
+ ' do {'
+ ' bytes = bytes / 1024;'
+ ' i++;'
+ ' } while (bytes > 1024);'
+ ' return Math.max(bytes, 0.1).toFixed(1) + \' \' + byteUnits[i];'
+ '};'
+ 'var collectionNames = db.getCollectionNames(), stats = [];'
+ 'collectionNames.forEach(function (n) {'
+ ' stats.push(db[n].stats());'
+ ' });'
+ 'stats = stats.sort(function(a, b) {'
+ ' return b[\'size\'] - a[\'size\']; });'
+ 'for (var c in stats) {'
+ ' print(stats[c][\'ns\'] + \': \' +'
+ ' humanReadable(stats[c][\'size\']) + \' (\' +'
+ ' humanReadable(stats[c][\'storageSize\']) + \')\'); }\"'
+ )
+
+ dbstats = self.build_mongo_cmd('\"db.stats()\"')
+
self.add_cmd_output(mtasks, suggest_filename="mongo-task_status")
self.add_cmd_output(mres, suggest_filename="mongo-reserved_resources")
self.add_cmd_output(prun, suggest_filename="pulp-running_tasks")
+ self.add_cmd_output(csizes, suggest_filename="mongo-collection_sizes")
+ self.add_cmd_output(dbstats, suggest_filename="mongo-db_stats")
def build_mongo_cmd(self, query):
_cmd = "bash -c %s"