Skip to content

Commit 8656d3a

Browse files
author
Tony Brüser
committed
Rollback
1 parent 4ae02e2 commit 8656d3a

File tree

13 files changed

+21
-292
lines changed

13 files changed

+21
-292
lines changed

README.de.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,11 @@ Zusätzlich steht nun ein **interaktives Terminal** über die Weboberfläche zur
2525
- Sammelt:
2626
- CPU-Auslastung (%)
2727
- Speicherauslastung (%)
28-
- Swap-Nutzung (%)
2928
- Gesamter RAM (MB)
3029
- Festplattenauslastung (% für `/`)
3130
- Netzwerkdurchsatz (Bytes/s, ein- und ausgehend)
3231
- Laufzeit (Sekunden)
3332
- Temperatur (°C, falls verfügbar)
34-
- Hardware- und Sensorwerte (z. B. Lüfterdrehzahlen, Spannungen, GPU-/SoC-Temperaturen, Stromverbrauch, sofern `lm-sensors` verfügbar)
3533
- CPU-Kerne
3634
- Last (1/5/15 Minuten)
3735
- CPU-Frequenz (MHz)
@@ -152,7 +150,6 @@ Für jeden Server sind folgende Entitäten verfügbar:
152150

153151
- `sensor.<name>_cpu` – CPU-Auslastung (%)
154152
- `sensor.<name>_mem` – Speicherauslastung (%)
155-
- `sensor.<name>_swap` – Swap-Nutzung (%)
156153
- `sensor.<name>_disk` – Festplattenauslastung (%)
157154
- `sensor.<name>_net_in` – Netzwerkeingang (Bytes/s)
158155
- `sensor.<name>_net_out` – Netzwerkausgang (Bytes/s)
@@ -172,7 +169,6 @@ Für jeden Server sind folgende Entitäten verfügbar:
172169
- `sensor.<name>_vnc` – "ja", wenn ein VNC-Server erkannt wurde
173170
- `sensor.<name>_web` – "ja", wenn ein HTTP- oder HTTPS-Dienst lauscht
174171
- `sensor.<name>_ssh` – "ja", wenn der SSH-Dienst lauscht
175-
- `sensor.<name>_local_ip` – Lokale IP-Adresse
176172
- Für jeden laufenden Container: `sensor.<name>_container_<container>_cpu` (CPU-Auslastung %) und `sensor.<name>_container_<container>_mem` (Speicherauslastung %)
177173

178174
---

README.es.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,11 @@ Además de la recopilación de estadísticas, el complemento incluye ahora un te
2626
- Recopila:
2727
- Uso de CPU (%)
2828
- Uso de memoria (%)
29-
- Uso de swap (%)
3029
- RAM total (MB)
3130
- Uso de disco (% para `/`)
3231
- Rendimiento de red (bytes/s de entrada y salida)
3332
- Tiempo de actividad (segundos)
3433
- Temperatura (°C, si está disponible)
35-
- Valores de hardware y sensores (velocidades de ventilador, voltajes, temperaturas de GPU/SoC, consumo eléctrico, si `lm-sensors` está disponible)
3634
- Núcleos de CPU
3735
- Carga promedio (1/5/15 min)
3836
- Frecuencia de CPU (MHz)
@@ -146,7 +144,6 @@ Para cada servidor estarán disponibles las siguientes entidades:
146144

147145
- `sensor.<name>_cpu` – Uso de CPU (%)
148146
- `sensor.<name>_mem` – Uso de memoria (%)
149-
- `sensor.<name>_swap` – Uso de swap (%)
150147
- `sensor.<name>_disk` – Uso de disco (%)
151148
- `sensor.<name>_net_in` – Tráfico de entrada (bytes/s)
152149
- `sensor.<name>_net_out` – Tráfico de salida (bytes/s)
@@ -166,7 +163,6 @@ Para cada servidor estarán disponibles las siguientes entidades:
166163
- `sensor.<name>_vnc` – "sí" si se detecta un servidor VNC
167164
- `sensor.<name>_web` – "sí" si escucha un servicio HTTP o HTTPS
168165
- `sensor.<name>_ssh` – "sí" si el servicio SSH está activo
169-
- `sensor.<name>_local_ip` – Dirección IP local
170166
- Para cada contenedor en ejecución: `sensor.<name>_container_<container>_cpu` (uso de CPU %) y `sensor.<name>_container_<container>_mem` (uso de memoria %)
171167

172168
---

README.fr.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,11 @@ En plus de la collecte de statistiques, le module inclut désormais un terminal
2626
- Collecte :
2727
- Utilisation du CPU (%)
2828
- Utilisation de la mémoire (%)
29-
- Utilisation du swap (%)
3029
- RAM totale (MB)
3130
- Utilisation du disque (% pour `/`)
3231
- Débit réseau (octets/s, entrant et sortant)
3332
- Temps de fonctionnement (secondes)
3433
- Température (°C, si disponible)
35-
- Valeurs matérielles et capteurs (vitesses des ventilateurs, tensions, températures GPU/SoC, consommation électrique, si `lm-sensors` est disponible)
3634
- Cœurs CPU
3735
- Charge moyenne (1/5/15 min)
3836
- Fréquence CPU (MHz)
@@ -146,7 +144,6 @@ Pour chaque serveur, les entités suivantes seront disponibles :
146144

147145
- `sensor.<name>_cpu` – Utilisation du CPU (%)
148146
- `sensor.<name>_mem` – Utilisation de la mémoire (%)
149-
- `sensor.<name>_swap` – Utilisation du swap (%)
150147
- `sensor.<name>_disk` – Utilisation du disque (%)
151148
- `sensor.<name>_net_in` – Trafic entrant (octets/s)
152149
- `sensor.<name>_net_out` – Trafic sortant (octets/s)
@@ -166,7 +163,6 @@ Pour chaque serveur, les entités suivantes seront disponibles :
166163
- `sensor.<name>_vnc` – "oui" si un serveur VNC est détecté
167164
- `sensor.<name>_web` – "oui" si un service HTTP ou HTTPS est à l'écoute
168165
- `sensor.<name>_ssh` – "oui" si le service SSH est actif
169-
- `sensor.<name>_local_ip` – Adresse IP locale
170166
- Pour chaque conteneur en cours d'exécution : `sensor.<name>_container_<container>_cpu` (utilisation CPU %) et `sensor.<name>_container_<container>_mem` (utilisation mémoire %)
171167

172168
---

README.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,11 @@ In addition to statistics collection, the add-on now includes an **interactive w
2828
- Collects:
2929
- CPU usage (%)
3030
- Memory usage (%)
31-
- Swap usage (%)
3231
- Total RAM (MB)
3332
- Disk usage (% for `/`)
3433
- Network throughput (bytes/s, in and out)
3534
- Uptime (seconds)
3635
- Temperature (°C, if available)
37-
- Hardware sensor values (fan speeds, voltages, GPU/SoC temperatures, power usage, if available via lm-sensors)
3836
- CPU cores
3937
- Load average (1/5/15 min)
4038
- CPU frequency (MHz)
@@ -155,9 +153,8 @@ disabled_entities:
155153

156154
For each server, the following entities will be available:
157155

158-
- `sensor.<name>_cpu` – CPU usage (%)
159-
- `sensor.<name>_mem` – Memory usage (%)
160-
- `sensor.<name>_swap` – Swap usage (%)
156+
- `sensor.<name>_cpu` – CPU usage (%)
157+
- `sensor.<name>_mem` – Memory usage (%)
161158
- `sensor.<name>_disk` – Disk usage (%)
162159
- `sensor.<name>_net_in` – Network inbound (bytes/s)
163160
- `sensor.<name>_net_out` – Network outbound (bytes/s)
@@ -177,7 +174,6 @@ For each server, the following entities will be available:
177174
- `sensor.<name>_vnc` – "yes" if a VNC server is detected
178175
- `sensor.<name>_web` – "yes" if an HTTP or HTTPS service is listening
179176
- `sensor.<name>_ssh` – "yes" if the SSH service is listening
180-
- `sensor.<name>_local_ip` – Local IP address
181177
- For each running container: `sensor.<name>_container_<container>_cpu` (CPU usage %) and `sensor.<name>_container_<container>_mem` (memory usage %)
182178

183179
---

addon/vserver_ssh_stats/app/collector.py

Lines changed: 2 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828

2929
# Verfolgte Container pro Server für MQTT Discovery
3030
_container_discovered: Dict[str, Set[str]] = defaultdict(set)
31-
_sensor_discovered: Dict[str, Set[str]] = defaultdict(set)
3231
net_cache = NetStatsCache()
3332

3433

@@ -37,26 +36,6 @@ def _sanitize(name: str) -> str:
3736
return re.sub(r"[^a-zA-Z0-9_]+", "_", name).lower()
3837

3938

40-
def _flatten_sensors(data: Any) -> Dict[str, float]:
41-
"""Flatten lm-sensors JSON output."""
42-
result: Dict[str, float] = {}
43-
44-
def _recurse(prefix: str, obj: Any) -> None:
45-
if isinstance(obj, dict):
46-
for k, v in obj.items():
47-
ksan = _sanitize(str(k))
48-
new_prefix = f"{prefix}_{ksan}" if prefix else ksan
49-
_recurse(new_prefix, v)
50-
else:
51-
try:
52-
result[f"sensor_{prefix}"] = float(obj)
53-
except (TypeError, ValueError):
54-
pass
55-
56-
_recurse("", data)
57-
return result
58-
59-
6039
def _setup_logging() -> None:
6140
"""Configure module wide logging."""
6241
logging.basicConfig(
@@ -125,7 +104,6 @@ def ensure_discovery(name: str) -> None:
125104
for key, unit, dc, str_value in [
126105
("cpu", "%", None, False),
127106
("mem", "%", None, False),
128-
("swap", "%", None, False),
129107
("disk", "%", None, False),
130108
("net_in", "B/s", None, False),
131109
("net_out", "B/s", None, False),
@@ -145,7 +123,6 @@ def ensure_discovery(name: str) -> None:
145123
("vnc", None, None, True),
146124
("web", None, None, True),
147125
("ssh", None, None, True),
148-
("local_ip", None, None, True),
149126
]:
150127
if key in DISABLED_ENTITIES:
151128
continue
@@ -168,30 +145,6 @@ def ensure_container_discovery(name: str, containers: List[Dict[str, Any]]) -> N
168145
continue
169146
publish_discovery(name, key, unit)
170147

171-
172-
def ensure_sensor_discovery(name: str, sample: Dict[str, Any]) -> None:
173-
"""Publish discovery topics for hardware sensors."""
174-
if not client:
175-
return
176-
known = _sensor_discovered[name]
177-
for key in sample.keys():
178-
if not key.startswith("sensor_") or key in known or key in DISABLED_ENTITIES:
179-
continue
180-
known.add(key)
181-
lower = key.lower()
182-
unit = None
183-
device_class = None
184-
if "temp" in lower:
185-
unit = "°C"
186-
device_class = "temperature"
187-
elif "fan" in lower:
188-
unit = "RPM"
189-
elif "power" in lower:
190-
unit = "W"
191-
elif lower.startswith("sensor_in") or "volt" in lower:
192-
unit = "V"
193-
publish_discovery(name, key, unit, device_class)
194-
195148
# ---------- SSH ----------
196149
def run_ssh(
197150
host: str,
@@ -248,13 +201,11 @@ def sample_server(srv: Dict[str, Any]) -> Dict[str, Any]:
248201
# Netzraten berechnen (Bytes/s)
249202
now = time.time()
250203
net_in, net_out = net_cache.compute(srv["name"], data["rx"], data["tx"], now)
251-
sensors = _flatten_sensors(data.get("sensors", {}))
252204

253205
# Antwort reduzieren
254-
result = {
206+
return {
255207
"cpu": int(data["cpu"]),
256208
"mem": int(data["mem"]),
257-
"swap": int(data.get("swap", 0)),
258209
"disk": int(data["disk"]),
259210
"uptime": int(data["uptime"]),
260211
"temp": (None if data["temp"] is None else float(data["temp"])),
@@ -274,11 +225,8 @@ def sample_server(srv: Dict[str, Any]) -> Dict[str, Any]:
274225
"vnc": data.get("vnc", ""),
275226
"web": data.get("web", ""),
276227
"ssh": data.get("ssh", ""),
277-
"local_ip": data.get("local_ip", ""),
278228
"container_stats": data.get("container_stats", []),
279229
}
280-
result.update(sensors)
281-
return result
282230

283231
def main():
284232
global client
@@ -294,9 +242,7 @@ def main():
294242
# initiale Netzbasis holen (damit ab dem 2. Tick Raten stimmen)
295243
for s in SERVERS:
296244
try:
297-
initial = sample_server(s)
298-
if client:
299-
ensure_sensor_discovery(s["name"], initial)
245+
_ = sample_server(s)
300246
except Exception:
301247
pass
302248

@@ -317,7 +263,6 @@ def main():
317263
mqtt_payload.pop(k, None)
318264
if client:
319265
ensure_container_discovery(s["name"], cont_stats)
320-
ensure_sensor_discovery(s["name"], payload)
321266
for c in cont_stats:
322267
cname = _sanitize(c.get("name", ""))
323268
for metric in ("cpu", "mem"):
@@ -345,7 +290,6 @@ def main():
345290
err = {
346291
"cpu": 0,
347292
"mem": 0,
348-
"swap": 0,
349293
"disk": 0,
350294
"uptime": 0,
351295
"temp": None,
@@ -361,7 +305,6 @@ def main():
361305
"vnc": "",
362306
"web": "",
363307
"ssh": "",
364-
"local_ip": "",
365308
"container_stats": [],
366309
}
367310
err_payload = err.copy()

addon/vserver_ssh_stats/app/remote_script.py

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,6 @@
1919
mem_avail=$(awk '/MemAvailable/ {print $2}' /proc/meminfo)
2020
if [ -z "$mem_avail" ]; then mem_avail=$(awk '/MemFree/ {print $2}' /proc/meminfo); fi
2121
mem=$(( (100*(mem_total - mem_avail) + mem_total/2) / mem_total ))
22-
# Swap %
23-
swap_total=$(awk '/SwapTotal/ {print $2}' /proc/meminfo)
24-
swap_free=$(awk '/SwapFree/ {print $2}' /proc/meminfo)
25-
if [ -n "$swap_total" ] && [ "$swap_total" -gt 0 ]; then
26-
swap=$(( (100*(swap_total - swap_free) + swap_total/2) / swap_total ))
27-
else
28-
swap=0
29-
fi
3022
# RAM total MB
3123
ram=$(( (mem_total + 512) / 1024 ))
3224
@@ -124,25 +116,11 @@
124116
if [ -n "$t" ]; then temp=$(awk -v v="$t" 'BEGIN{printf "%.1f", (v>=1000?v/1000:v)}'); fi
125117
fi
126118
127-
# Hardware sensors (best-effort via lm-sensors)
128-
sensors_json="{}"
129-
if command -v sensors >/dev/null 2>&1; then
130-
sj=$(sensors -j 2>/dev/null | tr -d '\n')
131-
if [ -n "$sj" ]; then sensors_json=$sj; fi
132-
fi
133-
134119
# NET (Summen Bytes RX/TX über alle nicht-lo Interfaces)
135120
rx=$(awk -F'[: ]+' '/:/{if($1!="lo"){rx+=$3; tx+=$11}} END{print rx+0}' /proc/net/dev)
136121
tx=$(awk -F'[: ]+' '/:/{if($1!="lo"){rx+=$3; tx+=$11}} END{print tx+0}' /proc/net/dev)
137122
138-
# Lokale IP-Adresse (erste nicht-lo IPv4)
139-
local_ip=$(hostname -I 2>/dev/null | awk '{print $1}')
140-
if [ -z "$local_ip" ]; then
141-
local_ip=$(ip -4 addr show scope global | awk '/inet /{print $2}' | cut -d/ -f1 | head -n1)
142-
fi
143-
local_ip_json=$(printf '%s' "$local_ip" | sed 's/"/\\"/g')
144-
145123
if [ -n "$temp" ]; then temp_json=$temp; else temp_json=null; fi
146-
printf '{"cpu":%s,"mem":%s,"swap":%s,"disk":%s,"uptime":%s,"temp":%s,"rx":%s,"tx":%s,"ram":%s,"cores":%s,"load_1":%s,"load_5":%s,"load_15":%s,"cpu_freq":%s,"os":"%s","pkg_count":%s,"pkg_list":"%s","docker":%s,"containers":"%s","container_stats":%s,"vnc":"%s","web":"%s","ssh":"%s","local_ip":"%s","sensors":%s}\n' \
147-
"$cpu" "$mem" "$swap" "$disk" "$uptime" "$temp_json" "$rx" "$tx" "$ram" "$cores" "$load_1" "$load_5" "$load_15" "$cpu_freq_json" "$os_json" "$pkg_count" "$pkg_list_json" "$docker" "$containers_json" "$container_stats_json" "$vnc" "$web" "$ssh_enabled" "$local_ip_json" "$sensors_json"
124+
printf '{"cpu":%s,"mem":%s,"disk":%s,"uptime":%s,"temp":%s,"rx":%s,"tx":%s,"ram":%s,"cores":%s,"load_1":%s,"load_5":%s,"load_15":%s,"cpu_freq":%s,"os":"%s","pkg_count":%s,"pkg_list":"%s","docker":%s,"containers":"%s","container_stats":%s,"vnc":"%s","web":"%s","ssh":"%s"}\n' \
125+
"$cpu" "$mem" "$disk" "$uptime" "$temp_json" "$rx" "$tx" "$ram" "$cores" "$load_1" "$load_5" "$load_15" "$cpu_freq_json" "$os_json" "$pkg_count" "$pkg_list_json" "$docker" "$containers_json" "$container_stats_json" "$vnc" "$web" "$ssh_enabled"
148126
'''

addon/vserver_ssh_stats/app/simple_collector.py

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,6 @@ def _sanitize(name: str) -> str:
1919
"""Return a lowercase, safe name for keys."""
2020
return re.sub(r"[^a-zA-Z0-9_]+", "_", name).lower()
2121

22-
23-
def _flatten_sensors(data: Any) -> Dict[str, float]:
24-
"""Flatten lm-sensors JSON output."""
25-
result: Dict[str, float] = {}
26-
27-
def _recurse(prefix: str, obj: Any) -> None:
28-
if isinstance(obj, dict):
29-
for k, v in obj.items():
30-
ksan = _sanitize(str(k))
31-
new_prefix = f"{prefix}_{ksan}" if prefix else ksan
32-
_recurse(new_prefix, v)
33-
else:
34-
try:
35-
result[f"sensor_{prefix}"] = float(obj)
36-
except (TypeError, ValueError):
37-
pass
38-
39-
_recurse("", data)
40-
return result
41-
4222
# ---------- SSH ----------
4323
def run_ssh(
4424
host: str,
@@ -76,11 +56,9 @@ def sample(host: str, username: str, password: Optional[str], key: Optional[str]
7656
now = time.time()
7757
net_in, net_out = net_cache.compute(host, data["rx"], data["tx"], now)
7858
cont_stats = data.get("container_stats", [])
79-
sensors = _flatten_sensors(data.get("sensors", {}))
8059
result = {
8160
"cpu": int(data["cpu"]),
8261
"mem": int(data["mem"]),
83-
"swap": int(data.get("swap", 0)),
8462
"disk": int(data["disk"]),
8563
"uptime": int(data["uptime"]),
8664
"temp": (None if data["temp"] is None else float(data["temp"])),
@@ -96,14 +74,12 @@ def sample(host: str, username: str, password: Optional[str], key: Optional[str]
9674
"vnc": data.get("vnc", ""),
9775
"web": data.get("web", ""),
9876
"ssh": data.get("ssh", ""),
99-
"local_ip": data.get("local_ip", ""),
10077
"container_stats": cont_stats,
10178
}
10279
for c in cont_stats:
10380
cname = _sanitize(c.get("name", ""))
10481
result[f"container_{cname}_cpu"] = c.get("cpu", 0)
10582
result[f"container_{cname}_mem"] = c.get("mem", 0)
106-
result.update(sensors)
10783
return result
10884

10985
def main():
@@ -160,7 +136,6 @@ def send_to_home_assistant(base_url: str, token: str, name: str, data: Dict[str,
160136
units = {
161137
"cpu": "%",
162138
"mem": "%",
163-
"swap": "%",
164139
"disk": "%",
165140
"net_in": "B/s",
166141
"net_out": "B/s",

addon/vserver_ssh_stats/config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: VServer SSH Stats
2-
version: "1.1.21"
2+
version: "1.2.1"
33
slug: vserver_ssh_stats
44
description: Holt CPU, RAM, Disk, Net per SSH (ohne Agent) und veröffentlicht sie via MQTT.
55
startup: services
@@ -35,7 +35,7 @@ schema:
3535
mqtt_pass: str
3636
interval_seconds: int
3737
disabled_entities:
38-
- match(cpu|mem|swap|disk|net_in|net_out|uptime|temp|ram|cores|load_1|load_5|load_15|cpu_freq|os|pkg_count|pkg_list|local_ip|sensor_.*)
38+
- match(cpu|mem|disk|net_in|net_out|uptime|temp|ram|cores|load_1|load_5|load_15|cpu_freq|os|pkg_count|pkg_list)
3939
servers:
4040
- name: str
4141
host: str

0 commit comments

Comments
 (0)