Skip to content

Instantly share code, notes, and snippets.

@SimonLeeGit
Created May 8, 2021 06:07
Show Gist options
  • Save SimonLeeGit/faec10d676a9bf41b302f93124a2ca89 to your computer and use it in GitHub Desktop.
Save SimonLeeGit/faec10d676a9bf41b302f93124a2ca89 to your computer and use it in GitHub Desktop.
check linux system info when necessary
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import os, sys
import json
import logging
import traceback
import psutil
import time
import preprocess_error
logger = logging.getLogger(__name__)
class CheckSystemInfo(object):
def __init__(self, params_obj, server, data_paths, perf_info):
self.data_paths = data_paths
self.perf_result = perf_info.info.add()
self.perf_result.step = 'preprocess'
self.perf_result.substep = 'check_system_info'
def DoProc(self):
print("[check_system_info]: before proc ++++++++++++++++++++++++++++++++++++++++")
self.perf_result.begin_time = int(time.time() * 1e3)
# CPU Info
print("CPU -----------------------------------------------------")
print("cpu logic core num: {}".format(psutil.cpu_count()))
print("cpu phys core num: {}".format(psutil.cpu_count(logical=False)))
print(psutil.cpu_times())
# Memory Info
print("Memory --------------------------------------------------")
print(psutil.virtual_memory())
print(psutil.swap_memory())
# Disk Info
print("Disk ----------------------------------------------------")
print(psutil.disk_usage('/'))
# Process Info
print("Process -------------------------------------------------")
print(psutil.test())
self.perf_result.end_time = int(time.time() * 1e3)
print("[check_system_info]: proc done! ++++++++++++++++++++++++++++++++++++++++")
return True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment