-
-
Save ruby232/c3edc6c2737a4994c1011f31d9ed8118 to your computer and use it in GitHub Desktop.
A simple script to count the containers on a Docker host.
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
#!/bin/bash | |
function countContainers() { | |
docker ps -q $1 | wc -l | |
} | |
function countCrashedContainers() { | |
docker ps -a | grep -v -F 'Exited (0)' | grep -c -F 'Exited (' | |
} | |
TYPE=${1-all} | |
case $TYPE in | |
running) COUNT_FUNCTION="countContainers"; shift;; | |
crashed) COUNT_FUNCTION="countCrashedContainers"; shift;; | |
all) COUNT_FUNCTION="countContainers -a"; shift;; | |
esac | |
$COUNT_FUNCTION | |
# Ordenar container por CPU | |
#docker stats --no-stream --format "table {{.Name}}\t{{.Container}}\t{{.CPUPerc}}\t{{.MemUsage}}" | sort -k 3 -h | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment