time_content = subprocess.Popen(
"timedatectl status | grep Time",
content, _ = time_content.communicate()
time_zone = content.strip().split(": ")[-1]
time_zone = time_zone.strip()
self.sys['time_zone'] = time_zone
self.sys["cpu"]["cpu_percent"] = psutil.cpu_percent()
"top -bn 1 | grep -v 'grep' | grep '%Cpu(s):'",
if cpus.returncode is None:
cpus = cpus.stdout.read().split()
cpus = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
self.sys["cpu"]["user"] = cpus[1]
self.sys["cpu"]["system"] = cpus[3]
self.sys["cpu"]["idle"] = cpus[7]
self.sys["cpu"]["cpus"] = psutil.cpu_percent(percpu=True)
total_disk, used_total = 0, 0
for i in psutil.disk_partitions():
mountpoint = i.mountpoint
if "home" in mountpoint and "docker" in mountpoint:
used = psutil.disk_usage(i.mountpoint).used
mountpoint_list = mountpoint.split("/")
if len(mountpoint_list) == 2:
total_disk += psutil.disk_usage(i.mountpoint).total
disk_remain = total_disk - used_total
self.sys['disk']['total'] = total_disk
self.sys['disk']['used'] = used_total
self.sys['disk']['remain'] = disk_remain
self.sys["memory"]["total"] = psutil.virtual_memory().total
self.sys["memory"]["percent"] = psutil.virtual_memory().percent
self.sys["memory"]["used"] = psutil.virtual_memory().used
self.sys["memory"]["free"] = psutil.virtual_memory().free
self.sys["memory"]["cached"] = (
psutil.virtual_memory().buffers + psutil.virtual_memory().cached
self.sys["memory"]["swap"] = psutil.swap_memory().used
counters = psutil.net_io_counters(" ")
self.sys["traffic"] = {"send": 0, "recv": 0}
if "veth" in counter or "lo" in counter or "docker" in counter:
self.sys["traffic"]["send"] += counters[counter].bytes_sent
self.sys["traffic"]["recv"] += counters[counter].bytes_recv
if __name__ == "__main__":