Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Info about the processes running in docker containers
####
# docker container processes
####
# processes running in docker containers
> /tmp/docker.processes.txt
for i_container_id in $(docker ps | tr -s ' ' ',' | cut -d',' -f1 | grep -v CONTAINER)
do
CONTAINER_NAME=$(docker ps | tr -s ' ' ',' | grep "$i_container_id" | sed -e 's/.*,//g')
echo "# $i_container_id, $CONTAINER_NAME" | tee -a /tmp/docker.processes.txt
docker top $i_container_id | tee -a /tmp/docker.processes.txt
done
# Number of processes running in docker containers
cat /tmp/docker.processes.txt | grep -v "^#\|UID" | tr -s ' ' ',' | cut -d',' -f2 | sort -n | uniq | wc -l
# docker container processes
cat /tmp/docker.processes.txt
# process pids of processes running in docker container
cat /tmp/docker.processes.txt | grep -v "^#\|UID" | tr -s ' ' ',' | cut -d',' -f2 | sort -n | uniq
PIDS=$(cat /tmp/docker.processes.txt | grep -v "^#\|UID" | tr -s ' ' ',' | cut -d',' -f2 | sort -n | uniq | tr '\n' ' ')
# pid list
ps u -p $PIDS
# Total %MEM used by processes in docker containers
ps u -p $PIDS | tr -s ' ' ',' | grep -v "USER,PID" | cut -d',' -f4 | paste -sd+ | bc
# Total %CPU used by processes in docker containers
ps u -p $PIDS | tr -s ' ' ',' | grep -v "USER,PID" | cut -d',' -f3 | paste -sd+ | bc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.