Last active
August 29, 2015 14:07
-
-
Save jtopjian/ef0c4f74c405fb3ebb10 to your computer and use it in GitHub Desktop.
mem-metrics
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| mem_total=$(cat /proc/meminfo | awk '/^MemTotal/ { print $2; }') | |
| mem_free=$(cat /proc/meminfo | awk '/^MemFree/ { print $2; }') | |
| swap_free=$(cat /proc/meminfo | awk '/^SwapFree/ { print $2; }') | |
| swap_total=$(cat /proc/meminfo | awk '/^SwapTotal/ { print $2; }') | |
| slab_size=$(cat /proc/meminfo | awk '/^Slab/ { print $2; }') | |
| dcache_size=$(cat /proc/meminfo | awk '/^Cached/ { print $2; }') | |
| swapcache_size=$(cat /proc/meminfo | awk '/^SwapCached/ { print $2; }') | |
| buffers_size=$(cat /proc/meminfo | awk '/^Buffers/ { print $2; }') | |
| mem_free_no_cache=$(( $mem_free + $swapcache_size + $buffers_size)) | |
| 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) | |
| if [ "${pages_shared}" != 0 ]; then | |
| ratio_sharing_to_shared=$(echo "scale=2;$pages_sharing / $pages_shared"|bc); | |
| else | |
| ratio_sharing_to_shared=0 | |
| fi | |
| if [ "${pages_unshared}" != 0 ]; then | |
| ratio_unshared_to_sharing=$(echo "scale=2;$pages_unshared / $pages_sharing"|bc); | |
| else | |
| ratio_unshared_to_sharing=0 | |
| fi | |
| ksm_saved=$(echo "scale=0;$pages_sharing * $page_size / 1024"|bc); | |
| if [ -d /proc/spl/kstat/zfs ]; then | |
| zfs_arc_shrink_shift=`cat /sys/module/zfs/parameters/zfs_arc_shrink_shift` | |
| zfs_arc_shrink_size=$(( $mem_total / (1<<$zfs_arc_shrink_shift) )) | |
| arc_size=$(cat /proc/spl/kstat/zfs/arcstats | awk '/^size/ { print $3; }') | |
| arc_mfu_size=$(cat /proc/spl/kstat/zfs/arcstats | awk '/^mfu_size/ { print $3; }') | |
| arc_mfu_ghost_size=$(cat /proc/spl/kstat/zfs/arcstats | awk '/^mfu_ghost_size/ { print $3; }') | |
| arc_mru_size=$(cat /proc/spl/kstat/zfs/arcstats | awk '/^mru_size/ { print $3; }') | |
| arc_mru_ghost_size=$(cat /proc/spl/kstat/zfs/arcstats | awk '/^mru_ghost_size/ { print $3; }') | |
| 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 | |
| hostname=$(hostname) | |
| epoch=$(date +%s) | |
| echo "${hostname}.meminfo.mem_total ${mem_total} ${epoch}" | |
| echo "${hostname}.meminfo.slab_size ${slab_size} ${epoch}" | |
| echo "${hostname}.meminfo.dcache_size ${dcache_size} ${epoch}" | |
| echo "${hostname}.meminfo.swapcache_size ${swapcache_size} ${epoch}" | |
| echo "${hostname}.meminfo.buffers_size ${buffers_size} ${epoch}" | |
| echo "${hostname}.meminfo.mem_free ${mem_free} ${epoch}" | |
| echo "${hostname}.meminfo.mem_free_no_cache ${mem_free_no_cache} ${epoch}" | |
| echo "${hostname}.meminfo.mem_swap_free ${swap_free} ${epoch}" | |
| echo "${hostname}.meminfo.mem_swap_used ${swap_used} ${epoch}" | |
| echo "${hostname}.meminfo.ksm_saved ${ksm_saved} ${epoch}" | |
| echo "${hostname}.meminfo.ksm_shared ${pages_shared} ${epoch}" | |
| echo "${hostname}.meminfo.ksm_sharing ${pages_sharing} ${epoch}" | |
| echo "${hostname}.meminfo.ksm_unshared ${pages_unshared} ${epoch}" | |
| echo "${hostname}.meminfo.ksm_volatile ${pages_volatile} ${epoch}" | |
| echo "${hostname}.meminfo.ksm_sharing_ratio ${ratio_sharing_to_shared} ${epoch}" | |
| echo "${hostname}.meminfo.ksm_unshared_ratio ${ratio_unshared_to_sharing} ${epoch}" | |
| if [ -d /proc/spl/kstat/zfs ]; then | |
| echo "${hostname}.meminfo.arc_hits ${arc_hits} ${epoch}" | |
| echo "${hostname}.meminfo.arc_misses ${arc_misses} ${epoch}" | |
| echo "${hostname}.meminfo.arc_hit_rate ${arc_hit_rate} ${epoch}" | |
| echo "${hostname}.meminfo.arc_size ${arc_size} ${epoch}" | |
| echo "${hostname}.meminfo.arc_mfu_size ${arc_mfu_size} ${epoch}" | |
| echo "${hostname}.meminfo.arc_mfu_ghost_size ${arc_mfu_ghost_size} ${epoch}" | |
| echo "${hostname}.meminfo.zfs_arc_shrink_size ${zfs_arc_shrink_size} ${epoch}" | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment