async () => {
const clusterId = "cls_abc123"; // resolved by the agent from conversation
const kube = (path) => cnap.request({
method: "GET",
path: `/v1/clusters/${clusterId}/kube/${path}`
}).then(r => r.body);
// Get all pods across all namespaces
const allPods = await kube("api/v1/pods");
// Fetch logs for all running containers in parallel
const results = await Promise.all(
allPods.items
.filter(p => p.status.phase === "Running")
.flatMap(p =>
p.spec.containers.map(c => ({
namespace: p.metadata.namespace,
pod: p.metadata.name,
container: c.name
}))
)
.map(async ({ namespace, pod, container }) => {
try {
const logs = await kube(
`api/v1/namespaces/${namespace}/pods/${pod}/log?container=${container}`
);
const lines = typeof logs === "string"
? logs.split("\n").filter(Boolean).length : 0;
return { namespace, pod, container, lines };
} catch {
return { namespace, pod, container, lines: 0, error: true };
}
})
);
const total = results.reduce((sum, r) => sum + r.lines, 0);
results.sort((a, b) => b.lines - a.lines);
return { total_lines: total, per_pod: results };
}