mirror of
https://github.com/karl0ss/homepage.git
synced 2025-05-02 13:33:40 +01:00
Prefer swarm task containers locally for status / stats
This commit is contained in:
parent
aabd05a0cb
commit
f74275293a
@ -53,17 +53,25 @@ export default async function handler(req, res) {
|
|||||||
})
|
})
|
||||||
.catch(() => []);
|
.catch(() => []);
|
||||||
|
|
||||||
// For now we are only interested in the first one (in case replicas > 1).
|
|
||||||
// TODO: Show the result for all replicas/containers?
|
// TODO: Show the result for all replicas/containers?
|
||||||
const taskContainerId = tasks.at(0)?.Status?.ContainerStatus?.ContainerID;
|
// We can only get stats for 'local' containers so try to find one
|
||||||
|
const localContainerIDs = containers.map(c => c.Id);
|
||||||
|
const task = tasks.find(t => localContainerIDs.includes(t.Status?.ContainerStatus?.ContainerID)) ?? tasks.at(0);
|
||||||
|
const taskContainerId = task?.Status?.ContainerStatus?.ContainerID;
|
||||||
|
|
||||||
if (taskContainerId) {
|
if (taskContainerId) {
|
||||||
|
try {
|
||||||
const container = docker.getContainer(taskContainerId);
|
const container = docker.getContainer(taskContainerId);
|
||||||
const stats = await container.stats({ stream: false });
|
const stats = await container.stats({ stream: false });
|
||||||
|
|
||||||
return res.status(200).json({
|
return res.status(200).json({
|
||||||
stats,
|
stats,
|
||||||
});
|
});
|
||||||
|
} catch (e) {
|
||||||
|
return res.status(200).json({
|
||||||
|
error: "Unable to retrieve stats"
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,11 +53,14 @@ export default async function handler(req, res) {
|
|||||||
})
|
})
|
||||||
.catch(() => []);
|
.catch(() => []);
|
||||||
|
|
||||||
// For now we are only interested in the first one (in case replicas > 1).
|
|
||||||
// TODO: Show the result for all replicas/containers?
|
// TODO: Show the result for all replicas/containers?
|
||||||
const taskContainerId = tasks.at(0)?.Status?.ContainerStatus?.ContainerID;
|
// We can only get stats for 'local' containers so try to find one
|
||||||
|
const localContainerIDs = containers.map(c => c.Id);
|
||||||
|
const task = tasks.find(t => localContainerIDs.includes(t.Status?.ContainerStatus?.ContainerID)) ?? tasks.at(0);
|
||||||
|
const taskContainerId = task?.Status?.ContainerStatus?.ContainerID;
|
||||||
|
|
||||||
if (taskContainerId) {
|
if (taskContainerId) {
|
||||||
|
try {
|
||||||
const container = docker.getContainer(taskContainerId);
|
const container = docker.getContainer(taskContainerId);
|
||||||
const info = await container.inspect();
|
const info = await container.inspect();
|
||||||
|
|
||||||
@ -65,6 +68,13 @@ export default async function handler(req, res) {
|
|||||||
status: info.State.Status,
|
status: info.State.Status,
|
||||||
health: info.State.Health?.Status,
|
health: info.State.Health?.Status,
|
||||||
});
|
});
|
||||||
|
} catch (e) {
|
||||||
|
if (task) {
|
||||||
|
return res.status(200).json({
|
||||||
|
status: task.Status.State
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user