Files
homelab-infra/apps/dashboard/assets/js/state.js
T
Micha bbdf2ffb60 updates
Repo sauber machen
2026-04-15 13:40:03 +02:00

61 lines
2.8 KiB
JavaScript

const DEFAULT_DATA = {
overview: {
generated_at: new Date().toISOString(),
overall_status: "online",
refresh_hint_seconds: 20,
services: { online: 8, degraded: 2, offline: 1, total: 11 },
docker: { running: 18, stopped: 2, unhealthy: 1, total: 20, source_status: "online" },
system: {
cpu_percent: 23,
ram_percent: 61,
root_storage_percent: 49,
network_rx_mbps: 12.4,
network_tx_mbps: 3.1,
uptime_seconds: 864000,
},
home_assistant: {
status: "online",
label: "Home Assistant",
version: "2026.3.4",
response_time_ms: 142,
last_checked: new Date().toISOString(),
},
},
system: {
generated_at: new Date().toISOString(),
source: { name: "system", status: "online", host_name: "nas", agent_name: "not_configured" },
cpu: { usage_percent: 23, cores: 8, load_1: 0.8, load_5: 0.6, load_15: 0.5 },
memory: { used_gb: 12.4, total_gb: 32.0, available_gb: 19.6, usage_percent: 38.7 },
network: { primary_interface: "eth0", rx_mbps: 12.4, tx_mbps: 3.1 },
host: { uptime_seconds: 864000, platform: "linux", kernel: "6.1.0" },
},
storage: {
generated_at: new Date().toISOString(),
summary: { total_used_gb: 2048, total_size_gb: 8192, total_free_gb: 6144, overall_usage_percent: 25 },
disks: [],
},
services: {
generated_at: new Date().toISOString(),
summary: { overall_status: "online", total: 11, online: 8, degraded: 2, offline: 1 },
docker: { running: 18, stopped: 2, unhealthy: 1, total: 20, source_status: "online" },
uptime_kuma: { monitors_up: 8, monitors_down: 1, source_status: "online" },
items: [],
},
adguard: { source_name: "adguard", source_status: "offline", total_queries: 0, blocked_queries: 0, blocked_percent: 0, avg_processing_ms: 0 },
scrutiny: { source_name: "scrutiny", source_status: "offline", overall_status: "offline", devices: [], failed_count: 0, total_count: 0 },
immich: { source_name: "immich", source_status: "offline", photos: 0, videos: 0, storage_gb: 0 },
backrest: { source_name: "backrest", source_status: "offline", repo_count: 0, last_backup_age_hours: null, last_backup_status: "unknown", error_count: 0 },
home_assistant: { source_name: "home_assistant", status: "offline", version: null, lights_on: 0, lights_total: 0, climate_active: 0, doors_open: 0, alerts: 0 },
uptime_kuma: { source_name: "uptime_kuma", source_status: "offline", monitors_up: 0, monitors_down: 0, monitors_paused: 0, total: 0, monitors: [] },
};
let _state = structuredClone(DEFAULT_DATA);
const _subscribers = [];
export function getState() { return _state; }
export function subscribe(fn) { _subscribers.push(fn); }
export function updateData(partial) {
_state = { ..._state, ...partial };
_subscribers.forEach((fn) => fn(_state));
}