RC: (update) script to save load history

This commit is contained in:
2026-03-31 15:06:30 +00:00
parent f5dea6770e
commit bb3ce618ca

View File

@@ -9,7 +9,7 @@ from http.server import BaseHTTPRequestHandler, HTTPServer
# --- CONFIGURATION ---
PORT = 8080
IFACE = "vmbr0"
IFACE = "bond0"
ENABLE_PVE_STATS = True
# ---------------------
@@ -18,6 +18,7 @@ hist_cpu = deque([0]*60, maxlen=60)
hist_ram = deque([0]*60, maxlen=60)
hist_rx = deque([0.0]*60, maxlen=60)
hist_tx = deque([0.0]*60, maxlen=60)
hist_load = deque([0.0]*60, maxlen=60)
# Dictionary to hold the most recent slow-changing data
latest_state = {}
@@ -60,10 +61,9 @@ def background_poller():
hist_cpu.append(round(cpu_pct, 1))
prev_idle, prev_total = idle, total
# 2. Network Delta Calculation (Changed to Mbps)
# 2. Network Delta Calculation
rx_now = int(run_cmd(f"cat /sys/class/net/{IFACE}/statistics/rx_bytes") or 0)
tx_now = int(run_cmd(f"cat /sys/class/net/{IFACE}/statistics/tx_bytes") or 0)
# Multiply by 8 for bits, divide by 1,000,000 for Megabits
hist_rx.append(round(((rx_now - rx_prev) * 8) / 1000000, 2))
hist_tx.append(round(((tx_now - tx_prev) * 8) / 1000000, 2))
@@ -81,7 +81,12 @@ def background_poller():
"total_gb": round(ram_total / (1024**3), 1)
}
# 4. Storage & System Health
# 4. System Load (ADD THIS BLOCK)
load1, load5, load15 = os.getloadavg()
hist_load.append(round(load1, 2))
latest_state["load_avg"] = [round(load1, 2), round(load5, 2), round(load15, 2)]
# 5. Storage & System Health
st = os.statvfs('/')
latest_state["root_disk_pct"] = round((1.0 - (st.f_bavail / st.f_blocks)) * 100.0, 1)
@@ -108,6 +113,8 @@ class MetricsHandler(BaseHTTPRequestHandler):
data["cpu_hist"] = list(hist_cpu)
data["ram_hist"] = list(hist_ram)
data["load_hist"] = list(hist_load)
data["rx_hist"] = list(hist_rx)
data["tx_hist"] = list(hist_tx)