sysinfo.py.in 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. #!@PYTHON@
  2. # Copyright (C) 2012 Internet Systems Consortium.
  3. #
  4. # Permission to use, copy, modify, and distribute this software for any
  5. # purpose with or without fee is hereby granted, provided that the above
  6. # copyright notice and this permission notice appear in all copies.
  7. #
  8. # THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SYSTEMS CONSORTIUM
  9. # DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
  10. # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
  11. # INTERNET SYSTEMS CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
  12. # INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
  13. # FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
  14. # NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
  15. # WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  16. """
  17. BIND 10 showtech program.
  18. """
  19. import sys; sys.path.append ('@@PYTHONPATH@@')
  20. import getopt
  21. import isc.util.process
  22. from isc.sysinfo import *
  23. isc.util.process.rename()
  24. def usage():
  25. print("Usage: %s [-h] [-o <output-file>]" % sys.argv[0], \
  26. file=sys.stderr)
  27. exit(1)
  28. def main():
  29. try:
  30. opts, args = getopt.getopt(sys.argv[1:], "o:h", \
  31. ["output", "help"])
  32. except getopt.GetoptError as e:
  33. print(str(e))
  34. usage()
  35. exit(1)
  36. output_filename = None
  37. for option, arg in opts:
  38. if option in ("-o", "--output"):
  39. output_filename = arg
  40. elif option in ("-h", "--help"):
  41. usage()
  42. else:
  43. assert False, "unhandled option"
  44. if output_filename is None:
  45. f = sys.stdout
  46. else:
  47. f = open(output_filename, 'w')
  48. s = SysInfoFromFactory()
  49. f.write('BIND 10 ShowTech tool\n')
  50. f.write('=====================\n')
  51. f.write('\nCPU\n');
  52. f.write(' + Number of processors: %d\n' % (s.get_num_processors()))
  53. f.write(' + Endianness: %s\n' % (s.get_endianness()))
  54. f.write('\nPlatform\n');
  55. f.write(' + Operating system: %s\n' % (s.get_platform_name()))
  56. f.write(' + Distribution: %s\n' % (s.get_platform_distro()))
  57. f.write(' + Kernel version: %s\n' % (s.get_platform_version()))
  58. f.write(' + SMP kernel: ')
  59. if s.get_platform_is_smp():
  60. f.write('yes')
  61. else:
  62. f.write('no')
  63. f.write('\n')
  64. f.write(' + Machine name: %s\n' % (s.get_platform_machine()))
  65. f.write(' + Hostname: %s\n' % (s.get_platform_hostname()))
  66. f.write(' + Uptime: %d seconds\n' % (s.get_uptime()))
  67. l = s.get_loadavg()
  68. f.write(' + Loadavg: %f %f %f\n' % (l[0], l[1], l[2]))
  69. f.write('\nMemory\n');
  70. f.write(' + Total: %d bytes\n' % (s.get_mem_total()))
  71. f.write(' + Free: %d bytes\n' % (s.get_mem_free()))
  72. f.write(' + Cached: %d bytes\n' % (s.get_mem_cached()))
  73. f.write(' + Buffers: %d bytes\n' % (s.get_mem_buffers()))
  74. f.write(' + Swap total: %d bytes\n' % (s.get_mem_swap_total()))
  75. f.write(' + Swap free: %d bytes\n' % (s.get_mem_swap_free()))
  76. f.write('\n\nNetwork\n');
  77. f.write('-------\n\n');
  78. f.write('Interfaces\n')
  79. f.write('~~~~~~~~~~\n\n')
  80. f.write(s.get_net_interfaces())
  81. f.write('\nRouting table\n')
  82. f.write('~~~~~~~~~~~~~\n\n')
  83. f.write(s.get_net_routing_table())
  84. f.write('\nStatistics\n')
  85. f.write('~~~~~~~~~~\n\n')
  86. f.write(s.get_net_stats())
  87. f.write('\nConnections\n')
  88. f.write('~~~~~~~~~~~\n\n')
  89. f.write(s.get_net_connections())
  90. try:
  91. if os.getuid() != 0:
  92. sys.stderr.write('\n')
  93. sys.stderr.write('NOTE: You have to run this program as the root user so that it can\n')
  94. sys.stderr.write(' collect all the information it requires. Some information is\n')
  95. sys.stderr.write(' only available to the root user.\n\n')
  96. except Exception:
  97. pass
  98. if f != sys.stdout:
  99. f.close()
  100. if __name__ == '__main__':
  101. main()