Docker Container Usage

2/1/2017

I am running docker with kubernetes.

I need to find out when the last time docker container is used by a user. I am creating one container per user.I have to kill that container if the user has not interacted with the container for a specific amount of time.

Currently, I am running a daemon inside docker container which checks last modified files and sends the info.

Is there any docker/kubernetes API for the same?

-- rishabh.bhardwaj
containers
docker
docker-api
kubernetes

1 Answer

2/3/2017

I thinks there's no API for that as "usage" is something which is hard to measure. One way would be to check whether systems stopped logging at some point back in time.

The other option would be to use the metrics which are exposed by Kubernetes and bring up monitoring and alerting systems like Prometheus to tell you once a Deployment/Pod is not used anymore. "Usage" could then be determined through the exposed network metrics e.g. like this:

max_over_time(
   container_network_receive_bytes_total{kubernetes_pod_name=~"^yourdeployment.*
quot;
}[1h] )

If that's below a certain threshold you could trigger and alert and perform further actions.

-- pagid
Source: StackOverflow