From: Rico Hoppe Date: Sat, 21 Oct 2023 16:19:58 +0000 (+0000) Subject: fireinfo.py: added a function that gets the avg memory usage X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=2a38b034b96d8f6fa2ac099be575583c304eaa7c;p=ipfire.org.git fireinfo.py: added a function that gets the avg memory usage --- diff --git a/src/backend/fireinfo.py b/src/backend/fireinfo.py index e5586902..f2273507 100644 --- a/src/backend/fireinfo.py +++ b/src/backend/fireinfo.py @@ -1874,6 +1874,14 @@ class Fireinfo(Object): return sorted(ret, key=lambda x: x[1], reverse=True) + def get_average_memory_amount(self, when=None): + res = self.db.get("WITH profiles AS (SELECT fireinfo_profiles_with_data_at(%s) AS id) \ + SELECT AVG(fireinfo_profiles_memory.amount) AS avg FROM profiles \ + LEFT JOIN fireinfo_profiles_memory ON profiles.id = fireinfo_profiles_memory.profile_id", when) + + if res: + return res.avg or 0 + def get_arch_map(self, when=None): res = self.db.query("WITH profiles AS (SELECT fireinfo_profiles_with_data_at(%s) AS id) \ SELECT fireinfo_arches.name AS arch, COUNT(*)::float / (SELECT COUNT(*) FROM profiles) AS count \ diff --git a/src/web/fireinfo.py b/src/web/fireinfo.py index bb4bd8d0..976b9e1d 100644 --- a/src/web/fireinfo.py +++ b/src/web/fireinfo.py @@ -156,6 +156,7 @@ class IndexHandler(BaseHandler): # Hardware "arches" : self.fireinfo.get_arch_map(when=self.when), "cpu_vendors" : self.fireinfo.get_cpu_vendors_map(when=self.when), + "memory_avg" : self.backend.fireinfo.get_average_memory_amount(when=self.when), # Virtualization "hypervisors" : self.fireinfo.get_hypervisor_map(when=self.when),