Container-Exporter icon indicating copy to clipboard operation
Container-Exporter copied to clipboard

Add CXP_CONTAINER_STATE Metric

Open Shayan-Ghani opened this issue 7 months ago • 7 comments

right now cxp_container_status does the job with 0 , 1 , 2 but it's good to track the exact state of 2 whether it's one the many states( e.g paused,” “exited,” “created but not started,” , etc)

Shayan-Ghani avatar May 31 '25 10:05 Shayan-Ghani

Does docker socket returns specific code for containers status or we should handle it our self?

shaerpour avatar Jun 03 '25 09:06 shaerpour

In get_containers, many fields as State: Running, paused, etc., are returned, along with the Status returns something like "up for 5 minutes". We rather intend to add the Value of the State field stored. However, I am not pretty sure where we can get the "Paused/unhealthy" status from for the Status code 2 on cxp_container_status.

Shayan-Ghani avatar Jun 06 '25 11:06 Shayan-Ghani

we have to inspect what get_containers returns to see whether Docker provides such info.

Shayan-Ghani avatar Jun 06 '25 12:06 Shayan-Ghani

it sounds like it does: 'Ports': [{'IP': '0.0.0.0', 'PrivatePort': 3000, 'PublicPort': 3000, 'Type': 'tcp'}, {'IP': '::', 'PrivatePort': 3000, 'PublicPort': 3000, 'Type': 'tcp'}], 'State': 'paused', 'Status': 'Up 2 hours (Paused)'}

Shayan-Ghani avatar Jun 06 '25 12:06 Shayan-Ghani

All status types are created, restarting, running, removing, paused, exited, or dead as documented here. So maybe using a dict object having all these types and then get value from it in update_container_status function can be a good idea.

shaerpour avatar Jun 07 '25 11:06 shaerpour

You're right about the doc. I think creating a dict is not necessary, all we got to do is assigning the metric, whatever value 'State' holds. That way we don't store anything we just update the metric for the container on update_container_status

Shayan-Ghani avatar Jun 07 '25 15:06 Shayan-Ghani

Every container state should have numbers to assign in gauge_container_status metric. Right now running containers are 1 and others are 0. Checking one by one is not really a good idea. Any ideas on how to handle it?

shaerpour avatar Jun 08 '25 12:06 shaerpour