|
4 | 4 | from app.services.vm_service import VmService |
5 | 5 | from app.core.config import system_monitor |
6 | 6 |
|
7 | | -# cpu_total_usage = 0 |
8 | | -# usage_per_cpu = [] |
9 | | - |
10 | | -# def get_cpu_usage_percent(cpu_idle_time_t2, cpu_idle_time_t1, cpu_total_time_t2, cpu_total_time_t1): |
11 | | -# return (1 - (cpu_idle_time_t2 - cpu_idle_time_t1)/ |
12 | | -# (sum(cpu_total_time_t2) - sum(cpu_total_time_t1))) * 100 |
13 | | - |
14 | | -# def get_cpu_counters(): |
15 | | -# per_cpus = psutil.cpu_times(percpu=True) |
16 | | -# total = Counter() |
17 | | -# for cpu in per_cpus: |
18 | | -# total.update(cpu._asdict()) |
19 | | -# cpu_total = psutil.cpu_times() |
20 | | -# return { |
21 | | -# "per_cpus": per_cpus, |
22 | | -# "cpu_total": cpu_total |
23 | | -# } |
24 | | - |
25 | | -# def get_cpu_usage(): |
26 | | -# global cpu_total_usage, usage_per_cpu |
27 | | -# while True: |
28 | | -# cpu_usage_t1 = get_cpu_counters() |
29 | | -# sleep(3) |
30 | | -# cpu_usage_t2 = get_cpu_counters() |
31 | | -# cpu_total_usage = get_cpu_usage_percent(cpu_usage_t2["cpu_total"].idle, cpu_usage_t1["cpu_total"].idle, cpu_usage_t2["cpu_total"], cpu_usage_t1["cpu_total"]) |
32 | | -# usage_per_cpu = [] |
33 | | -# for i in range(len(cpu_usage_t1["per_cpus"])): |
34 | | -# usage_per_cpu.append(round(get_cpu_usage_percent(cpu_usage_t2["per_cpus"][i].idle, cpu_usage_t1["per_cpus"][i].idle, cpu_usage_t2["per_cpus"][i], cpu_usage_t1["per_cpus"][i]), 2)) |
35 | | - |
36 | | - |
37 | | -# Thread(target=get_cpu_usage, daemon=True).start() |
38 | | - |
39 | | -# cpu_overall_time_t1 = psutil.cpu_times(percpu=True) |
40 | | -# cpu_total_time_t1 = psutil.cpu_times() |
41 | | -# print(sum(cpu_total_time_t1)) |
42 | | -# cpu_idle_time_t1 = cpu_total_time_t1.idle |
43 | | - |
44 | | - |
45 | | -# sleep(3) |
46 | | -# cpu_total_time_t2 = psutil.cpu_times() |
47 | | -# cpu_idle_time_t2 = cpu_total_time_t2.idle |
48 | | - |
49 | | -# percent_used = (1 - (cpu_idle_time_t2 - cpu_idle_time_t1)/ (sum(cpu_total_time_t2) - sum(cpu_total_time_t1))) * 100 |
50 | | -# print(percent_used) |
51 | | -# print(psutil.cpu_percent(interval=1)) |
52 | | -# print(sum(psutil.cpu_times(percpu=True))) |
53 | | - |
54 | | - |
55 | | -# print(psutil.cpu_times_percent(interval=2)) |
56 | | - |
57 | | - |
58 | | -# for dom_stats in stats: |
59 | | -# data = dom_stats[1] |
60 | | -# print(data.get('cpu.system')) |
61 | 7 |
|
62 | 8 | class HostService: |
63 | 9 |
|
|
0 commit comments