Skip to content

Instantly share code, notes, and snippets.

@andboson
Last active September 10, 2022 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andboson/83b6d0c9f43e9314a3c0f2cc35363d95 to your computer and use it in GitHub Desktop.
Save andboson/83b6d0c9f43e9314a3c0f2cc35363d95 to your computer and use it in GitHub Desktop.
Monitor memory of docker container usage in Graphite
# run graphite
docker run \
--name graphite \
--restart=always \
-p 81:80 \
-p 2003-2004:2003-2004 \
-p 2023-2024:2023-2024 \
-p 8125:8125/udp \
-p 8126:8126 \
graphiteapp/graphite-statsd
# collect and send metrics
while true; do t="my_service.mem $(docker stats --no-stream --format "{{ .MemUsage }}" <container_name> |cut -d'/' -f1 |rev | cut -c5- | rev) `date +%s`"; echo $t; echo $t | nc -w3 127.0.0.1 2003; done
while true; do t="my_service.cpu $(docker stats --no-stream --format "{{ .CPUPerc}}" <container_name> |rev | cut -c2- | rev) `date +%s`"; echo $t; echo $t | nc -w3 127.0.0.1 2003; done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment