fix uptime on dashboard
This commit is contained in:
+8
-1
@@ -25,6 +25,9 @@ from logging.handlers import RotatingFileHandler
|
|||||||
import uuid
|
import uuid
|
||||||
import contextvars
|
import contextvars
|
||||||
|
|
||||||
|
# Track API start time for uptime calculation
|
||||||
|
API_START_TIME = time.time()
|
||||||
|
|
||||||
from network_manager import NetworkManager
|
from network_manager import NetworkManager
|
||||||
from wireguard_manager import WireGuardManager
|
from wireguard_manager import WireGuardManager
|
||||||
from peer_registry import PeerRegistry
|
from peer_registry import PeerRegistry
|
||||||
@@ -305,10 +308,14 @@ def get_cell_status():
|
|||||||
|
|
||||||
peers = peer_registry.list_peers()
|
peers = peer_registry.list_peers()
|
||||||
|
|
||||||
|
# Calculate actual uptime
|
||||||
|
current_time = time.time()
|
||||||
|
uptime_seconds = int(current_time - API_START_TIME)
|
||||||
|
|
||||||
return jsonify({
|
return jsonify({
|
||||||
"cell_name": "personal-internet-cell",
|
"cell_name": "personal-internet-cell",
|
||||||
"domain": "cell.local",
|
"domain": "cell.local",
|
||||||
"uptime": 3600, # Placeholder
|
"uptime": uptime_seconds,
|
||||||
"peers_count": len(peers),
|
"peers_count": len(peers),
|
||||||
"services": services_status,
|
"services": services_status,
|
||||||
"timestamp": datetime.utcnow().isoformat()
|
"timestamp": datetime.utcnow().isoformat()
|
||||||
|
|||||||
@@ -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) => {
|
const handleServiceControl = async (serviceName, action) => {
|
||||||
if (!isOnline) return;
|
if (!isOnline) return;
|
||||||
|
|
||||||
@@ -224,7 +241,7 @@ function Dashboard({ isOnline }) {
|
|||||||
<div className="ml-4">
|
<div className="ml-4">
|
||||||
<p className="text-sm font-medium text-gray-500">Uptime</p>
|
<p className="text-sm font-medium text-gray-500">Uptime</p>
|
||||||
<p className="text-lg font-semibold text-gray-900">
|
<p className="text-lg font-semibold text-gray-900">
|
||||||
{Math.floor((cellStatus.uptime || 0) / 3600)}h {Math.floor(((cellStatus.uptime || 0) % 3600) / 60)}m
|
{formatUptime(cellStatus.uptime || 0)}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user