- FastAPI app med 7 bundled module-typer (proxmox, esxi, truenas, splunk, linux, windows, http-json) - Multi-instance support: flere instanser af samme modultype med adskilte assets - Community/Enterprise licensing med admin enterprise-toggle - Capacity forecasting, trends, what-if simulator, alert policies - MCP server + LLM copilot integration - Dockerfile + rune.yaml til Yggdrasil
227 lines
12 KiB
Python
227 lines
12 KiB
Python
"""Deterministic demo fleet.
|
|
|
|
The same definitions power both the 30-day seed history and the live demo
|
|
snapshots returned by the bundled modules, so the UI is consistent out of the
|
|
box while every collector module still implements a real API path.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import hashlib
|
|
import math
|
|
from typing import Any, Dict, List, Optional
|
|
|
|
REFERENCE_METRICS = {"cpu_pct", "mem_pct", "storage_pct", "license_pct", "load_pct", "battery_pct"}
|
|
|
|
|
|
def _noise(key: str, ts: int, scale: float) -> float:
|
|
digest = hashlib.sha256(f"{key}:{ts // 3600}".encode()).digest()
|
|
return ((int.from_bytes(digest[:2], "big") / 65535.0) * 2 - 1) * scale
|
|
|
|
|
|
def _asset(
|
|
external_id: str,
|
|
name: str,
|
|
type_: str,
|
|
cluster: str,
|
|
site: str,
|
|
capacity: Dict[str, float],
|
|
metrics: Dict[str, float],
|
|
growth: Optional[Dict[str, float]] = None,
|
|
amp: Optional[Dict[str, float]] = None,
|
|
tags: Optional[List[str]] = None,
|
|
meta: Optional[Dict[str, Any]] = None,
|
|
) -> Dict[str, Any]:
|
|
return {
|
|
"external_id": external_id,
|
|
"name": name,
|
|
"type": type_,
|
|
"cluster": cluster,
|
|
"site": site,
|
|
"capacity": capacity,
|
|
"metrics": metrics,
|
|
"growth": growth or {},
|
|
"amp": amp or {},
|
|
"tags": tags or [],
|
|
"meta": meta or {},
|
|
}
|
|
|
|
|
|
FLEET: Dict[str, List[Dict[str, Any]]] = {
|
|
"proxmox": [
|
|
_asset("pve-01", "pve-01", "hypervisor", "Proxmox / Atlas", "Rack A",
|
|
{"cpu_cores": 16, "mem_gb": 64, "storage_gb": 2000},
|
|
{"cpu_pct": 46, "mem_pct": 64, "vm_count": 9, "power_w": 185, "uptime_days": 63},
|
|
{"cpu_pct": 0.15, "mem_pct": 0.22}, {"cpu_pct": 8, "mem_pct": 3},
|
|
["prod", "pve"], {"vendor": "Proxmox VE", "version": "8.2", "cpu": "AMD Ryzen 9 5950X"}),
|
|
_asset("pve-02", "pve-02", "hypervisor", "Proxmox / Atlas", "Rack A",
|
|
{"cpu_cores": 16, "mem_gb": 64, "storage_gb": 2000},
|
|
{"cpu_pct": 61, "mem_pct": 71, "vm_count": 11, "power_w": 212, "uptime_days": 91},
|
|
{"cpu_pct": 0.2, "mem_pct": 0.16}, {"cpu_pct": 9, "mem_pct": 3},
|
|
["prod", "pve"], {"vendor": "Proxmox VE", "version": "8.2"}),
|
|
_asset("pve-03", "pve-03", "hypervisor", "Proxmox / Atlas", "Rack A",
|
|
{"cpu_cores": 24, "mem_gb": 96, "storage_gb": 2000},
|
|
{"cpu_pct": 33, "mem_pct": 48, "vm_count": 7, "power_w": 168, "uptime_days": 34},
|
|
{"cpu_pct": 0.28, "mem_pct": 0.3}, {"cpu_pct": 6, "mem_pct": 2},
|
|
["lab", "pve"], {"vendor": "Proxmox VE", "version": "8.3"}),
|
|
_asset("ceph-atlas", "ceph-atlas", "storage", "Proxmox / Atlas", "Rack A",
|
|
{"storage_gb": 12288},
|
|
{"storage_pct": 71, "iops": 1850, "latency_ms": 3.4},
|
|
{"storage_pct": 0.32}, {"storage_pct": 0.4, "iops": 240, "latency_ms": 0.7},
|
|
["ceph", "ssd"], {"vendor": "Ceph", "pools": 3}),
|
|
_asset("local-lvm-01", "local-lvm (pve-01)", "storage", "Proxmox / Atlas", "Rack A",
|
|
{"storage_gb": 1900}, {"storage_pct": 58, "latency_ms": 1.9},
|
|
{"storage_pct": 0.18}, {"storage_pct": 0.3, "latency_ms": 0.3}, ["local", "nvme"]),
|
|
_asset("local-lvm-02", "local-lvm (pve-02)", "storage", "Proxmox / Atlas", "Rack A",
|
|
{"storage_gb": 1900}, {"storage_pct": 66, "latency_ms": 2.1},
|
|
{"storage_pct": 0.22}, {"storage_pct": 0.3, "latency_ms": 0.3}, ["local", "nvme"]),
|
|
_asset("nfs-vault", "nfs-vault", "storage", "Proxmox / Atlas", "Rack C",
|
|
{"storage_gb": 8192}, {"storage_pct": 82, "latency_ms": 6.2, "iops": 640},
|
|
{"storage_pct": 0.18}, {"storage_pct": 0.2, "latency_ms": 1.4},
|
|
["nfs", "backup"], {"vendor": "Synology", "mount": "/mnt/vault"}),
|
|
],
|
|
"esxi": [
|
|
_asset("esx-01", "esx-01.lab", "hypervisor", "ESXi / Edge", "Rack B",
|
|
{"cpu_cores": 32, "mem_gb": 256, "storage_gb": 960},
|
|
{"cpu_pct": 57, "mem_pct": 84, "vm_count": 24, "power_w": 412, "uptime_days": 122},
|
|
{"cpu_pct": 0.12, "mem_pct": 0.3}, {"cpu_pct": 10, "mem_pct": 2},
|
|
["prod", "esxi"], {"vendor": "VMware", "version": "8.0 U2"}),
|
|
_asset("esx-02", "esx-02.lab", "hypervisor", "ESXi / Edge", "Rack B",
|
|
{"cpu_cores": 32, "mem_gb": 256, "storage_gb": 960},
|
|
{"cpu_pct": 38, "mem_pct": 44, "vm_count": 18, "power_w": 355, "uptime_days": 118},
|
|
{"cpu_pct": 0.1, "mem_pct": 0.18}, {"cpu_pct": 8, "mem_pct": 2},
|
|
["prod", "esxi"], {"vendor": "VMware", "version": "8.0 U2"}),
|
|
_asset("vsan-edge", "vsan-edge", "storage", "ESXi / Edge", "Rack B",
|
|
{"storage_gb": 20480}, {"storage_pct": 74, "latency_ms": 2.8, "iops": 4200},
|
|
{"storage_pct": 0.25}, {"storage_pct": 0.3, "iops": 500, "latency_ms": 0.5},
|
|
["vsan", "ssd"], {"vendor": "VMware vSAN"}),
|
|
_asset("ds-scratch", "ds-scratch", "storage", "ESXi / Edge", "Rack B",
|
|
{"storage_gb": 4096}, {"storage_pct": 46, "latency_ms": 4.1},
|
|
{"storage_pct": 0.4}, {"storage_pct": 0.5, "latency_ms": 0.9}, ["scratch", "hdd"]),
|
|
],
|
|
"splunk": [
|
|
_asset("splunk-idx-01", "splunk-idx-01", "appliance", "Splunk / Observability", "Rack A",
|
|
{"cpu_cores": 16, "mem_gb": 64, "storage_gb": 4096},
|
|
{"cpu_pct": 52, "mem_pct": 67, "license_pct": 87, "index_gb": 2980,
|
|
"storage_pct": 73, "temp_c": 38, "uptime_days": 210},
|
|
{"license_pct": 0.35, "storage_pct": 0.3, "index_gb": 12},
|
|
{"cpu_pct": 6, "mem_pct": 3}, ["logging", "siem"],
|
|
{"vendor": "Splunk", "version": "9.2", "license": "Enterprise 50 GB/day"}),
|
|
],
|
|
"truenas": [
|
|
_asset("truenas-01", "truenas-01", "nas", "Storage / Vault", "Rack C",
|
|
{"cpu_cores": 12, "mem_gb": 96}, {"cpu_pct": 22, "mem_pct": 58, "temp_c": 41, "power_w": 238},
|
|
{"cpu_pct": 0.05, "mem_pct": 0.08}, {"cpu_pct": 4, "mem_pct": 2}, ["nas", "zfs"],
|
|
{"vendor": "TrueNAS SCALE", "version": "24.04", "disks": 12}),
|
|
_asset("tank-primary", "tank / primary", "storage", "Storage / Vault", "Rack C",
|
|
{"storage_gb": 40960}, {"storage_pct": 88, "latency_ms": 5.4, "iops": 980},
|
|
{"storage_pct": 0.5}, {"storage_pct": 0.4, "latency_ms": 1.1},
|
|
["zfs", "raidz2"], {"vendor": "TrueNAS SCALE", "pool": "tank/primary"}),
|
|
_asset("tank-backup", "tank / backup", "storage", "Storage / Vault", "Rack C",
|
|
{"storage_gb": 12288}, {"storage_pct": 48, "latency_ms": 7.8},
|
|
{"storage_pct": 0.2}, {"storage_pct": 0.3, "latency_ms": 1.2},
|
|
["zfs", "backup"], {"vendor": "TrueNAS SCALE", "pool": "tank/backup"}),
|
|
],
|
|
"linux": [
|
|
_asset("lnx-docker-01", "lnx-docker-01", "server", "Linux / Core", "Rack A",
|
|
{"cpu_cores": 16, "mem_gb": 64, "storage_gb": 1900},
|
|
{"cpu_pct": 39, "mem_pct": 55, "storage_pct": 62, "temp_c": 47, "uptime_days": 88},
|
|
{"cpu_pct": 0.22, "mem_pct": 0.25, "storage_pct": 0.3},
|
|
{"cpu_pct": 9, "mem_pct": 3}, ["docker", "prod"], {"os": "Ubuntu 24.04"}),
|
|
_asset("lnx-k8s-01", "lnx-k8s-01", "server", "Linux / Core", "Rack B",
|
|
{"cpu_cores": 24, "mem_gb": 128, "storage_gb": 3800},
|
|
{"cpu_pct": 66, "mem_pct": 73, "storage_pct": 69, "temp_c": 52, "uptime_days": 140},
|
|
{"cpu_pct": 0.45, "mem_pct": 0.4, "storage_pct": 0.35},
|
|
{"cpu_pct": 11, "mem_pct": 4}, ["kubernetes", "prod"], {"os": "Debian 12"}),
|
|
_asset("lnx-mon-01", "lnx-mon-01", "server", "Linux / Core", "Rack C",
|
|
{"cpu_cores": 8, "mem_gb": 32, "storage_gb": 950},
|
|
{"cpu_pct": 28, "mem_pct": 41, "storage_pct": 57, "temp_c": 43, "uptime_days": 67},
|
|
{"cpu_pct": 0.08, "mem_pct": 0.1, "storage_pct": 0.25},
|
|
{"cpu_pct": 5, "mem_pct": 2}, ["monitoring"], {"os": "Ubuntu 22.04"}),
|
|
],
|
|
"windows": [
|
|
_asset("win-ad-01", "win-ad-01", "server", "Windows / Core", "Rack A",
|
|
{"cpu_cores": 8, "mem_gb": 32, "storage_gb": 480},
|
|
{"cpu_pct": 21, "mem_pct": 46, "storage_pct": 64, "uptime_days": 55},
|
|
{"cpu_pct": 0.04, "mem_pct": 0.06, "storage_pct": 0.12},
|
|
{"cpu_pct": 3, "mem_pct": 2}, ["ad", "windows"], {"os": "Windows Server 2022"}),
|
|
_asset("win-files-01", "win-files-01", "server", "Windows / Core", "Rack B",
|
|
{"cpu_cores": 16, "mem_gb": 64, "storage_gb": 7600},
|
|
{"cpu_pct": 35, "mem_pct": 58, "storage_pct": 79},
|
|
{"cpu_pct": 0.1, "mem_pct": 0.15, "storage_pct": 0.3},
|
|
{"cpu_pct": 5, "mem_pct": 2}, ["files", "windows"], {"os": "Windows Server 2022"}),
|
|
],
|
|
"http-json": [
|
|
_asset("core-switch-01", "core-switch-01", "network", "Network / Facilities", "Rack C",
|
|
{}, {"load_pct": 47, "net_rx_mbps": 4230, "net_tx_mbps": 3120, "temp_c": 44, "uptime_days": 301},
|
|
{"load_pct": 0.12, "net_rx_mbps": 18, "net_tx_mbps": 14},
|
|
{"load_pct": 12, "net_rx_mbps": 420, "net_tx_mbps": 380, "temp_c": 2},
|
|
["network", "10g"], {"vendor": "UniFi", "model": "USW-Pro-48"}),
|
|
_asset("ups-rack-c", "ups-rack-c", "power", "Network / Facilities", "Rack C",
|
|
{}, {"load_pct": 62, "power_w": 1250, "battery_pct": 96, "temp_c": 32, "uptime_days": 200},
|
|
{}, {"load_pct": 4, "power_w": 80, "temp_c": 1},
|
|
["ups", "power"], {"vendor": "APC", "model": "Smart-UPS 3000"}),
|
|
],
|
|
}
|
|
|
|
MODULE_META = {
|
|
"proxmox": {"name": "Proxmox VE", "cluster": "Proxmox / Atlas"},
|
|
"esxi": {"name": "VMware ESXi", "cluster": "ESXi / Edge"},
|
|
"splunk": {"name": "Splunk", "cluster": "Splunk / Observability"},
|
|
"truenas": {"name": "TrueNAS", "cluster": "Storage / Vault"},
|
|
"linux": {"name": "Linux hosts", "cluster": "Linux / Core"},
|
|
"windows": {"name": "Windows hosts", "cluster": "Windows / Core"},
|
|
"http-json": {"name": "HTTP JSON bridge", "cluster": "Network / Facilities"},
|
|
}
|
|
|
|
|
|
def demo_value(spec: Dict[str, Any], metric: str, ts: int, reference_ts: int) -> float:
|
|
base = float(spec["metrics"].get(metric, 0))
|
|
growth = float(spec["growth"].get(metric, 0))
|
|
days_ago = (reference_ts - ts) / 86400.0
|
|
value = base - growth * days_ago
|
|
amp = float(spec["amp"].get(metric, 0))
|
|
if amp:
|
|
hour = (ts % 86400) / 3600.0
|
|
value += amp * math.sin(2 * math.pi * (hour - 8) / 24.0)
|
|
if metric == "uptime_days":
|
|
value = max(0.0, base - days_ago)
|
|
elif metric == "vm_count":
|
|
value = round(value + _noise(f"{spec['external_id']}:{metric}", ts, 0.5))
|
|
elif metric == "battery_pct":
|
|
value += _noise(f"{spec['external_id']}:{metric}", ts, 0.5)
|
|
elif growth:
|
|
value += _noise(f"{spec['external_id']}:{metric}", ts, 0.18)
|
|
else:
|
|
scale = {"power_w": 6.0, "temp_c": 1.0, "latency_ms": 0.2, "iops": 40.0}.get(metric, 0.9)
|
|
value += _noise(f"{spec['external_id']}:{metric}", ts, scale)
|
|
if metric in REFERENCE_METRICS:
|
|
value = max(0.0, min(99.5, value))
|
|
return round(value, 2)
|
|
|
|
|
|
def snapshot(module_id: str, now_ts: int) -> List[Dict[str, Any]]:
|
|
out: List[Dict[str, Any]] = []
|
|
for spec in FLEET.get(module_id, []):
|
|
metrics = {
|
|
metric: demo_value(spec, metric, now_ts, now_ts)
|
|
for metric in spec["metrics"]
|
|
}
|
|
out.append(
|
|
{
|
|
"external_id": spec["external_id"],
|
|
"name": spec["name"],
|
|
"type": spec["type"],
|
|
"cluster": spec["cluster"],
|
|
"site": spec["site"],
|
|
"tags": list(spec["tags"]),
|
|
"capacity": dict(spec["capacity"]),
|
|
"metrics": metrics,
|
|
"meta": dict(spec["meta"]),
|
|
}
|
|
)
|
|
return out
|
|
|
|
|
|
def assets_for(module_id: str) -> List[Dict[str, Any]]:
|
|
return list(FLEET.get(module_id, []))
|