Report per-core CPU percentages alongside the overall figure
Derived from the same percpu psutil.cpu_percent() call rather than a second blocking call, so the aggregate and the per-core breakdown describe the same sampling window.
This commit is contained in:
@@ -183,7 +183,12 @@ def _network() -> dict:
|
||||
|
||||
|
||||
def collect() -> dict:
|
||||
cpu_percent = psutil.cpu_percent(interval=0.3)
|
||||
# A single percpu=True call gives every core's percent over the same
|
||||
# sampling window; the overall figure is derived from it (its mean)
|
||||
# instead of a second separate blocking call, so both numbers describe
|
||||
# the same 0.3s window rather than two slightly different ones.
|
||||
per_core_percent = psutil.cpu_percent(interval=0.3, percpu=True)
|
||||
cpu_percent = round(sum(per_core_percent) / len(per_core_percent), 1) if per_core_percent else 0.0
|
||||
vm = psutil.virtual_memory()
|
||||
swap = psutil.swap_memory()
|
||||
boot_time = psutil.boot_time()
|
||||
@@ -197,6 +202,7 @@ def collect() -> dict:
|
||||
"cores": psutil.cpu_count(logical=True) or 0,
|
||||
"model": _cpu_model(),
|
||||
"loadAverage": _load_average(),
|
||||
"perCore": per_core_percent,
|
||||
},
|
||||
"memory": {
|
||||
"totalBytes": vm.total,
|
||||
|
||||
Reference in New Issue
Block a user