From 5e4c275bf0680a4d3af8bb57130437fc0a420427 Mon Sep 17 00:00:00 2001 From: zhanghan2021 Date: Tue, 21 Nov 2023 19:12:14 +0800 Subject: [PATCH] get cpu stat and pid --- category/get_cpu_info.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/category/get_cpu_info.py b/category/get_cpu_info.py index df73628..52eff87 100644 --- a/category/get_cpu_info.py +++ b/category/get_cpu_info.py @@ -34,6 +34,27 @@ class CPUInfo: res_all = res_lscpu + res_cpuinfo return Command.cmd_write_file(res_all, self.__default_file_name) + @GlobalCall.monitor_info_thread_pool.threaded_pool + def __get_pid_cpustat_info(self): + ''' + pidstat + ''' + pidstat_command = "pidstat -w 1 1" + cmd_name = 'pidstat' + cmd_result = Command.cmd_run(pidstat_command) + res_all = FileOperation.wrap_output_format(cmd_name, cmd_result,'-') + + pidstat_command="pidstat |sort -ir -k 9" + for i in range(5): + cmd_result = Command.cmd_run(pidstat_command) + if i == 0 : + result = cmd_result.split('\n',1)[0] + '\n' + cmd_result.split('\n',1)[1].rsplit('\n',3)[1] + '\n\n' + result += cmd_result.split('\n',1)[1].rsplit('\n',3)[0] + '\n\n' + + sleep(1) + res_all += FileOperation.wrap_output_format(cmd_name, result,'=') + return Command.cmd_write_file(res_all, self.__default_file_name) + # getInfo def get_info(self): self.__get_cpu_info() -- Gitee