Skip to content

Instantly share code, notes, and snippets.

@jtopjian
Created May 5, 2014 21:22
Show Gist options
  • Select an option

  • Save jtopjian/2b63484a0365b5b358ba to your computer and use it in GitHub Desktop.

Select an option

Save jtopjian/2b63484a0365b5b358ba to your computer and use it in GitHub Desktop.
#!/bin/bash
case "$1" in
-g)
UNITS_DIV="/1024/1024"
UNITS="GB"
;;
-m)
UNITS_DIV="/1024"
UNITS="MB"
;;
-k)
UNITS_DIV=""
UNITS="kB"
;;
*)
UNITS_DIV="/1024"
UNITS="MB"
esac
mem_total=$((`cat /proc/meminfo | awk '/^MemTotal/ { print $2; }'`$UNITS_DIV))
mem_free=$((`cat /proc/meminfo | awk '/^MemFree/ { print $2; }'`$UNITS_DIV))
swap_free=$((`cat /proc/meminfo | awk '/^SwapFree/ { print $2; }'`$UNITS_DIV))
swap_total=$((`cat /proc/meminfo | awk '/^SwapTotal/ { print $2; }'`$UNITS_DIV))
slab_size=$((`cat /proc/meminfo | awk '/^Slab/ { print $2; }'`$UNITS_DIV))
dcache_size=$((`cat /proc/meminfo | awk '/^Cached/ { print $2; }'`$UNITS_DIV))
swapcache_size=$((`cat /proc/meminfo | awk '/^SwapCached/ { print $2; }'`$UNITS_DIV))
buffers_size=$((`cat /proc/meminfo | awk '/^Buffers/ { print $2; }'`$UNITS_DIV))
mem_free_no_cache=$(( $mem_free + $swapcache_size + $buffers_size))
zfs_arc_shrink_shift=`cat /sys/module/zfs/parameters/zfs_arc_shrink_shift`
zfs_arc_shrink_size=$(( $mem_total / (1<<$zfs_arc_shrink_shift) ))
swap_used=$(( $swap_total - $swap_free ))
pages_shared=$(cat /sys/kernel/mm/ksm/pages_shared)
pages_sharing=$(cat /sys/kernel/mm/ksm/pages_sharing)
pages_unshared=$(cat /sys/kernel/mm/ksm/pages_unshared)
pages_volatile=$(cat /sys/kernel/mm/ksm/pages_volatile)
page_size=$(getconf PAGESIZE)
ratio_sharing_to_shared=$(echo "scale=2;$pages_sharing / $pages_shared"|bc);
ratio_unshared_to_sharing=$(echo "scale=2;$pages_unshared / $pages_sharing"|bc);
ksm_saved=$(echo "scale=0;$pages_sharing * $page_size / 1024"|bc);
ksm_saved=$(($ksm_saved $UNITS_DIV))
if [ -d /proc/spl/kstat/zfs ]; then
arc_size=$((`cat /proc/spl/kstat/zfs/arcstats | awk '/^size/ { print $3; }'`/1024$UNITS_DIV))
arc_mfu_size=$((`cat /proc/spl/kstat/zfs/arcstats | awk '/^mfu_size/ { print $3; }'`/1024$UNITS_DIV))
arc_mfu_ghost_size=$((`cat /proc/spl/kstat/zfs/arcstats | awk '/^mfu_ghost_size/ { print $3; }'`/1024$UNITS_DIV))
arc_mru_size=$((`cat /proc/spl/kstat/zfs/arcstats | awk '/^mru_size/ { print $3; }'`/1024$UNITS_DIV))
arc_mru_ghost_size=$((`cat /proc/spl/kstat/zfs/arcstats | awk '/^mru_ghost_size/ { print $3; }'`/1024$UNITS_DIV))
arc_hits=$(grep '^hits' /proc/spl/kstat/zfs/arcstats | awk '{print $3}')
arc_misses=$(grep '^misses' /proc/spl/kstat/zfs/arcstats | awk '{print $3}')
arc_total=$(($arc_hits + $arc_misses))
arc_hit_rate=$(($arc_hits * 100 / $arc_total))
fi
printf "mem_total %12s $UNITS\n" $mem_total
printf "slab_size %12s $UNITS\n" $slab_size
printf "dcache_size %12s $UNITS\n" $dcache_size
printf "swapcache_size %12s $UNITS\n" $swapcache_size
printf "buffers_size %12s $UNITS\n" $buffers_size
printf "arc_size %12s $UNITS\n" $arc_size
printf "arc_mfu_size %12s $UNITS\n" $arc_mfu_size
printf "arc_mfu_ghost_size %12s $UNITS\n" $arc_mfu_ghost_size
printf "arc_mru_size %12s $UNITS\n" $arc_mru_size
printf "arc_mru_ghost_size %12s $UNITS\n" $arc_mru_ghost_size
printf "zfs_arc_shrink_size %12s $UNITS\n" $zfs_arc_shrink_size
printf "mem_free %12s $UNITS\n" $mem_free
printf "mem_free_no_cache %12s $UNITS\n" $mem_free_no_cache
printf "mem_swap_free %12s $UNITS\n" $swap_free
printf "mem_swap_used %12s $UNITS\n" $swap_used
printf "ksm_saved %12s $UNITS\n" $ksm_saved
printf "ksm_shared %12s\n" $pages_shared
printf "ksm_sharing %12s\n" $pages_sharing
printf "ksm_unsuared %12s\n" $pages_unshared
printf "ksm_volatile %12s\n" $pages_volatile
printf "ksm_sharing_ratio %12s %%\n" $ratio_sharing_to_shared
printf "ksm_unshared_ratio %12s %%\n" $ratio_unshared_to_sharing
if [ -d /proc/spl/kstat/zfs ]; then
printf "arc_hits %12s\n" $arc_hits
printf "arc_misses %12s\n" $arc_misses
printf "arc_hit_rate %12s %%\n" $arc_hit_rate
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment