From daafb1c5cc2198a5e43e87721895be42f090a158 Mon Sep 17 00:00:00 2001 From: lxb <1580622474@qq.com> Date: Wed, 4 Dec 2024 16:49:50 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=96=B0=E6=94=B9=E9=80=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- client.py | 47 +++++++++++++++++++++++ data_define/client_data_example.json | 57 ++++++++++++++++++++++++++++ 3 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 client.py create mode 100644 data_define/client_data_example.json diff --git a/README.md b/README.md index 2d0240e..30ffbd9 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ ## 2.1. 运行环境 即运行后端程序所需的环境,可在conda中安装虚拟环境,linux和windows都可以。 ```bash -pip install flask flask-cors paramiko -i https://pypi.tuna.tsinghua.edu.cn/simple +pip install flask flask-cors paramiko psutil -i https://pypi.tuna.tsinghua.edu.cn/simple ``` ## 2.2. 服务器环境 即需要被查看的服务器上所安装的环境。 diff --git a/client.py b/client.py new file mode 100644 index 0000000..c459b60 --- /dev/null +++ b/client.py @@ -0,0 +1,47 @@ +import os +import json +import time +import psutil + +# region get data + +def get_gpus_info(): + # todo + pass + +def get_cpus_info(): + # cpu_usage_per_core = psutil.cpu_percent(interval=1, percpu=True) + # for i, usage in enumerate(cpu_usage_per_core): + # print(f"CPU核心 {i} 使用率: {usage}%") + + # print(psutil.sensors_temperatures()) + # 获取逻辑核心数(超线程技术下的线程数) + logical_cores = psutil.cpu_count() + print(f"Logical cores: {logical_cores}") + + # 获取物理核心数(实际的CPU核心数) + physical_cores = psutil.cpu_count(logical=False) + print(f"Physical cores: {physical_cores}") + +def get_storages_info(): + # todo + pass + +def get_memory_info(): + # todo + pass + +def get_networks_info(): + # todo + pass + +# endregion + +def main(): + get_cpus_info() + # cpu_usage_per_core = get_cpus_info() + # for i, usage in enumerate(cpu_usage_per_core): + # print(f"CPU核心 {i} 使用率: {usage}%") + +if __name__ == '__main__': + main() \ No newline at end of file diff --git a/data_define/client_data_example.json b/data_define/client_data_example.json new file mode 100644 index 0000000..4fc9a94 --- /dev/null +++ b/data_define/client_data_example.json @@ -0,0 +1,57 @@ +{ + "update_time_stamp": "1673082950", + "error_dict":{ + "gpu": "some error", + "cpu": "some error" + }, + "gpu_list":[ + { + "idx": 0, + "name": "RTX 3090", + "temperature": 100, + "used_memory": 1000, + "total_memory": 10240, + "utilization": 34, + "process_list":[ + { + "user": "lxb", + "memory": 100, + "cmd": "python run.py" + } + ] + } + ], + "cpu_list":[ + { + "idx": 0, + "name": "i5 6500", + "temperature": 50, + "core_avg_occupy": 31.25, + "core_occupy_list":[ + 12, + 23, + 0, + 90 + ] + } + ], + "storage_list":[ + { + "path": "/media/F", + "available": 211108624, + "total": 5813178480 + } + ], + "memory":{ + "total": 1935468, + "used": 1382196 + }, + "network_list":[ + { + "name": "eth0", + "default": true, + "in": 67.8, + "out": 12.3 + } + ] +} \ No newline at end of file