]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cephadm: enhance memory and cpu data
authorPaul Cuzner <pcuzner@redhat.com>
Mon, 10 Aug 2020 21:53:12 +0000 (09:53 +1200)
committerPaul Cuzner <pcuzner@redhat.com>
Mon, 10 Aug 2020 21:53:12 +0000 (09:53 +1200)
Added free/available memory state, and cpu loadavg info

Signed-off-by: Paul Cuzner <pcuzner@redhat.com>
src/cephadm/cephadm

index 594dff20c3492016f967d9d880fbe88287a9524f..9b541373d60d781e30e9002e1798286a97797074 100755 (executable)
@@ -4714,7 +4714,7 @@ class HostFacts():
         self.cpu_threads = 0
         self.interfaces = {}
 
-        self._memory = read_file(['/proc/meminfo'])
+        self._meminfo = read_file(['/proc/meminfo']).splitlines()
         self._get_cpuinfo()
         self._process_nics()
         self.arch = platform.processor()
@@ -4867,6 +4867,18 @@ class HostFacts():
         """Return the total capacity for all HDD devices (human readable format)"""
         return bytes_to_human(self.hdd_capacity_bytes)
 
+    @property
+    def cpu_load(self):
+        # type: () -> Dict[str, float]
+        """Return the cpu load average data for the host"""
+        raw = read_file(['/proc/loadavg']).strip()
+        data = raw.split()
+        return {
+            "1min": float(data[0]),
+            "5min": float(data[1]),
+            "15min": float(data[2]),
+        }
+
     @property
     def flash_count(self):
         # type: () -> int
@@ -4938,8 +4950,6 @@ class HostFacts():
                 else:
                     iftype = 'logical'
                     driver = ''
-                
-                
 
                 self.interfaces[iface] = {
                     "mtu": mtu,
@@ -4964,17 +4974,33 @@ class HostFacts():
                 phys_devs.append(iface)
         return len(phys_devs)
 
-    @property
-    def memory_kb(self):
-        # type: () -> int
-        """Determine the memory installed"""
-        out = self._memory.splitlines()
-        for line in out:
-            if line.startswith('MemTotal'):
+
+    def _get_mem_data(self, field_name):
+        # type: (str) -> int
+        for line in self._meminfo:
+            if line.startswith(field_name):
                 _d = line.split()
                 return int(_d[1])
         return 0
 
+    @property
+    def memory_total_kb(self):
+        # type: () -> int
+        """Determine the memory installed (kb)"""
+        return self._get_mem_data('MemTotal')
+    
+    @property
+    def memory_free_kb(self):
+        # type: () -> int
+        """Determine the memory free (not cache, immediately usable)"""
+        return self._get_mem_data('MemFree')
+
+    @property
+    def memory_available_kb(self):
+        # type: () -> int
+        """Determine the memory available to new applications without swapping"""
+        return self._get_mem_data('MemAvailable')
+
     @property
     def vendor(self):
         # type: () -> str
@@ -5020,7 +5046,7 @@ class HostFacts():
 
     @property
     def kernel_security(self):
-        # type: () -> Dict[str -> str]
+        # type: () -> Dict[str, str]
         """Determine the security features enabled in the kernel - SELinux, AppArmor"""
         def _fetch_selinux():
             """Read the selinux config file to determine state"""
@@ -5052,7 +5078,7 @@ class HostFacts():
                     except OSError:
                         pass
                     else:
-                        summary = {}
+                        summary = {}  # type: Dict[str, int]
                         for line in profiles.split('\n'):
                             item, mode = line.split(' ')
                             mode= mode.strip('()')
@@ -5061,7 +5087,7 @@ class HostFacts():
                             else:
                                 summary[mode] = 0
                         summary_str = ",".join(["{} {}".format(v, k) for k, v in summary.items()])
-                        security = {**security, **summary}
+                        security = {**security, **summary} # type: ignore
                         security['description'] += "({})".format(summary_str)
                     
                     return security