diff --git a/api/app.py b/api/app.py index 318de3f..8aa6b19 100644 --- a/api/app.py +++ b/api/app.py @@ -25,6 +25,9 @@ from logging.handlers import RotatingFileHandler import uuid import contextvars +# Track API start time for uptime calculation +API_START_TIME = time.time() + from network_manager import NetworkManager from wireguard_manager import WireGuardManager from peer_registry import PeerRegistry @@ -305,10 +308,14 @@ def get_cell_status(): peers = peer_registry.list_peers() + # Calculate actual uptime + current_time = time.time() + uptime_seconds = int(current_time - API_START_TIME) + return jsonify({ "cell_name": "personal-internet-cell", "domain": "cell.local", - "uptime": 3600, # Placeholder + "uptime": uptime_seconds, "peers_count": len(peers), "services": services_status, "timestamp": datetime.utcnow().isoformat() diff --git a/webui/src/pages/Dashboard.jsx b/webui/src/pages/Dashboard.jsx index a5fa83a..16cf79f 100644 --- a/webui/src/pages/Dashboard.jsx +++ b/webui/src/pages/Dashboard.jsx @@ -62,6 +62,23 @@ function Dashboard({ isOnline }) { } }; + const formatUptime = (seconds) => { + if (!seconds || seconds < 0) return '0s'; + + const days = Math.floor(seconds / 86400); + const hours = Math.floor((seconds % 86400) / 3600); + const minutes = Math.floor((seconds % 3600) / 60); + const secs = Math.floor(seconds % 60); + + const parts = []; + if (days > 0) parts.push(`${days}d`); + if (hours > 0) parts.push(`${hours}h`); + if (minutes > 0) parts.push(`${minutes}m`); + if (secs > 0 || parts.length === 0) parts.push(`${secs}s`); + + return parts.join(' '); + }; + const handleServiceControl = async (serviceName, action) => { if (!isOnline) return; @@ -224,7 +241,7 @@ function Dashboard({ isOnline }) {

Uptime

- {Math.floor((cellStatus.uptime || 0) / 3600)}h {Math.floor(((cellStatus.uptime || 0) % 3600) / 60)}m + {formatUptime(cellStatus.uptime || 0)}