Dashboard 2 (unifi) hinzugefügt
This commit is contained in:
parent
709cea301b
commit
c3fa99bc0d
1 changed files with 124 additions and 10 deletions
134
down.py
134
down.py
|
|
@ -248,6 +248,107 @@ from(bucket: "{INFLUX_BUCKET}")
|
|||
print(traceback.format_exc())
|
||||
|
||||
return []
|
||||
def get_unifi_clients():
|
||||
|
||||
try:
|
||||
|
||||
with urllib.request.urlopen(
|
||||
"http://10.0.1.122:8087/getPlainValue/unifi.2.default.health.lan.num_user",
|
||||
timeout=3
|
||||
) as response:
|
||||
|
||||
lan = int(response.read().decode().strip())
|
||||
|
||||
with urllib.request.urlopen(
|
||||
"http://10.0.1.122:8087/getPlainValue/unifi.2.default.health.wlan.num_user",
|
||||
timeout=3
|
||||
) as response:
|
||||
|
||||
wlan = int(response.read().decode().strip())
|
||||
|
||||
return lan + wlan
|
||||
|
||||
except Exception as e:
|
||||
|
||||
print("UniFi Client Fehler:", e)
|
||||
|
||||
return 0
|
||||
|
||||
def get_url_value(url):
|
||||
|
||||
try:
|
||||
|
||||
with urllib.request.urlopen(url, timeout=3) as response:
|
||||
|
||||
value = response.read().decode().strip()
|
||||
|
||||
# ioBroker liefert manche Werte als "2.3" oder "721371"
|
||||
value = value.replace('"', '')
|
||||
|
||||
return value
|
||||
|
||||
except Exception as e:
|
||||
|
||||
print("URL Fehler:", e)
|
||||
|
||||
return "0"
|
||||
|
||||
def get_unifi_stats():
|
||||
|
||||
try:
|
||||
|
||||
lan = int(get_url_value(
|
||||
"http://10.0.1.122:8087/getPlainValue/unifi.2.default.health.lan.num_user"
|
||||
))
|
||||
|
||||
wlan = int(get_url_value(
|
||||
"http://10.0.1.122:8087/getPlainValue/unifi.2.default.health.wlan.num_user"
|
||||
))
|
||||
|
||||
cpu = float(
|
||||
get_url_value(
|
||||
"http://10.0.1.122:8087/getPlainValue/unifi.2.default.devices.9c:05:d6:52:52:19.system-stats.cpu"
|
||||
).replace('"', '')
|
||||
)
|
||||
|
||||
ram = float(
|
||||
get_url_value(
|
||||
"http://10.0.1.122:8087/getPlainValue/unifi.2.default.devices.9c:05:d6:52:52:19.system-stats.mem"
|
||||
).replace('"', '')
|
||||
)
|
||||
|
||||
uptime = int(get_url_value(
|
||||
"http://10.0.1.122:8087/getPlainValue/unifi.2.default.devices.9c:05:d6:52:52:19.system-stats.uptime"
|
||||
))
|
||||
|
||||
return {
|
||||
"lan": lan,
|
||||
"wlan": wlan,
|
||||
"clients": lan + wlan,
|
||||
"cpu": cpu,
|
||||
"ram": ram,
|
||||
"uptime": uptime
|
||||
}
|
||||
|
||||
except Exception as e:
|
||||
|
||||
print("UniFi Fehler:", e)
|
||||
|
||||
return {
|
||||
"lan": 0,
|
||||
"wlan": 0,
|
||||
"clients": 0,
|
||||
"cpu": 0,
|
||||
"ram": 0,
|
||||
"uptime": 0
|
||||
}
|
||||
|
||||
def format_uptime(seconds):
|
||||
|
||||
days = seconds // 86400
|
||||
hours = (seconds % 86400) // 3600
|
||||
|
||||
return f"{days}d {hours}h"
|
||||
|
||||
# -------------------------------------------------
|
||||
# Speedtest aus InfluxDB lesen
|
||||
|
|
@ -613,6 +714,9 @@ def draw_dashboard_2():
|
|||
|
||||
draw = ImageDraw.Draw(img)
|
||||
|
||||
stats = get_unifi_stats()
|
||||
|
||||
|
||||
# Header wie Dashboard 1
|
||||
|
||||
draw.text(
|
||||
|
|
@ -657,20 +761,30 @@ def draw_dashboard_2():
|
|||
(10, 60, WIDTH - 10, 60),
|
||||
fill="white"
|
||||
)
|
||||
|
||||
draw.text(
|
||||
(20, 110),
|
||||
time.strftime("%d.%m.%Y"),
|
||||
fill="white",
|
||||
(20, 90),
|
||||
"UNIFI GATEWAY MAX",
|
||||
fill="cyan",
|
||||
font=font_small_bold
|
||||
)
|
||||
|
||||
draw.text(
|
||||
(20, 140),
|
||||
time.strftime("%H:%M:%S"),
|
||||
fill="green",
|
||||
font=font_download
|
||||
)
|
||||
draw.text((20, 130), "LAN CLIENTS", fill="white", font=font_small_bold)
|
||||
draw.text((220, 130), str(stats["lan"]), fill="lime", font=font_small_bold)
|
||||
|
||||
draw.text((20, 160), "WLAN CLIENTS", fill="white", font=font_small_bold)
|
||||
draw.text((220, 160), str(stats["wlan"]), fill="lime", font=font_small_bold)
|
||||
|
||||
draw.text((20, 190), "CLIENTS GES.", fill="white", font=font_small_bold)
|
||||
draw.text((220, 190), str(stats["clients"]), fill="lime", font=font_small_bold)
|
||||
|
||||
draw.text((20, 220), "UXG CPU", fill="white", font=font_small_bold)
|
||||
draw.text((220, 220), f"{stats['cpu']:.0f} %", fill="yellow", font=font_small_bold)
|
||||
|
||||
draw.text((20, 250), "UXG RAM", fill="white", font=font_small_bold)
|
||||
draw.text((220, 250), f"{stats['ram']:.0f} %", fill="cyan", font=font_small_bold)
|
||||
|
||||
draw.text((20, 280), "UPTIME", fill="white", font=font_small_bold)
|
||||
draw.text((220, 280), format_uptime(stats["uptime"]), fill="orange", font=font_small_bold)
|
||||
|
||||
return img
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue