user-cont / conu

conu - python API for your containers
http://conu.readthedocs.io/en/latest/
MIT License
165 stars 33 forks source link

Access to resource usage? #378

Closed ghost closed 4 years ago

ghost commented 4 years ago

Hi,

We have some containers that appear to use up all the memory allocated to it on k8s which then results in the container getting evicted. We think we have a fix for it but would like to be able to check the memory usage before and after we run some test to make sure this is about the same.

Can this be done with conu?

TomasTomecek commented 4 years ago

It can, but it will much easier for you to do it directly with a kubernetes client.

conu is about portability b/w container runtimes; since you're on k8s, you don't need that

ghost commented 4 years ago

but how do we detect of there is a memory leak in the container or its using up disk space it shouldn't? That is within the container

TomasTomecek commented 4 years ago

I'm sorry but this is not a support forum for your organization. Reach out to your vendor to get those questions answered.

(hint: cgroups and k8s resource limits)

ghost commented 4 years ago

This has nothing to do with k8s! This is a container testing framework, right? HOW DO YOU TEST RESOURCE USAGE OF A CONTAINER WITH THIS FRAMEWORK? I'm asking for access to Docker status info in this framework. This is a Docker container testing framework ISN'T IT? https://docs.docker.com/engine/reference/commandline/stats/

TomasTomecek commented 4 years ago

First of all, I consider the caps lock to be completely unprofessional and over the line.

Second, you should have asked your question more clearly - you mentioned k8s in your first post, then it was a generic container and finally it's a docker container.

Third, we don't have native support for resources in conu right now (and probably will never have since we no longer actively develop this project). You can use docker-py directly to get all those stats dockerd provides:

In [2]: c = conu.DockerContainer(image=None, container_id=None, name="my-container")

In [3]: print(next(c.d.stats(c.get_id())))
b'{"read":"2020-03-12T08:40:12.843337229Z","preread":"0001-01-01T00:00:00Z","pids_stats":{"current":1},"blkio_stats":{"io_service_bytes_recursive":[{"major":259,"minor":0,"op":"Read","value":49528832},{"major":259,"minor":0,"op":"Write","value":0},{"major...

Docker-py equivalent of that code would be something like:

>>> import docker

>>> client = docker.APIClient()

>>> stats = client.stats("my-container")