r5399 - trunk/mint/python/mint/plumage
croberts at fedoraproject.org
croberts at fedoraproject.org
Mon Jun 4 14:02:44 UTC 2012
Author: croberts
Date: 2012-06-04 14:02:43 +0000 (Mon, 04 Jun 2012)
New Revision: 5399
Modified:
trunk/mint/python/mint/plumage/session.py
Log:
Fixing a bug in the plumage data loading for inactive grids, also refactored to eliminate duplicated code.
Modified: trunk/mint/python/mint/plumage/session.py
===================================================================
--- trunk/mint/python/mint/plumage/session.py 2012-06-01 21:16:27 UTC (rev 5398)
+++ trunk/mint/python/mint/plumage/session.py 2012-06-04 14:02:43 UTC (rev 5399)
@@ -184,30 +184,38 @@
record.owner = len(self.collection.find({'ts':time,'st':'Owner'}).distinct('n'))
reduced = self.collection.map_reduce(timestamp_mapper, timestamp_reducer, temptable, query={'ts':time,})
reduced_collection = Collection(self.database,temptable)
- record.freemem = int(reduced_collection.find({'_id.st':{'$nin':['Claimed','Owner']}})[0]['value']['mem'])
- record.freecpu = int(reduced_collection.find({'_id.st':{'$nin':['Claimed','Owner']}})[0]['value']['cpu'])
- record.usedmem = int(reduced_collection.find({'_id.st':'Claimed'})[0]['value']['mem'])
- record.usedcpu = int(reduced_collection.find({'_id.st':'Claimed'})[0]['value']['cpu'])
+ result_claimed = reduced_collection.find({'_id.st':'Claimed'})
+ result_unclaimed = reduced_collection.find({'_id.st':'Unclaimed'})
+ result_owner = reduced_collection.find({'_id.st':'Owner'})
+ result_matched = reduced_collection.find({'_id.st':'Matched'})
+
+ record.freemem = self.getStat(result_unclaimed, 'mem')
+ record.freecpu = self.getStat(result_unclaimed, 'cpu')
+ record.usedmem = self.getStat(result_claimed, 'mem')
+ record.usedcpu = self.getStat(result_claimed, 'cpu')
+ record.availmem = self.getStat(result_claimed, 'mem') + self.getStat(result_unclaimed, 'mem')
+ record.availcpu = self.getStat(result_claimed, 'cpu') + self.getStat(result_unclaimed, 'cpu')
+ record.totalmem = self.getStat(result_claimed, 'mem') + self.getStat(result_unclaimed, 'mem') + self.getStat(result_owner, 'mem') + self.getStat(result_matched, 'mem')
+ record.totalcpu = self.getStat(result_claimed, 'cpu') + self.getStat(result_unclaimed, 'cpu') + self.getStat(result_owner, 'cpu') + self.getStat(result_matched, 'cpu')
- record.availmem = int(reduced_collection.find({'_id.st':'Claimed'})[0]['value']['mem']) + int(reduced_collection.find({'_id.st':'Unclaimed'})[0]['value']['mem'])
- record.availcpu = int(reduced_collection.find({'_id.st':'Claimed'})[0]['value']['cpu']) + int(reduced_collection.find({'_id.st':'Unclaimed'})[0]['value']['cpu'])
-
- record.totalmem = int(reduced_collection.find({'_id.st':'Claimed'})[0]['value']['mem']) + \
- int(reduced_collection.find({'_id.st':'Unclaimed'})[0]['value']['mem']) + \
- int(reduced_collection.find({'_id.st':'Owner'})[0]['value']['mem'])
-
- record.totalcpu = int(reduced_collection.find({'_id.st':'Claimed'})[0]['value']['cpu']) + \
- int(reduced_collection.find({'_id.st':'Unclaimed'})[0]['value']['cpu']) + \
- int(reduced_collection.find({'_id.st':'Owner'})[0]['value']['cpu'])
-
if(record.total != record.owner):
record.efficiency = (record.used/(record.total-record.owner))*100
else:
record.efficiency = 0
record.ts = time - UTC_DIFF
return record
+
+ def getStat(self, result_object, item):
+ itemcount = 0
+ try:
+ itemcount = result_object[0]['value'][item]
+ except:
+ return 0
+ return itemcount
+
+
def run(self):
while True:
self._check_connection()
More information about the cumin-developers
mailing list