$ docker stats --no-stream
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
a5ed2facaadd webcentos 0.00% 2.398MiB / 12.37GiB 0.02% 1.31kB / 0B 0B / 0B 2
e3a96695d263 docker_mysql_1 0.12% 187.5MiB / 12.37GiB 1.48% 1.05kB / 0B 0B / 0B 27
cc761f675b3b docker_nginx_1 0.00% 4.309MiB / 12.37GiB 0.03% 956B / 0B 0B / 0B 2
$ docker stats --no-stream --format "{{.Name}},{{.MemPerc}},{{.CPUPerc}}" #Nom du conteneur,Utilisation de la mémoire,l'utilisation du processeur
webcentos,0.02%,0.00%
docker_mysql_1,1.48%,0.12%
docker_nginx_1,0.03%,0.00%
#!/bin/bash
#Seuil(%)
LIMIT=90
#Obtenir des statistiques pour le conteneur
CHECK_STATS=$(docker stats --no-stream --format "{{.Name}},{{.MemPerc}},{{.CPUPerc}}") #Nom du conteneur,Utilisation de la mémoire,l'utilisation du processeur
while read row; do
name=`echo ${row} | cut -d , -f 1` #Nom du conteneur
memPer=`echo ${row} | cut -d , -f 2` #Utilisation de la mémoire
memPer_i=`echo ${memPer%%.*}`
cpuPer=`echo ${row} | cut -d , -f 3` #l'utilisation du processeur
cpuPer_i=`echo ${cpuPer%%.*}`
#Vérification du seuil d'utilisation de la mémoire
if [ $memPer_i -ge $LIMIT ]; then
message="Container:${name} Memory alert ${memPer}"
curl -X POST --data-urlencode 'payload={"channel": "#alert", "username": "admin", "text": "${message}"}' <webhook URL>
fi
#Vérification du seuil d'utilisation du processeur
if [ $cpuPer_i -ge $LIMIT ]; then
message="Container:${name} CPU alert ${cpuPer}"
curl -X POST --data-urlencode 'payload={"channel": "#alert", "username": "admin", "text": "${message}"}' <webhook URL>
fi
done < echo "$CHECK_STATS"
Recommended Posts