Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retrieving the PID of a specific container #3470

Open
danielkleinstein opened this issue Feb 21, 2024 · 0 comments
Open

Retrieving the PID of a specific container #3470

danielkleinstein opened this issue Feb 21, 2024 · 0 comments

Comments

@danielkleinstein
Copy link

danielkleinstein commented Feb 21, 2024

Hi all, I'm trying to understand if I can use cAdvisor to monitor for newly created containers and then retrieve the PID of those specific containers.

I am using this API:

http://localhost:8080/api/v1.3/events?stream=true&all_events=true&subcontainers=true

Which allows me to monitor for new containers. I then receive a message such as:

{"container_name":"/system.slice/docker-394b73cdd59f26778a19868b9f960837914c12392177f76a54841df6f9f20586.scope","timestamp":"2024-02-21T13:23:55.844120129Z","event_type":"containerCreation","event_data":{}}

i.e. a container with a name of /system.slice/docker-394b73cdd59f26778a19868b9f960837914c12392177f76a54841df6f9f20586.scope, which I've learned is the name of the container's cgroup.

If I query the (undocumented) /ps endpoint at:

http://localhost:8080/api/v2.0/ps

Then I see my container in the output:

...
{"user":"root","pid":337870,"parent_pid":337850,"start_time":"13:23","percent_cpu":0,"percent_mem":0,"rss":3801088,"virtual_size":4739072,"status":"Ss+","running_time":"00:00:00","cgroup_path":"/../docker-394b73cdd59f26778a19868b9f960837914c12392177f76a54841df6f9f20586.scope","cmd":"bash","fd_count":4,"psr":5},
...

Which has the PID I want - 337870. However this involves retrieving the entirety of /ps output to retrieve the PID of a specific container, which has non-trivial performance implications in my usecase. I tried to do this:

http://localhost:8080/api/v2.0/ps/system.slice/docker-394b73cdd59f26778a19868b9f960837914c12392177f76a54841df6f9f20586.scope

To retrieve the specific container's information, but then I just get an empty list:

[]

And trying variations of the name (e.g. copying the /../docker-394b73cdd59f26778a19868b9f960837914c12392177f76a54841df6f9f20586.scope cgroup_path specified in the /ps output above) invariably results in a:

process listing failed: unknown container 

Would really appreciate help on this, thanks in advance!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant