Add CXP_CONTAINER_STATE Metric
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)
Does docker socket returns specific code for containers status or we should handle it our self?
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.
we have to inspect what get_containers returns to see whether Docker provides such info.
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)'}
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.
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
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?