Skip to content

Instantly share code, notes, and snippets.

@simonsj
Last active March 18, 2016 08:56
Show Gist options
  • Select an option

  • Save simonsj/ba81502832a24b32d1c0 to your computer and use it in GitHub Desktop.

Select an option

Save simonsj/ba81502832a24b32d1c0 to your computer and use it in GitHub Desktop.
Scrape out Some cgroups memory.stat Accounting
#!/bin/sh
#
# Original raw output looks something like this:
#
# # cat /sys/fs/cgroup/memory/git/memory.stat
# cache 33129496576
# rss 13348773888
# mapped_file 4296413184
# pgpgin 16204719443
# pgpgout 16193372209
# swap 83202048
# pgfault 39341890156
# pgmajfault 10387764
# inactive_anon 1939718144
# active_anon 11408601088
# inactive_file 16055021568
# active_file 17095233536
# unevictable 0
# hierarchical_memory_limit 51539607552
# hierarchical_memsw_limit 9223372036854775807
# total_cache 33129496576
# total_rss 13348806656
# total_mapped_file 4296417280
# total_pgpgin 16204719452
# total_pgpgout 16193372209
# total_swap 83202048
# total_pgfault 39341890166
# total_pgmajfault 10387764
# total_inactive_anon 1939718144
# total_active_anon 11408658432
# total_inactive_file 16055021568
# total_active_file 17095233536
# total_unevictable 0
#
#
# New output looks like:
#
# # ./show-cgroups-accounting.sh
# /sys/fs/cgroup/memory/git/memory.stat GB
#
# cache 33.85
# rss 10.86
# mapped_file 5.08
# swap 0.08
# inactive_anon 1.32
# active_anon 9.54
# inactive_file 16.26
# active_file 17.61
# unevictable 0.00
# hierarchical_memory_limit 48.00
#
set -e
printf "%40s %20s\n" "/sys/fs/cgroup/memory/git/memory.stat" "GB"
printf "\n"
cat /sys/fs/cgroup/memory/git/memory.stat |
grep -vE "(pgpg|memsw|fault)" | # drop "counts" of a couple of things, only interested in bytes
grep -v -e "total_" | # drop "total_" metrics: only interested in top level
while read metric bytes; do
printf "%40s %20.2f\n" "$metric" "$(printf "($bytes / 1024.0 / 1024.0 / 1024.0)\n" | bc -l)"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment