Skip to content

Instantly share code, notes, and snippets.

@maurobaraldi
Forked from KyleBanks/docker-stats-json
Last active July 30, 2021 16:48
Show Gist options
  • Save maurobaraldi/f2b200315d1607073f22a11f247a62ad to your computer and use it in GitHub Desktop.
Save maurobaraldi/f2b200315d1607073f22a11f247a62ad to your computer and use it in GitHub Desktop.
Returns Docker stats as a JSON Object

Docker Status Command Line Mode

docker stats --no-stream --format "{\"container\": \"{{ .Container }}\", \"memory\": { \"raw\": \"{{ .MemUsage }}\", \"percent\": \"{{ .MemPerc }}\"}, \"cpu\": \"{{ .CPUPerc }}\"}"

Docker Status Command Line Mode + Date - JSON format

docker stats --no-stream --format "{\"container\": \"{{ .Container }}\", \"name\": \"{{ .Name }}\", \"memory\": { \"raw\": \"{{ .MemUsage }}\", \"percent\": \"{{ .MemPerc }}\"}, \"cpu\": \"{{ .CPUPerc }}\"}###" | sed "s/}###/, \"date\": $(date \"+%d\/%m\/%Y %H:%M\")},/g" >> /home/mauro/docker_homolog_status.json

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment