-#
-# sysinfo.py
-#
-# Get standard system information from basic Unix commands
-#
+"""
+Get standard system information from basic Unix commands
+"""
import platform
import subprocess
import os
import re
+from datetime import timedelta
+from multiprocessing import cpu_count
from logparse.formatting import *
from logparse.config import prefs
section = Section("system")
table = Table()
- table.add_row(Row([Column("Hostname"), Column(util.hostname(prefs.get("logparse", "hostname-path")))]))
+ table.add_row(Row([Column("Hostname"),
+ Column(util.hostname(prefs.get("logparse", "hostname-path")))]))
table.add_row(Row([Column("OS"), Column(platform.platform())]))
table.add_row(Row([Column("OS version"), Column(platform.version())]))
- table.add_row(Row([Column("Platform"), Column(platform.system() + " " + platform.machine())]))
+ table.add_row(Row([Column("Platform"),
+ Column(platform.system() + " " + platform.machine())]))
processors = []
raw_proc = util.readlog(prefs.get("logs", "cpuinfo"))
for line in raw_proc.splitlines():
if "model name" in line:
processor = line_regex.sub("", line, 1)
- processor = " ".join(proc_regex.sub("", processor).split()) # remove extraneous text and whitespace
+ # Remove extraneous text and whitespace:
+ processor = " ".join(proc_regex.sub("", processor).split())
if not processor in processors:
processors.append(processor)
else:
- logger.debug("Found duplicate entry (perhaps multiple cores?) for {0}".format(processor))
+ logger.debug("Found duplicate entry (perhaps multiple "
+ "cores?) for {0}".format(processor))
table.align_column(0, "right")
if len(processors) == 1:
- table.add_row(Row([Column("Processor"), Column("; ".join(processors))]))
+ table.add_row(Row([Column("Processor"),
+ Column("; ".join(processors))]))
section.append_table(table)
elif len(processors) > 1:
section.append_table(table)
else:
logger.warning("Failed to find processor data")
+ raw_uptime = util.readlog(prefs.get("logs", "uptime")).split("\n")[0]
+ logger.debug("Found uptime data " + str(raw_uptime))
+
+ uptime_total = float(raw_uptime.split()[0])
+ table.add_row(Row([Column("Uptime"),
+ Column("%d d %d h %d m" % (
+ uptime_total // 86400,
+ uptime_total % 86400 // 3600,
+ uptime_total % 3600 // 60))]))
+
+ idle_time = float(raw_uptime.split()[1]) / cpu_count()
+ m, s = divmod(idle_time, 60)
+ h, m = divmod(m, 60)
+ table.add_row(Row([Column("Idle time"),
+ Column("%d d %d h %d m per core (avg)" % (
+ idle_time // 86400,
+ idle_time % 86400 // 3600,
+ idle_time % 3600 // 60))]))
+
logger.info("Finished sysinfo section")
return section