cpu-loader 0.3.0__tar.gz → 0.4.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {cpu_loader-0.3.0/src/cpu_loader.egg-info → cpu_loader-0.4.2}/PKG-INFO +1 -1
- {cpu_loader-0.3.0 → cpu_loader-0.4.2}/pyproject.toml +1 -1
- {cpu_loader-0.3.0 → cpu_loader-0.4.2}/src/cpu_loader/cpu_loader.py +1 -0
- {cpu_loader-0.3.0 → cpu_loader-0.4.2}/src/cpu_loader/main.py +13 -13
- {cpu_loader-0.3.0 → cpu_loader-0.4.2}/src/cpu_loader/mqtt_publisher.py +8 -2
- {cpu_loader-0.3.0 → cpu_loader-0.4.2}/src/cpu_loader/static/favicon.svg +5 -1
- {cpu_loader-0.3.0 → cpu_loader-0.4.2}/src/cpu_loader/templates/index.html +2 -2
- {cpu_loader-0.3.0 → cpu_loader-0.4.2/src/cpu_loader.egg-info}/PKG-INFO +1 -1
- {cpu_loader-0.3.0 → cpu_loader-0.4.2}/LICENSE +0 -0
- {cpu_loader-0.3.0 → cpu_loader-0.4.2}/MANIFEST.in +0 -0
- {cpu_loader-0.3.0 → cpu_loader-0.4.2}/README.md +0 -0
- {cpu_loader-0.3.0 → cpu_loader-0.4.2}/setup.cfg +0 -0
- {cpu_loader-0.3.0 → cpu_loader-0.4.2}/setup.py +0 -0
- {cpu_loader-0.3.0 → cpu_loader-0.4.2}/src/cpu_loader/__init__.py +0 -0
- {cpu_loader-0.3.0 → cpu_loader-0.4.2}/src/cpu_loader/__main__.py +0 -0
- {cpu_loader-0.3.0 → cpu_loader-0.4.2}/src/cpu_loader/cpu_loader_core.c +0 -0
- {cpu_loader-0.3.0 → cpu_loader-0.4.2}/src/cpu_loader/example.py +0 -0
- {cpu_loader-0.3.0 → cpu_loader-0.4.2}/src/cpu_loader.egg-info/SOURCES.txt +0 -0
- {cpu_loader-0.3.0 → cpu_loader-0.4.2}/src/cpu_loader.egg-info/dependency_links.txt +0 -0
- {cpu_loader-0.3.0 → cpu_loader-0.4.2}/src/cpu_loader.egg-info/entry_points.txt +0 -0
- {cpu_loader-0.3.0 → cpu_loader-0.4.2}/src/cpu_loader.egg-info/requires.txt +0 -0
- {cpu_loader-0.3.0 → cpu_loader-0.4.2}/src/cpu_loader.egg-info/top_level.txt +0 -0
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
CPU Loader FastAPI Application
|
|
3
3
|
Provides REST API and WebUI for controlling CPU load.
|
|
4
4
|
"""
|
|
5
|
+
|
|
5
6
|
import argparse
|
|
6
7
|
import asyncio
|
|
7
8
|
import logging
|
|
@@ -12,7 +13,7 @@ from typing import Dict, List, Optional, Set
|
|
|
12
13
|
import psutil
|
|
13
14
|
import uvicorn
|
|
14
15
|
from fastapi import FastAPI, HTTPException, WebSocket, WebSocketDisconnect
|
|
15
|
-
from fastapi.responses import
|
|
16
|
+
from fastapi.responses import FileResponse, HTMLResponse
|
|
16
17
|
from fastapi.staticfiles import StaticFiles
|
|
17
18
|
from pydantic import BaseModel, Field
|
|
18
19
|
|
|
@@ -62,36 +63,37 @@ mqtt_publisher: Optional[MQTTPublisher] = None
|
|
|
62
63
|
websocket_connections: Set[WebSocket] = set()
|
|
63
64
|
monitoring_task = None
|
|
64
65
|
temperature_monitoring_enabled = True
|
|
66
|
+
temperature_monitoring_enabled = True
|
|
65
67
|
|
|
66
68
|
|
|
67
69
|
def get_cpu_temperature() -> Optional[float]:
|
|
68
70
|
"""Get CPU temperature if available and enabled."""
|
|
69
71
|
if not temperature_monitoring_enabled:
|
|
70
72
|
return None
|
|
71
|
-
|
|
73
|
+
|
|
72
74
|
try:
|
|
73
75
|
# Try to get CPU temperature using psutil
|
|
74
76
|
temperatures = psutil.sensors_temperatures()
|
|
75
|
-
|
|
77
|
+
|
|
76
78
|
# Common temperature sensor names to check
|
|
77
|
-
temp_names = [
|
|
78
|
-
|
|
79
|
+
temp_names = ["coretemp", "cpu_thermal", "acpi", "k8temp", "k10temp"]
|
|
80
|
+
|
|
79
81
|
for temp_name in temp_names:
|
|
80
82
|
if temp_name in temperatures:
|
|
81
83
|
# Get the first temperature reading
|
|
82
84
|
temp_list = temperatures[temp_name]
|
|
83
85
|
if temp_list:
|
|
84
86
|
return round(temp_list[0].current, 1)
|
|
85
|
-
|
|
87
|
+
|
|
86
88
|
# If no specific sensor found, try the first available
|
|
87
89
|
for sensor_name, temp_list in temperatures.items():
|
|
88
90
|
if temp_list:
|
|
89
91
|
return round(temp_list[0].current, 1)
|
|
90
|
-
|
|
92
|
+
|
|
91
93
|
except (AttributeError, OSError, ImportError):
|
|
92
94
|
# Temperature monitoring not available on this system
|
|
93
95
|
pass
|
|
94
|
-
|
|
96
|
+
|
|
95
97
|
return None
|
|
96
98
|
|
|
97
99
|
|
|
@@ -108,7 +110,7 @@ async def cpu_monitoring_loop():
|
|
|
108
110
|
# Get CPU metrics (non-blocking after first call)
|
|
109
111
|
per_cpu = psutil.cpu_percent(interval=None, percpu=True)
|
|
110
112
|
total_cpu = sum(per_cpu) / len(per_cpu) if per_cpu else 0.0
|
|
111
|
-
|
|
113
|
+
|
|
112
114
|
# Get CPU temperature if available
|
|
113
115
|
cpu_temp = get_cpu_temperature()
|
|
114
116
|
|
|
@@ -238,9 +240,7 @@ async def get_cpu_metrics():
|
|
|
238
240
|
total_cpu = psutil.cpu_percent(interval=0)
|
|
239
241
|
cpu_temp = get_cpu_temperature()
|
|
240
242
|
return CPUMetricsResponse(
|
|
241
|
-
total_cpu_percent=total_cpu,
|
|
242
|
-
per_cpu_percent=per_cpu,
|
|
243
|
-
cpu_temperature=cpu_temp
|
|
243
|
+
total_cpu_percent=total_cpu, per_cpu_percent=per_cpu, cpu_temperature=cpu_temp
|
|
244
244
|
)
|
|
245
245
|
|
|
246
246
|
|
|
@@ -366,7 +366,7 @@ def run():
|
|
|
366
366
|
"""Entry point for the CPU Loader application."""
|
|
367
367
|
global temperature_monitoring_enabled
|
|
368
368
|
args = parse_args()
|
|
369
|
-
|
|
369
|
+
|
|
370
370
|
# Set temperature monitoring based on CLI argument
|
|
371
371
|
temperature_monitoring_enabled = not args.disable_temperature
|
|
372
372
|
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
MQTT Publisher Module
|
|
3
3
|
Publishes CPU load control settings and metrics to MQTT broker.
|
|
4
4
|
"""
|
|
5
|
+
|
|
5
6
|
import json
|
|
6
7
|
import logging
|
|
7
8
|
import os
|
|
@@ -144,7 +145,12 @@ class MQTTPublisher:
|
|
|
144
145
|
except Exception as e:
|
|
145
146
|
logger.error(f"Failed to publish load settings: {e}")
|
|
146
147
|
|
|
147
|
-
def publish_cpu_metrics(
|
|
148
|
+
def publish_cpu_metrics(
|
|
149
|
+
self,
|
|
150
|
+
total_cpu_percent: float,
|
|
151
|
+
per_cpu_percent: list,
|
|
152
|
+
cpu_temperature: Optional[float] = None,
|
|
153
|
+
):
|
|
148
154
|
"""
|
|
149
155
|
Publish CPU metrics to MQTT.
|
|
150
156
|
|
|
@@ -162,7 +168,7 @@ class MQTTPublisher:
|
|
|
162
168
|
"total_cpu_percent": round(total_cpu_percent, 1),
|
|
163
169
|
"per_cpu_percent": [round(cpu, 1) for cpu in per_cpu_percent],
|
|
164
170
|
}
|
|
165
|
-
|
|
171
|
+
|
|
166
172
|
# Add temperature if available
|
|
167
173
|
if cpu_temperature is not None:
|
|
168
174
|
payload["cpu_temperature"] = cpu_temperature
|
|
@@ -31,4 +31,8 @@
|
|
|
31
31
|
<rect x="13" y="14" width="2" height="6" fill="#FFC107"/>
|
|
32
32
|
<rect x="16" y="10" width="2" height="10" fill="#F44336"/>
|
|
33
33
|
<rect x="19" y="16" width="2" height="4" fill="#2196F3"/>
|
|
34
|
-
|
|
34
|
+
<<<<<<< HEAD
|
|
35
|
+
</svg>
|
|
36
|
+
=======
|
|
37
|
+
</svg>
|
|
38
|
+
>>>>>>> 0b500ee (feat: add CPU temperature monitoring and update related UI components)
|
|
@@ -288,10 +288,10 @@
|
|
|
288
288
|
const tempContainer = document.getElementById('cpu-temperature-container');
|
|
289
289
|
const tempValue = document.getElementById('cpu-temperature-value');
|
|
290
290
|
const tempBar = document.getElementById('cpu-temperature-bar');
|
|
291
|
-
|
|
291
|
+
|
|
292
292
|
tempContainer.style.display = 'block';
|
|
293
293
|
tempValue.textContent = `${data.cpu_temperature}°C`;
|
|
294
|
-
|
|
294
|
+
|
|
295
295
|
// Scale temperature (0-100°C -> 0-100%)
|
|
296
296
|
const tempPercent = Math.min(100, Math.max(0, data.cpu_temperature));
|
|
297
297
|
tempBar.style.width = `${tempPercent}%`;
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|