Skip to content

Commit 9073439

Browse files
committed
mod_k8s: allow pod cpu-state to show stopped/crashed etc. with last update, and pass on network counters if supplied from containerd.
1 parent e8aa938 commit 9073439

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

src/Linux/mod_k8s.c

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,18 @@ extern "C" {
261261
HSPK8sContainer *container;
262262
UTHASH_WALK(pod->containers, container) {
263263
if(container->stats.state == SFL_VIR_DOMAIN_RUNNING) {
264+
// if any container in the pod is running, then say the pod is running...
264265
stats.state = SFL_VIR_DOMAIN_RUNNING;
265266
}
267+
else if(stats.state != SFL_VIR_DOMAIN_RUNNING) {
268+
// ...otherwise follow whatever is the state of the last container in this pod.
269+
// This way we should report that the pod has stopped (or crashed) along with
270+
// the last counter-sample update. So the collector can know if the pod ended
271+
// gracefully, reclaim resources immiediately, and still accrue the residual
272+
// counter-deltas for the last moments. This could be important if the pod only
273+
// ran for a few seconds.
274+
stats.state = container->stats.state;
275+
}
266276
stats.cpu_count += container->stats.cpu_count;
267277
EVDebug(mod, 2, "getCounters_POD(): container %s has cpu_count %u (total now = %u)",
268278
container->name ?: "<no name>",
@@ -279,10 +289,17 @@ extern "C" {
279289
stats.dsk.wr_req += container->stats.dsk.wr_req;
280290
stats.dsk.wr_bytes += container->stats.dsk.wr_bytes;
281291
stats.dsk.errs += container->stats.dsk.errs;
282-
// TODO: accumulate net counters too? (If they appear)
292+
stats.net.bytes_in += container->stats.net.bytes_in;
293+
stats.net.bytes_in += container->stats.net.bytes_in;
294+
stats.net.pkts_in += container->stats.net.pkts_in;
295+
stats.net.errs_in += container->stats.net.errs_in;
296+
stats.net.drops_in += container->stats.net.drops_in;
297+
stats.net.bytes_out += container->stats.net.bytes_out;
298+
stats.net.pkts_out += container->stats.net.pkts_out;
299+
stats.net.errs_out += container->stats.net.errs_out;
300+
stats.net.drops_out += container->stats.net.drops_out;
283301
}
284302

285-
// TODO: how to detect that a POD has stopped? No containers running?
286303
pod->state = stats.state;
287304

288305
// host ID

0 commit comments

Comments
 (0)