Last active
July 10, 2017 23:54
-
-
Save beldpro-ci/3888043be8582f0a97e01f7cdcd59923 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# let's get the ID of the container. Docker uses that ID | |
# to name things in the host to we can probably use it to | |
# find the cgroup created for the container | |
# under the parent docker cgroup | |
docker ps | |
CONTAINER ID IMAGE COMMAND | |
a730051832e7 cirocosta/stress "pid -n 300" | |
# Having the prefix in hands, let's search for it under the | |
# mountpoint for cgroups in our system | |
find /sys/fs/cgroup/ -name "a730051832e7*" | |
/sys/fs/cgroup/cpu,cpuacct/docker/a730051832e7d776442b2e969e057660ad108a7d6e6a30569398ec660a75a959 | |
/sys/fs/cgroup/cpuset/docker/a730051832e7d776442b2e969e057660ad108a7d6e6a30569398ec660a75a959 | |
/sys/fs/cgroup/devices/docker/a730051832e7d776442b2e969e057660ad108a7d6e6a30569398ec660a75a959 | |
/sys/fs/cgroup/pids/docker/a730051832e7d776442b2e969e057660ad108a7d6e6a30569398ec660a75a959 | |
/sys/fs/cgroup/freezer/docker/a730051832e7d776442b2e969e057660ad108a7d6e6a30569398ec660a75a959 | |
/sys/fs/cgroup/perf_event/docker/a730051832e7d776442b2e969e057660ad108a7d6e6a30569398ec660a75a959 | |
/sys/fs/cgroup/blkio/docker/a730051832e7d776442b2e969e057660ad108a7d6e6a30569398ec660a75a959 | |
/sys/fs/cgroup/memory/docker/a730051832e7d776442b2e969e057660ad108a7d6e6a30569398ec660a75a959 | |
/sys/fs/cgroup/net_cls,net_prio/docker/a730051832e7d776442b2e969e057660ad108a7d6e6a30569398ec660a75a959 | |
/sys/fs/cgroup/hugetlb/docker/a730051832e7d776442b2e969e057660ad108a7d6e6a30569398ec660a75a959 | |
/sys/fs/cgroup/systemd/docker/a730051832e7d776442b2e969e057660ad108a7d6e6a30569398ec660a75a959 | |
# There they are! Docker creates a control group with the name | |
# being the exact ID of the container under all the subsystems. | |
# What can we discover from this inspection? We can look at the | |
# subsystem that we want to place contrainst on (PIDs), for instance: | |
tree /sys/fs/cgroup/pids/docker/a7300518327d... | |
/sys/fs/cgroup/pids/docker/a73005183... | |
├── cgroup.clone_children | |
├── cgroup.procs | |
├── notify_on_release | |
├── pids.current | |
├── pids.events | |
├── pids.max | |
└── tasks | |
# Which means that, if we want to know how many PIDs are in use right | |
# now we can look at 'pids.current', to know the limits, 'pids.max' and | |
# to know which processes have been assigned to this control group, | |
# look at tasks. Lets do it: | |
cat /sys/fs/cgroup/pids/docker/a730...c660a75a959/tasks | |
5329 | |
5371 | |
5372 | |
5373 | |
5374 | |
5375 | |
5376 | |
5377 | |
(...) | |
# continues until the 300th entry - as we have 300 processes in this container | |
# 300 pids | |
cat /sys/fs/cgroup/pids/docker/a730051832e7d7764...9/pids.current | |
300 | |
# no max set | |
cat /sys/fs/cgroup/pids/docker/a730051832e7d77.../pids.max | |
max |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment