]> git.ipfire.org Git - ipfire.org.git/commitdiff
fireinfo.py: added a function that gets the avg memory usage
authorRico Hoppe <rico.hoppe@ipfire.org>
Sat, 21 Oct 2023 16:19:58 +0000 (16:19 +0000)
committerRico Hoppe <rico.hoppe@ipfire.org>
Sat, 21 Oct 2023 16:19:58 +0000 (16:19 +0000)
src/backend/fireinfo.py
src/web/fireinfo.py

index e5586902d08b3b7668b4dabd7cc6f8961813d3da..f2273507d45194f5e3dec8a0449e7130a628bc09 100644 (file)
@@ -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 \
index bb4bd8d049d8cc183a00a1592858e0e2712a0582..976b9e1d1fe3676b9310d56320fa2c4294dfc469 100644 (file)
@@ -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),