Skip to content

Commit ddffa7d

Browse files
committed
Merge branch 'eclipse-pullpiri:main' into main
2 parents a8b116d + af62b03 commit ddffa7d

File tree

3 files changed

+197
-102
lines changed

3 files changed

+197
-102
lines changed

src/tools/dashboard/.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
VITE_SETTING_SERVICE_API_URL=http://0.0.0.0:8080

src/tools/dashboard/src/components/Dashboard.tsx

Lines changed: 123 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useState } from "react";
1+
import { useEffect, useState } from "react";
22
import { Sidebar } from "./Sidebar";
33
import { Header } from "./Header";
44
import { Overview } from "./Overview";
@@ -39,73 +39,128 @@ export function Dashboard() {
3939
const [selectedPodName, setSelectedPodName] = useState<string>("");
4040

4141
// Move pods state to Dashboard level
42-
const [pods, setPods] = useState<Pod[]>([
43-
{
44-
name: "frontend-app-7d4b8c9f8d-xyz12",
45-
image: "nginx:1.21",
46-
labels: { app: "frontend", version: "v1.2.0" },
47-
node: "worker-node-1",
48-
status: "Running",
49-
cpuUsage: "45m",
50-
memoryUsage: "128Mi",
51-
age: "2d",
52-
ready: "1/1",
53-
restarts: 0,
54-
ip: "10.244.1.15",
55-
},
56-
{
57-
name: "frontend-app-7d4b8c9f8d-abc34",
58-
image: "nginx:1.21",
59-
labels: { app: "frontend", version: "v1.2.0" },
60-
node: "worker-node-2",
61-
status: "Running",
62-
cpuUsage: "38m",
63-
memoryUsage: "115Mi",
64-
age: "2d",
65-
ready: "1/1",
66-
restarts: 0,
67-
ip: "10.244.2.18",
68-
},
69-
{
70-
name: "backend-api-5f6a7b8c9d-def56",
71-
image: "node:18-alpine",
72-
labels: { app: "backend", tier: "api" },
73-
node: "worker-node-1",
74-
status: "Running",
75-
cpuUsage: "120m",
76-
memoryUsage: "256Mi",
77-
age: "5d",
78-
ready: "1/1",
79-
restarts: 1,
80-
ip: "10.244.1.22",
81-
},
82-
{
83-
name: "redis-cache-8e9f0a1b2c-ghi78",
84-
image: "redis:7-alpine",
85-
labels: { app: "redis", role: "cache" },
86-
node: "worker-node-3",
87-
status: "Running",
88-
cpuUsage: "25m",
89-
memoryUsage: "64Mi",
90-
age: "1d",
91-
ready: "1/1",
92-
restarts: 0,
93-
ip: "10.244.3.9",
94-
},
95-
{
96-
name: "database-migration-1a2b3c4d5e-jkl90",
97-
image: "postgres:14",
98-
labels: { job: "migration", app: "database" },
99-
node: "worker-node-2",
100-
status: "Pending",
101-
cpuUsage: "0m",
102-
memoryUsage: "0Mi",
103-
age: "30m",
104-
ready: "0/1",
105-
restarts: 0,
106-
ip: "N/A",
107-
},
108-
]);
42+
43+
// Lgsi pod data
44+
const [podsToUse, setPods] = useState<Pod[]>([]);
45+
const [podsFetchSuccess, setPodsFetchSuccess] = useState(false);
46+
47+
useEffect(() => {
48+
const settingserviceApiUrl = import.meta.env.VITE_SETTING_SERVICE_API_URL;
49+
if (!settingserviceApiUrl) return;
50+
fetch(`${settingserviceApiUrl}/api/v1/metrics`)
51+
.then(res => res.json())
52+
.then(data => {
53+
// Filter for containers only
54+
const containers = Array.isArray(data)
55+
? data.filter(
56+
(item: any) =>
57+
item.component === "container" &&
58+
item.metric_type === "ContainerInfo" &&
59+
item.value &&
60+
item.value.value
61+
)
62+
: [];
63+
if (containers.length > 0) {
64+
// Map API data to Pod[]
65+
const mappedPods = containers.map((item: any, idx: number) => {
66+
const val = item.value.value;
67+
return {
68+
name: (val.names && val.names[0]) || val.id || `pod-${idx}`,
69+
image: val.image || "",
70+
labels: item.labels || {},
71+
node: (val.state && (val.state.node_name || val.state.hostname)) || (val.config.Hostname) || "",
72+
status: (val.state && (val.state.status || val.state.Status)) || "",
73+
cpuUsage: val.stats?.CpuTotalUsage || "",
74+
memoryUsage: val.stats?.MemoryUsage || "",
75+
age: item.timestamp || "",
76+
ready: "", // Not available in this API, leave blank or compute if possible
77+
restarts: 0, // Not available, default to 0
78+
ip: item.labels?.ip || "",
79+
};
80+
});
81+
setPods(mappedPods);
82+
setPodsFetchSuccess(true);
83+
console.log("✅ Pods API (metrics) fetched:", mappedPods);
84+
} else {
85+
setPodsFetchSuccess(false);
86+
}
87+
})
88+
.catch(e => {
89+
setPodsFetchSuccess(false);
90+
console.error("❌ Pods API (metrics) fetch failed:", e);
91+
});
92+
}, []);
93+
94+
95+
const pods = podsFetchSuccess && podsToUse.length > 0
96+
? podsToUse
97+
: [
98+
{
99+
name: "frontend-app-7d4b8c9f8d-xyz12",
100+
image: "nginx:1.21",
101+
labels: { app: "frontend", version: "v1.2.0" },
102+
node: "worker-node-1",
103+
status: "Running",
104+
cpuUsage: "45m",
105+
memoryUsage: "128Mi",
106+
age: "2d",
107+
ready: "1/1",
108+
restarts: 0,
109+
ip: "10.244.1.15",
110+
},
111+
{
112+
name: "frontend-app-7d4b8c9f8d-abc34",
113+
image: "nginx:1.21",
114+
labels: { app: "frontend", version: "v1.2.0" },
115+
node: "worker-node-2",
116+
status: "Running",
117+
cpuUsage: "38m",
118+
memoryUsage: "115Mi",
119+
age: "2d",
120+
ready: "1/1",
121+
restarts: 0,
122+
ip: "10.244.2.18",
123+
},
124+
{
125+
name: "backend-api-5f6a7b8c9d-def56",
126+
image: "node:18-alpine",
127+
labels: { app: "backend", tier: "api" },
128+
node: "worker-node-1",
129+
status: "Running",
130+
cpuUsage: "120m",
131+
memoryUsage: "256Mi",
132+
age: "5d",
133+
ready: "1/1",
134+
restarts: 1,
135+
ip: "10.244.1.22",
136+
},
137+
{
138+
name: "redis-cache-8e9f0a1b2c-ghi78",
139+
image: "redis:7-alpine",
140+
labels: { app: "redis", role: "cache" },
141+
node: "worker-node-3",
142+
status: "Running",
143+
cpuUsage: "25m",
144+
memoryUsage: "64Mi",
145+
age: "1d",
146+
ready: "1/1",
147+
restarts: 0,
148+
ip: "10.244.3.9",
149+
},
150+
{
151+
name: "database-migration-1a2b3c4d5e-jkl90",
152+
image: "postgres:14",
153+
labels: { job: "migration", app: "database" },
154+
node: "worker-node-2",
155+
status: "Pending",
156+
cpuUsage: "0m",
157+
memoryUsage: "0Mi",
158+
age: "30m",
159+
ready: "0/1",
160+
restarts: 0,
161+
ip: "N/A",
162+
},
163+
];
109164

110165
// Calculate running pods count
111166
const runningPodsCount = pods.filter(

src/tools/dashboard/src/components/Workloads.tsx

Lines changed: 73 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useState } from "react";
1+
import { useEffect, useState } from "react";
22
import { createPortal } from "react-dom";
33
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "./ui/card";
44
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "./ui/table";
@@ -44,6 +44,34 @@ export function Workloads({ onPodClick, pods, setPods }: WorkloadsProps) {
4444
right: number;
4545
} | null>(null);
4646

47+
// LGSI changes:
48+
const [nodesDataToUse, setNodesDataToUse] = useState<any[]>([]); // Replace mock with fetched data
49+
const [nodesFetchSuccess, setNodesFetchSuccess] = useState(false);
50+
51+
useEffect(() => {
52+
const settingserviceApiUrl = import.meta.env.VITE_SETTING_SERVICE_API_URL;
53+
if (!settingserviceApiUrl) {
54+
console.error("VITE_SETTING_SERVICE_API_URL is not defined");
55+
return;}
56+
fetch(`${settingserviceApiUrl}/api/v1/metrics/nodes`)
57+
.then(res => res.json())
58+
.then(data => {
59+
if (Array.isArray(data) && data.length > 0) {
60+
setNodesDataToUse(data);
61+
setNodesFetchSuccess(true);
62+
console.log("✅ Nodes API fetched:", data);
63+
} else {
64+
setNodesFetchSuccess(false);
65+
setNodesDataToUse([]);
66+
}
67+
})
68+
.catch(e => {
69+
setNodesFetchSuccess(false);
70+
setNodesDataToUse([]);
71+
console.error("❌ Nodes API fetch failed:", e);
72+
});
73+
}, []);
74+
4775
// Dialog states
4876
const [logsDialog, setLogsDialog] = useState<{
4977
open: boolean;
@@ -150,38 +178,49 @@ export function Workloads({ onPodClick, pods, setPods }: WorkloadsProps) {
150178
const failedPods = pods.filter((pod) => pod.status === "Failed").length;
151179
*/
152180
// Nodes data with more detailed information
153-
const nodesData = [
154-
{
155-
name: "worker-node-1",
156-
pods: pods.filter((pod) => pod.node === "worker-node-1").length,
181+
const nodesData = nodesFetchSuccess
182+
? nodesDataToUse.map((node: any) => ({
183+
name: node.node_name,
184+
pods: pods.filter((pod) => pod.node === node.node_name).length,
157185
status: "Ready",
158-
cpu: "2.4/4",
159-
memory: "3.2/8",
160-
cpuUsage: 60,
161-
memoryUsage: 40,
162-
storageUsage: 35,
163-
},
164-
{
165-
name: "worker-node-2",
166-
pods: pods.filter((pod) => pod.node === "worker-node-2").length,
167-
status: "Ready",
168-
cpu: "1.8/4",
169-
memory: "2.1/8",
170-
cpuUsage: 45,
171-
memoryUsage: 26,
172-
storageUsage: 50,
173-
},
174-
{
175-
name: "worker-node-3",
176-
pods: pods.filter((pod) => pod.node === "worker-node-3").length,
177-
status: "Ready",
178-
cpu: "0.8/4",
179-
memory: "1.5/8",
180-
cpuUsage: 20,
181-
memoryUsage: 19,
182-
storageUsage: 60,
183-
},
184-
];
186+
cpu: `${(node.cpu_usage / 100 * node.cpu_count).toFixed(1)}/${node.cpu_count}`,
187+
memory: `${(node.used_memory / 1024 / 1024 / 1024).toFixed(1)}/${(node.total_memory / 1024 / 1024 / 1024).toFixed(1)}`,
188+
cpuUsage: Number(node.cpu_usage.toFixed(1)),
189+
memoryUsage: Number(node.mem_usage.toFixed(1)),
190+
storageUsage: 0, // If you have storage info, fill here
191+
}))
192+
: [
193+
{
194+
name: "worker-node-1",
195+
pods: pods.filter((pod) => pod.node === "worker-node-1").length,
196+
status: "Ready",
197+
cpu: "2.4/4",
198+
memory: "3.2/8",
199+
cpuUsage: 60,
200+
memoryUsage: 40,
201+
storageUsage: 35,
202+
},
203+
{
204+
name: "worker-node-2",
205+
pods: pods.filter((pod) => pod.node === "worker-node-2").length,
206+
status: "Ready",
207+
cpu: "1.8/4",
208+
memory: "2.1/8",
209+
cpuUsage: 45,
210+
memoryUsage: 26,
211+
storageUsage: 50,
212+
},
213+
{
214+
name: "worker-node-3",
215+
pods: pods.filter((pod) => pod.node === "worker-node-3").length,
216+
status: "Ready",
217+
cpu: "0.8/4",
218+
memory: "1.5/8",
219+
cpuUsage: 20,
220+
memoryUsage: 19,
221+
storageUsage: 60,
222+
},
223+
];
185224

186225
// Get unique node names from pods
187226
const availableNodes = Array.from(new Set(pods.map((pod) => pod.node)));
@@ -210,13 +249,13 @@ export function Workloads({ onPodClick, pods, setPods }: WorkloadsProps) {
210249
// Calculate cluster health based on actual data
211250
/* const totalPods = pods.length; //2025-09-23 comment out
212251
const runningPodPercentage =
213-
totalPods > 0 ? (runningPods / totalPods) * 100 : 100;
252+
totalPods > 0 ? (runningPods / totalPods) * 100 : 100;
214253
const healthyNodeCount = nodesData.filter(
215254
(node) => node.status === "Ready"
216255
).length;
217256
const totalNodeCount = nodesData.length;
218257
const nodeHealthPercentage =
219-
totalNodeCount > 0 ? (healthyNodeCount / totalNodeCount) * 100 : 100;
258+
totalNodeCount > 0 ? (healthyNodeCount / totalNodeCount) * 100 : 100;
220259
*/
221260
// Determine cluster health status
222261
/*const getClusterHealth = () => { //2025-09-23 comment out

0 commit comments

Comments
 (0)