swarm_memreservation.sh 626 B

123456789101112131415161718
  1. #!/bin/bash
  2. exec 2> /dev/null
  3. TOTALRESERVE=0
  4. for SERVICENAME in $(docker service ls -q); do
  5. echo -n $( docker service inspect ${SERVICENAME} -f {{.Spec.Name}} )' '
  6. SERVICE_RESERVE=$(docker service inspect $SERVICENAME -f {{.Spec.TaskTemplate.Resources.Reservations.MemoryBytes}})
  7. if [ $? -eq 0 ]; then
  8. SERVICE_RESERVE=$(( SERVICE_RESERVE*$(docker service ps $SERVICENAME -q -f desired-state=running | wc -l)/1024/1024 ))
  9. else
  10. SERVICE_RESERVE='none'
  11. fi
  12. echo ' Total service reserved '$SERVICE_RESERVE' M'
  13. TOTALRESERVE=$(( TOTALRESERVE+SERVICE_RESERVE ))
  14. done
  15. echo 'Summary reserved '$TOTALRESERVE' M'