예제 #1
0
def build_sysinfo_page():
    contents = ["<html><head><title>System Information</title></head><body>"]
    contents.append("<h1>System Information</h1>")
    contents.append("The current time is %s" % timestamp.get_pretty())

    def add(key, val):
        contents.append("<tr><td><i>%s</i></td><td>%s</td></tr>" % (key, val))

    contents.append("<h2>Process</h2>")
    contents.append("<table>")
    add("command line", " ".join(sys.argv))

    start_ms = timestamp.process_start_time_ms()
    age_ms = timestamp.process_age_ms()
    add("started at", timestamp.get_pretty_ms(start_ms))
    add("running for", timestamp.get_human_readable_duration(age_ms / 1000.0))

    add("process pid", os.getpid())
    gc_counts = gc.get_count()
    add("live objects", "%d (%s)" % (sum(gc_counts),
                                     " / ".join(str(x) for x in gc_counts)))

    add("live threads", threading.activeCount())

    cpu_s, sys_cpu_s = os.times()[:2]
    cpu_percent = 100 * (1000 * cpu_s) / age_ms
    sys_cpu_percent = 100 * (1000 * sys_cpu_s) / age_ms
    add("cpu utilization", "%.2f%%" % cpu_percent)
    add("system cpu", "%.2f%%" % sys_cpu_percent)


    add("Python version", sys.version)

    contents.append("</table>")
    contents.append("<h2>Machine</h2>")
    contents.append("<table>")

    add("hostname", socket.gethostname())
    add("uname", " / ".join(os.uname()))
    add("load average", " / ".join(str(x) for x in os.getloadavg()))
    add("uptime", timestamp.get_human_readable_duration(os.times()[-1]))
        
    contents.append("</table>")
    contents.append("</body></html>")
    return "\n".join(contents)
 def test_human_readable_durations(self):
     self.assertEqual("17.000 secs", timestamp.get_human_readable_duration(17))
     self.assertEqual("1 min, 0.000 secs", timestamp.get_human_readable_duration(60))
     self.assertEqual("1 min, 17.000 secs", timestamp.get_human_readable_duration(77))
     self.assertEqual("2 mins, 0.000 secs", timestamp.get_human_readable_duration(120))
     self.assertEqual("1 hr, 0.000 secs", timestamp.get_human_readable_duration(3600))
     self.assertEqual("3 hrs, 25 mins, 45.000 secs", timestamp.get_human_readable_duration(12345))
     self.assertEqual("1 day, 10 hrs, 17 mins, 36.000 secs", timestamp.get_human_readable_duration(123456))
예제 #3
0
 def test_human_readable_durations(self):
     self.assertEqual("17.000 secs",
                      timestamp.get_human_readable_duration(17))
     self.assertEqual("1 min, 0.000 secs",
                      timestamp.get_human_readable_duration(60))
     self.assertEqual("1 min, 17.000 secs",
                      timestamp.get_human_readable_duration(77))
     self.assertEqual("2 mins, 0.000 secs",
                      timestamp.get_human_readable_duration(120))
     self.assertEqual("1 hr, 0.000 secs",
                      timestamp.get_human_readable_duration(3600))
     self.assertEqual("3 hrs, 25 mins, 45.000 secs",
                      timestamp.get_human_readable_duration(12345))
     self.assertEqual("1 day, 10 hrs, 17 mins, 36.000 secs",
                      timestamp.get_human_readable_duration(123456))