Skip to content

Instantly share code, notes, and snippets.

@thejmazz
Created September 14, 2017 18:59
Show Gist options
  • Save thejmazz/5567ca5e46f408d7a0dd871dd086d756 to your computer and use it in GitHub Desktop.
Save thejmazz/5567ca5e46f408d7a0dd871dd086d756 to your computer and use it in GitHub Desktop.
Get mb/days of logfile for a docker container
#!/usr/bin/env sh
# Usage: call with docker container name, requires stat
# E.g. sudo ./logs-per-hour project_service_1
id=$(docker inspect $1 --format "{{ .ID }}")
started_date=$(docker inspect $id --format "{{ .Created}}")
started=$(date +%s -d ${started_date})
now=$(date +%s)
diff=$(($now - $started))
diff_days=$(awk -v diff=$diff 'BEGIN { print diff / 86400}')
log_size=$(stat --printf="%s" /var/lib/docker/containers/$id/$id-json.log)
log_size_mb=$(awk -v b=$log_size 'BEGIN { print b / 1024 }')
log_mb_per_day=$(awk -v bytes=$log_size_mb -v days=$diff_days 'BEGIN { print bytes / days }')
echo "$1: $log_mb_per_day mb/day"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment