Files
SnarfCode/scripts/test_cluster_widgets.py

77 lines
3.3 KiB
Python

import requests
import json
import urllib3
urllib3.disable_warnings()
headers = {"User-Agent": "Mozilla/5.0"}
print("=== 1. Spaceport Kubernetes Cluster Metrics ===")
try:
r = requests.get("https://homepage.snarfnet.net/api/widgets/kubernetes", headers=headers, verify=False, timeout=10)
data = r.json()
cpu = data.get("cluster", {}).get("cpu", {})
mem = data.get("cluster", {}).get("memory", {})
print(f"Status: {r.status_code}")
print(f" CPU Load: {cpu.get('load', 0):.2f} / {cpu.get('total')} cores ({cpu.get('percent', 0):.1f}%)")
print(f" Memory: {mem.get('used', 0)/(1024**3):.1f} / {mem.get('total', 0)/(1024**3):.1f} GiB ({mem.get('percent', 0):.1f}%)")
print(f" Nodes: {len(data.get('nodes', []))} nodes online")
except Exception as e:
print("Error:", e)
print("\n=== 2. Longhorn Spaceport Storage Metrics ===")
try:
r = requests.get("https://homepage.snarfnet.net/api/widgets/longhorn", headers=headers, verify=False, timeout=10)
data = r.json()
for n in data.get("nodes", []):
if n.get("id") == "total":
max_gb = n.get("maximum", 0) / (1024**3)
avail_gb = n.get("available", 0) / (1024**3)
used_gb = max_gb - avail_gb
print(f"Status: {r.status_code}")
print(f" Storage Total: {max_gb:.1f} GiB ({max_gb/1024:.2f} TiB)")
print(f" Storage Used: {used_gb:.1f} GiB ({used_gb/max_gb*100:.1f}%)")
print(f" Storage Available: {avail_gb:.1f} GiB")
except Exception as e:
print("Error:", e)
print("\n=== 3. Portainer Swarm Metrics ===")
try:
url = "https://homepage.snarfnet.net/api/services/proxy?group=Storage%20%26%20Clusters&service=Portainer%20Swarm&index=0&endpoint=docker/containers"
r = requests.get(url, headers=headers, verify=False, timeout=10)
print(f"Status: {r.status_code}")
if r.status_code == 200:
containers = r.json()
running = len([c for c in containers if c.get("State") == "running"])
stopped = len([c for c in containers if c.get("State") == "exited"])
print(f" Containers: Running: {running}, Stopped: {stopped}, Total: {len(containers)}")
except Exception as e:
print("Error:", e)
print("\n=== 4. Rancher (Aerodrome Cluster) Metrics ===")
try:
url = "https://homepage.snarfnet.net/api/services/proxy?group=Storage%20%26%20Clusters&service=Rancher%20(Aerodrome)&index=0"
r = requests.get(url, headers=headers, verify=False, timeout=10)
print(f"Status: {r.status_code}")
if r.status_code == 200:
d = r.json()
cap = d.get("capacity", {})
print(f" Cluster State: {d.get('state')}, CPU Cores: {cap.get('cpu')}, Max Pods: {cap.get('pods')}")
else:
print(r.text[:200])
except Exception as e:
print("Error:", e)
print("\n=== 5. Harvester HCI (Spacedock Cluster) Metrics ===")
try:
url = "https://homepage.snarfnet.net/api/services/proxy?group=Storage%20%26%20Clusters&service=Harvester%20HCI%20(Spacedock)&index=0"
r = requests.get(url, headers=headers, verify=False, timeout=10)
print(f"Status: {r.status_code}")
if r.status_code == 200:
d = r.json()
cap = d.get("capacity", {})
print(f" HCI State: {d.get('state')}, CPU Cores: {cap.get('cpu')}, Max Pods: {cap.get('pods')}")
else:
print(r.text[:200])
except Exception as e:
print("Error:", e)