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

wip

parent 146f0e0d
...@@ -135,56 +135,53 @@ class ConsumptionReportBase(object): ...@@ -135,56 +135,53 @@ class ConsumptionReportBase(object):
def getPartitionCPULoadAverage(self, partition_id, date_scope): def getPartitionCPULoadAverage(self, partition_id, date_scope):
self.db.connect() 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)", columns="SUM(cpu_percent)",
where="partition = '%s'" % partition_id) 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 return
sample_amount = self.db.select("user", date_scope, (sample_amount,), = self.db.select("user", date_scope,
columns="COUNT(DISTINCT time)", columns="COUNT(DISTINCT time)",
where="partition = '%s'" % partition_id) where="partition = '%s'" % partition_id)
self.db.close() self.db.close()
if len(sample_amount) and len(cpu_percent_sum): return cpu_percent_sum/sample_amount
return cpu_percent_sum[0][0]/sample_amount[0][0]
def getPartitionUsedMemoryAverage(self, partition_id, date_scope): def getPartitionUsedMemoryAverage(self, partition_id, date_scope):
self.db.connect() self.db.connect()
memory_sum = self.db.select("user", date_scope, (memory_sum,), = self.db.select("user", date_scope,
columns="SUM(memory_rss)", columns="SUM(memory_rss)",
where="partition = '%s'" % partition_id) where="partition = '%s'" % partition_id)
if len(memory_sum) and memory_sum[0][0] is None: if memory_sum is None:
return return
sample_amount = self.db.select("user", date_scope, (sample_amount,), = self.db.select("user", date_scope,
columns="COUNT(DISTINCT time)", columns="COUNT(DISTINCT time)",
where="partition = '%s'" % partition_id) where="partition = '%s'" % partition_id)
self.db.close() self.db.close()
if len(sample_amount) and len(memory_sum): return memory_sum/sample_amount
return memory_sum[0][0]/sample_amount[0][0]
def getPartitionDiskUsedAverage(self, partition_id, date_scope): def getPartitionDiskUsedAverage(self, partition_id, date_scope):
self.db.connect() 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)", columns="SUM(disk_used)",
where="partition = '%s'" % partition_id) 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 return
collect_amount = self.db.select("folder", date_scope, (collect_amount,), = self.db.select("folder", date_scope,
columns="COUNT(DISTINCT time)", columns="COUNT(DISTINCT time)",
where="partition = '%s'" % partition_id) where="partition = '%s'" % partition_id)
self.db.close() self.db.close()
if len(collect_amount) and len(disk_used_sum): return disk_used_sum/collect_amount
return disk_used_sum[0][0]/collect_amount[0][0]
class ConsumptionReport(ConsumptionReportBase): class ConsumptionReport(ConsumptionReportBase):
...@@ -292,21 +289,19 @@ class ConsumptionReport(ConsumptionReportBase): ...@@ -292,21 +289,19 @@ class ConsumptionReport(ConsumptionReportBase):
def _getCpuLoadAverageConsumption(self, date_scope): def _getCpuLoadAverageConsumption(self, date_scope):
self.db.connect() 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)") columns="SUM(cpu_percent)/COUNT(cpu_percent)")
self.db.close() self.db.close()
if len(cpu_load_percent_list): return cpu_load_percent_list
return cpu_load_percent_list[0][0]
def _getMemoryAverageConsumption(self, date_scope): def _getMemoryAverageConsumption(self, date_scope):
self.db.connect() 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)") columns="SUM(memory_used)/COUNT(memory_used)")
self.db.close() self.db.close()
if len(memory_used_list): return memory_used_list
return memory_used_list[0][0]
def _getZeroEmissionContribution(self): def _getZeroEmissionContribution(self):
self.db.connect() self.db.connect()
......
...@@ -1207,7 +1207,7 @@ class TestSoftwareProductCollection(SlapMixin): ...@@ -1207,7 +1207,7 @@ class TestSoftwareProductCollection(SlapMixin):
self.assertEqual(self.product_collection.foo, '0') self.assertEqual(self.product_collection.foo, '0')
if __name__ == '__main__': if __name__ == '__main__':
print('You can point to any SLAP server by setting TEST_SLAP_SERVER_URL '\ print('You can point to any SLAP server by setting TEST_SLAP_SERVER_URL'
'environment variable') ' environment variable')
unittest.main() 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