Browse Source

[2062] Update showtech tool to start showing info

Mukund Sivaraman 13 years ago
parent
commit
b2a7049b19

+ 36 - 7
src/bin/showtech/showtech.py.in

@@ -21,14 +21,43 @@ BIND 10 showtech program.
 """
 
 import sys; sys.path.append ('@@PYTHONPATH@@')
-from isc.sysinfo import CPU
-
-def show_cpu():
-    print("Number of processors (hyperthreads):")
-    print(CPU.get_num_processors())
+from isc.sysinfo import *
 
 def main():
-    show_cpu()
+    s = SysInfo()
+
+    print('BIND 10 ShowTech tool')
+    print('---------------------')
+
+    print('\nCPU');
+    print(' + Number of processors: ' + str(s.get_num_processors()))
+    print(' + Endianness: ' + s.get_endianness())
+
+    print('\nPlatform');
+    print(' + Operating system: ' + s.get_platform_name())
+    print(' + Kernel version: ' + s.get_platform_version())
+    if s.get_platform_is_smp():
+        print(' + SMP kernel: yes')
+    else:
+        print(' + SMP kernel: no')
+    print(' + Machine name: ' + s.get_platform_machine())
+    print(' + Uptime: %d seconds' % (s.get_uptime()))
+
+    l = s.get_loadavg()
+    print(' + Loadavg: %f %f %f' % (l[0], l[1], l[2]))
+
+    print('\nMemory');
+    print(' + Total: %d bytes' % (s.get_mem_total()))
+    print(' + Free: %d bytes' % (s.get_mem_free()))
+    print(' + Cached: %d bytes' % (s.get_mem_cached()))
+    print(' + Buffers: %d bytes' % (s.get_mem_buffers()))
+    print(' + Swap total: %d bytes' % (s.get_mem_swap_total()))
+    print(' + Swap free: %d bytes' % (s.get_mem_swap_free()))
+
+    print('\nNetwork');
+    print(' + Hostname: ' + s.get_hostname())
+
+    print('')
 
-if __name__ == "__main__":
+if __name__ == '__main__':
     main()

+ 1 - 2
src/lib/python/isc/sysinfo/Makefile.am

@@ -1,6 +1,5 @@
 python_PYTHON = __init__.py
-python_PYTHON += cpu.py
-python_PYTHON += platform.py
+python_PYTHON += sysinfo.py
 
 pythondir = $(pyexecdir)/isc/sysinfo
 

+ 1 - 1
src/lib/python/isc/sysinfo/__init__.py

@@ -1 +1 @@
-from isc.sysinfo.cpu import *
+from isc.sysinfo.sysinfo import *

+ 0 - 33
src/lib/python/isc/sysinfo/cpu.py

@@ -1,33 +0,0 @@
-# Copyright (C) 2012  Internet Systems Consortium, Inc. ("ISC")
-#
-# Permission to use, copy, modify, and distribute this software for any
-# purpose with or without fee is hereby granted, provided that the above
-# copyright notice and this permission notice appear in all copies.
-#
-# THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SYSTEMS CONSORTIUM
-# DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
-# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
-# INTERNET SYSTEMS CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
-# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
-# FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
-# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
-# WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-
-'''This module returns CPU information.'''
-
-import os
-import sys
-
-class CPU:
-    def get_num_cores():
-        # Not implemented
-        return -1
-
-    def get_num_processors():
-        # This is the number of hyperthreads when hyper-threading is
-        # used. This is not entirely portable, so we'll have to handle
-        # the case when it's not available.
-        return os.sysconf('SC_NPROCESSORS_CONF')
-
-    def get_endianness():
-        return sys.byteorder

+ 0 - 20
src/lib/python/isc/sysinfo/platform.py

@@ -1,20 +0,0 @@
-# Copyright (C) 2012  Internet Systems Consortium, Inc. ("ISC")
-#
-# Permission to use, copy, modify, and distribute this software for any
-# purpose with or without fee is hereby granted, provided that the above
-# copyright notice and this permission notice appear in all copies.
-#
-# THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SYSTEMS CONSORTIUM
-# DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
-# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
-# INTERNET SYSTEMS CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
-# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
-# FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
-# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
-# WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-
-'''This module returns platform information (about the distro).'''
-
-class Platform:
-    def get_arch():
-        return ""

+ 120 - 0
src/lib/python/isc/sysinfo/sysinfo.py

@@ -0,0 +1,120 @@
+# Copyright (C) 2012  Internet Systems Consortium, Inc. ("ISC")
+#
+# Permission to use, copy, modify, and distribute this software for any
+# purpose with or without fee is hereby granted, provided that the above
+# copyright notice and this permission notice appear in all copies.
+#
+# THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SYSTEMS CONSORTIUM
+# DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
+# INTERNET SYSTEMS CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
+# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
+# FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
+# WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+'''This module returns CPU information.'''
+
+import os
+import sys
+import re
+
+class SysInfo:
+    def __init__(self):
+        self._num_processors = os.sysconf('SC_NPROCESSORS_CONF')
+        self._endianness = sys.byteorder
+
+        with open('/proc/sys/kernel/hostname') as f:
+            self._hostname = f.read().strip()
+
+        u = os.uname()
+        self._platform_name = u[0]
+        self._platform_version = u[2]
+        self._platform_machine = u[4]
+
+        with open('/proc/version') as f:
+            self._platform_is_smp = ' SMP ' in f.read().strip()
+
+        with open('/proc/uptime') as f:
+            u = f.read().strip().split(' ')
+            self._uptime = int(round(float(u[0])))
+
+        with open('/proc/loadavg') as f:
+            l = f.read().strip().split(' ')
+            self._loadavg = [float(l[0]), float(l[1]), float(l[2])]
+
+        with open('/proc/meminfo') as f:
+            m = f.readlines()
+            for line in m:
+                r = re.match('^MemTotal:\s+(.*)\s*kB', line)
+                if r:
+                    self._mem_total = int(r.group(1).strip()) * 1024
+                    continue
+                r = re.match('^MemFree:\s+(.*)\s*kB', line)
+                if r:
+                    self._mem_free = int(r.group(1).strip()) * 1024
+                    continue
+                r = re.match('^Cached:\s+(.*)\s*kB', line)
+                if r:
+                    self._mem_cached = int(r.group(1).strip()) * 1024
+                    continue
+                r = re.match('^Buffers:\s+(.*)\s*kB', line)
+                if r:
+                    self._mem_buffers = int(r.group(1).strip()) * 1024
+                    continue
+                r = re.match('^SwapTotal:\s+(.*)\s*kB', line)
+                if r:
+                    self._mem_swap_total = int(r.group(1).strip()) * 1024
+                    continue
+                r = re.match('^SwapFree:\s+(.*)\s*kB', line)
+                if r:
+                    self._mem_swap_free = int(r.group(1).strip()) * 1024
+                    continue
+
+    def get_num_processors(self):
+        # This is the number of hyperthreads when hyper-threading is
+        # used. This is not entirely portable, so we'll have to handle
+        # the case when it's not available.
+        return self._num_processors
+
+    def get_endianness(self):
+        return self._endianness
+
+    def get_hostname(self):
+        return self._hostname
+
+    def get_platform_name(self):
+        return self._platform_name
+
+    def get_platform_version(self):
+        return self._platform_version
+
+    def get_platform_machine(self):
+        return self._platform_machine
+
+    def get_platform_is_smp(self):
+        return self._platform_is_smp
+
+    def get_uptime(self):
+        return self._uptime
+
+    def get_loadavg(self):
+        return self._loadavg
+
+    def get_mem_total(self):
+        return self._mem_total
+
+    def get_mem_free(self):
+        return self._mem_free
+
+    def get_mem_cached(self):
+        return self._mem_cached
+
+    def get_mem_buffers(self):
+        return self._mem_buffers
+
+    def get_mem_swap_total(self):
+        return self._mem_swap_total
+
+    def get_mem_swap_free(self):
+        return self._mem_swap_free