Fix cluster client issues

- Extract real client IP address from websocket connection
- Preserve connected_at timestamp for accurate uptime calculation
- Send full GPU device info from client to master for proper VRAM reporting
parent e5e3cc98
...@@ -86,13 +86,7 @@ class ClusterClient: ...@@ -86,13 +86,7 @@ class ClusterClient:
'capabilities': capabilities, 'capabilities': capabilities,
'weight': self.client_weight, 'weight': self.client_weight,
'shared_dir': self.shared_dir, 'shared_dir': self.shared_dir,
'gpu_info': { 'gpu_info': gpu_info # Send full gpu_info including device details
'cuda_available': gpu_info['cuda'],
'rocm_available': gpu_info['rocm'],
'cuda_devices': gpu_info['cuda_devices'],
'rocm_devices': gpu_info['rocm_devices'],
'available_backends': available_backends
}
} }
} }
await self.websocket.send(json.dumps(auth_msg)) await self.websocket.send(json.dumps(auth_msg))
......
...@@ -209,7 +209,11 @@ class ClusterMaster: ...@@ -209,7 +209,11 @@ class ClusterMaster:
# Get hostname and IP # Get hostname and IP
hostname = client_info.get('hostname', 'unknown') hostname = client_info.get('hostname', 'unknown')
ip_address = '127.0.0.1' # Placeholder, could be extracted from websocket # Try to get real IP address from websocket
try:
ip_address = websocket.remote_address[0] if websocket.remote_address else '127.0.0.1'
except:
ip_address = '127.0.0.1'
# Save client to database # Save client to database
weight = client_info.get('weight', 100) weight = client_info.get('weight', 100)
......
...@@ -1665,11 +1665,25 @@ def save_cluster_client(client_id: str, token: str, hostname: str, ip_address: s ...@@ -1665,11 +1665,25 @@ def save_cluster_client(client_id: str, token: str, hostname: str, ip_address: s
last_seen = CURRENT_TIMESTAMP last_seen = CURRENT_TIMESTAMP
''', (client_id, token, hostname, ip_address, weight, gpu_info_json, available_backends_json)) ''', (client_id, token, hostname, ip_address, weight, gpu_info_json, available_backends_json))
else: else:
cursor.execute(''' # For SQLite, preserve connected_at if client already exists
INSERT OR REPLACE INTO cluster_clients cursor.execute('SELECT connected_at FROM cluster_clients WHERE client_id = ?', (client_id,))
(client_id, token, hostname, ip_address, weight, gpu_info, available_backends, connected, connected_at, last_seen) existing = cursor.fetchone()
VALUES (?, ?, ?, ?, ?, ?, ?, 1, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)
''', (client_id, token, hostname, ip_address, weight, gpu_info_json, available_backends_json)) if existing and existing['connected_at']:
# Update existing client, preserve connected_at
cursor.execute('''
UPDATE cluster_clients SET
hostname = ?, ip_address = ?, weight = ?, gpu_info = ?, available_backends = ?,
connected = 1, last_seen = CURRENT_TIMESTAMP
WHERE client_id = ?
''', (hostname, ip_address, weight, gpu_info_json, available_backends_json, client_id))
else:
# Insert new client
cursor.execute('''
INSERT INTO cluster_clients
(client_id, token, hostname, ip_address, weight, gpu_info, available_backends, connected, connected_at, last_seen)
VALUES (?, ?, ?, ?, ?, ?, ?, 1, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)
''', (client_id, token, hostname, ip_address, weight, gpu_info_json, available_backends_json))
conn.commit() conn.commit()
success = cursor.rowcount > 0 success = cursor.rowcount > 0
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment