blob: 215c7908b688a8be7b449a9c7b63acfb1a8ab479 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
import React, { useEffect, useState } from 'react'
import { Link } from 'react-router-dom'
interface DaemonSummary {
id: string
ownerId: string
connectionId: string
hostname: string | null
machineId: string | null
maxConcurrentTasks: number
currentTaskCount: number
status: string
lastHeartbeatAt: string
connectedAt: string
disconnectedAt: string | null
}
function statusDotColor(status: string): string {
switch (status.toLowerCase()) {
case 'connected':
return 'green'
case 'disconnected':
return 'red'
case 'unhealthy':
return 'yellow'
default:
return 'gray'
}
}
export function DaemonList() {
const [daemons, setDaemons] = useState<DaemonSummary[]>([])
const [loading, setLoading] = useState(true)
const [error, setError] = useState<string | null>(null)
useEffect(() => {
async function fetchDaemons() {
try {
setLoading(true)
const response = await fetch('/api/v1/mesh/daemons')
if (!response.ok) {
throw new Error(`Failed to fetch daemons: ${response.statusText}`)
}
const data = await response.json()
setDaemons(data.daemons || [])
} catch (err) {
setError(err instanceof Error ? err.message : 'Unknown error')
} finally {
setLoading(false)
}
}
fetchDaemons()
const interval = setInterval(async () => {
try {
const response = await fetch('/api/v1/mesh/daemons')
if (response.ok) {
const data = await response.json()
setDaemons(data.daemons || [])
}
} catch {
// Silently ignore refresh errors
}
}, 10000)
return () => clearInterval(interval)
}, [])
if (loading) {
return (
<div className="daemon-list-container">
<div className="loading">Loading daemons...</div>
</div>
)
}
if (error) {
return (
<div className="daemon-list-container">
<div className="error">Error: {error}</div>
</div>
)
}
return (
<div className="daemon-list-container">
<Link to="/" className="back-link">
Back to Home
</Link>
<h1>Daemons</h1>
{daemons.length === 0 ? (
<p>No daemons found</p>
) : (
<ul className="daemon-list">
{daemons.map((daemon) => (
<li key={daemon.id} className="daemon-item">
<Link to={`/daemons/${daemon.id}`}>
<h2>{daemon.hostname || 'Unknown Host'}</h2>
<div className="daemon-status">
<span
className="status-dot"
style={{ backgroundColor: statusDotColor(daemon.status) }}
/>
<span>{daemon.status}</span>
</div>
<div className="daemon-meta">
<span>
Tasks: {daemon.currentTaskCount} / {daemon.maxConcurrentTasks}
</span>
<span>
Connected: {new Date(daemon.connectedAt).toLocaleString()}
</span>
{daemon.machineId && (
<span>Machine: {daemon.machineId}</span>
)}
</div>
</Link>
</li>
))}
</ul>
)}
</div>
)
}
|