Commit 064ee487 authored by Bryton Lacquement's avatar Bryton Lacquement 🚪

wip

parent 146f0e0d
......@@ -135,56 +135,53 @@ class ConsumptionReportBase(object):
def getPartitionCPULoadAverage(self, partition_id, date_scope):
self.db.connect()
cpu_percent_sum = self.db.select("user", date_scope,
(cpu_percent_sum,), = self.db.select("user", date_scope,
columns="SUM(cpu_percent)",
where="partition = '%s'" % partition_id)
if len(cpu_percent_sum) and cpu_percent_sum[0][0] is None:
if cpu_percent_sum is None:
return
sample_amount = self.db.select("user", date_scope,
(sample_amount,), = self.db.select("user", date_scope,
columns="COUNT(DISTINCT time)",
where="partition = '%s'" % partition_id)
self.db.close()
if len(sample_amount) and len(cpu_percent_sum):
return cpu_percent_sum[0][0]/sample_amount[0][0]
return cpu_percent_sum/sample_amount
def getPartitionUsedMemoryAverage(self, partition_id, date_scope):
self.db.connect()
memory_sum = self.db.select("user", date_scope,
(memory_sum,), = self.db.select("user", date_scope,
columns="SUM(memory_rss)",
where="partition = '%s'" % partition_id)
if len(memory_sum) and memory_sum[0][0] is None:
if memory_sum is None:
return
sample_amount = self.db.select("user", date_scope,
(sample_amount,), = self.db.select("user", date_scope,
columns="COUNT(DISTINCT time)",
where="partition = '%s'" % partition_id)
self.db.close()
if len(sample_amount) and len(memory_sum):
return memory_sum[0][0]/sample_amount[0][0]
return memory_sum/sample_amount
def getPartitionDiskUsedAverage(self, partition_id, date_scope):
self.db.connect()
disk_used_sum = self.db.select("folder", date_scope,
(disk_used_sum,), = self.db.select("folder", date_scope,
columns="SUM(disk_used)",
where="partition = '%s'" % partition_id)
if len(disk_used_sum) and disk_used_sum[0][0] is None:
if disk_used_sum is None:
return
collect_amount = self.db.select("folder", date_scope,
(collect_amount,), = self.db.select("folder", date_scope,
columns="COUNT(DISTINCT time)",
where="partition = '%s'" % partition_id)
self.db.close()
if len(collect_amount) and len(disk_used_sum):
return disk_used_sum[0][0]/collect_amount[0][0]
return disk_used_sum/collect_amount
class ConsumptionReport(ConsumptionReportBase):
......@@ -292,21 +289,19 @@ class ConsumptionReport(ConsumptionReportBase):
def _getCpuLoadAverageConsumption(self, date_scope):
self.db.connect()
cpu_load_percent_list = self.db.select("system", date_scope,
(cpu_load_percent_list,), = self.db.select("system", date_scope,
columns="SUM(cpu_percent)/COUNT(cpu_percent)")
self.db.close()
if len(cpu_load_percent_list):
return cpu_load_percent_list[0][0]
return cpu_load_percent_list
def _getMemoryAverageConsumption(self, date_scope):
self.db.connect()
memory_used_list = self.db.select("system", date_scope,
(memory_used_list,), = self.db.select("system", date_scope,
columns="SUM(memory_used)/COUNT(memory_used)")
self.db.close()
if len(memory_used_list):
return memory_used_list[0][0]
return memory_used_list
def _getZeroEmissionContribution(self):
self.db.connect()
......
......@@ -1207,7 +1207,7 @@ class TestSoftwareProductCollection(SlapMixin):
self.assertEqual(self.product_collection.foo, '0')
if __name__ == '__main__':
print('You can point to any SLAP server by setting TEST_SLAP_SERVER_URL '\
'environment variable')
print('You can point to any SLAP server by setting TEST_SLAP_SERVER_URL'
' environment variable')
unittest.main()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment