Skip to content

Instantly share code, notes, and snippets.

@bboozzoo
Created December 23, 2020 11:20
Show Gist options
  • Save bboozzoo/6d49dc9f19c514bfebd26a59ecbc5a57 to your computer and use it in GitHub Desktop.
Save bboozzoo/6d49dc9f19c514bfebd26a59ecbc5a57 to your computer and use it in GitHub Desktop.
#!/bin/bash
set -eu -o pipefail
if [ -n "${V:-}" ]; then
set -x
fi
CGROUP_BASE_MOUNT=/sys/fs/cgroup
CGROUPV1_MEMORY_MOUNT=/sys/fs/cgroup/memory
help() {
echo "usage:"
echo " $(basename $0) [-d <sample-int>] <cgroup>"
}
sample_intv=1
while getopts d:h name; do
case "$name" in
d)
sample_intv="$OPTARG"
;;
h)
help
exit 0
;;
?)
echo "error: incorrect arguments"
help
exit 2
;;
esac
done
shift $(($OPTIND - 1))
cg="${1-}"
if [ -z "$cg" ]; then
echo "error: missing cgroup"
help
exit 1
fi
while true; do
total_rss="$(cat "$CGROUPV1_MEMORY_MOUNT/$cg/memory.stat" | awk '/^rss / { print $2 }')"
echo "$(LC_ALL=C date --rfc-3339=ns),$total_rss"
sleep "$sample_intv"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment