From 2be4511097a770cc5ea6967422912e38121fe1d4 Mon Sep 17 00:00:00 2001 From: Pavel Moravec Date: Wed, 10 Apr 2019 22:35:20 +0200 Subject: [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 --- sos/plugins/pulp.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) 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" -- cgit