1
0
Fork 0
mirror of https://github.com/munin-monitoring/contrib.git synced 2025-07-21 18:41:03 +00:00

Update memory_osx plugin

This commit is contained in:
sdarwin 2022-04-06 14:46:18 -05:00 committed by Lars Kruse
parent 04c0dc3ca5
commit cdccc5aef6

View file

@ -11,8 +11,7 @@ memory - Plugin to measure memory on osx.
=head1 NOTES
This plugin runs the top command once per interval, to discover memory usage on OSX.
Contributions are welcome to collect additional memory regions, if possible, such as buffers and caches.
This plugin runs the vm_stat command once per interval, to discover memory usage on OSX.
=head1 LICENSE
@ -35,33 +34,68 @@ if [ "$1" = "autoconf" ]; then
fi
fi
TOTALMEM=$(sysctl hw.memsize | cut -d" " -f2)
graphlimit=$TOTALMEM
dehumanise() {
echo "$1" | sed -e "s/K/*1024/g;s/M/*1024*1024/;s/G/*1024*1024*1024/;s/T/*1024*1024*1024*1024/"
}
if [ "$1" = "config" ]; then
echo 'graph_title Memory'
echo "graph_order used wired unused"
echo "graph_args --base 1024 -r --lower-limit 0 --upper-limit $graphlimit"
echo "graph_order wired app compressed cached free swap_used swap_free"
echo "graph_args --base 1024 -r --lower-limit 0"
echo 'graph_vlabel Bytes'
echo 'graph_category system'
echo 'used.label used (not incl. wired)'
echo 'used.draw AREA'
echo 'used.min 0'
echo "used.info Used memory, not including wired"
echo 'wired.label wired'
echo 'wired.draw STACK'
echo 'wired.draw AREA'
echo 'wired.min 0'
echo 'wired.info Wired memory'
echo 'app.label app'
echo 'app.draw STACK'
echo 'app.min 0'
echo "app.info Application memory"
echo 'compressed.label compressed'
echo 'compressed.draw STACK'
echo 'compressed.min 0'
echo 'compressed.info Compressed memory'
echo 'cached.label cached'
echo 'cached.draw STACK'
echo 'cached.min 0'
echo 'cached.info Cached memory'
echo 'free.label free'
echo 'free.draw STACK'
echo 'free.min 0'
echo 'free.info Free memory'
echo 'swap_used.label swap_used'
echo 'swap_used.draw STACK'
echo 'swap_used.min 0'
echo 'swap_used.info Swap used'
echo 'swap_free.label swap_free'
echo 'swap_free.draw STACK'
echo 'swap_free.min 0'
echo 'swap_free.info Swap free'
exit 0
fi
TOPINFO=$(top -l 1 | grep "PhysMem: ")
MEM_USED=$(echo "$TOPINFO" | awk '/PhysMem: / { print substr($2, 1, length($2)) }')
MEM_WIRED=$(echo "$TOPINFO" | awk '/PhysMem: / { print substr($4, 2, length($4)-1) }')
echo "used.value" $(( $(dehumanise "$MEM_USED") - $(dehumanise "$MEM_WIRED") ))
echo "wired.value" $(( $(dehumanise "$MEM_WIRED") ))
PAGESIZE=$(pagesize)
VMSTATINFO=$(vm_stat)
MEM_FREE=$(echo "$VMSTATINFO" | awk '/Pages free: / { print substr($3, 1, length($3)-1) }')
MEM_WIRED=$(echo "$VMSTATINFO" | awk '/Pages wired down: / { print substr($4, 1, length($4)-1) }')
MEM_ANONYMOUS=$(echo "$VMSTATINFO" | awk '/Anonymous pages: / { print substr($3, 1, length($3)-1) }')
MEM_PURGEABLE=$(echo "$VMSTATINFO" | awk '/Pages purgeable: / { print substr($3, 1, length($3)-1) }')
MEM_COMPRESSED=$(echo "$VMSTATINFO" | awk '/Pages occupied by compressor: / { print substr($5, 1, length($5)-1) }')
MEM_FILEBACKED=$(echo "$VMSTATINFO" | awk '/File-backed pages: / { print substr($3, 1, length($3)-1) }')
#
MEM_APP=$( echo "$MEM_ANONYMOUS $MEM_PURGEABLE" | awk '{ print $1 - $2 }')
MEM_CACHED=$( echo "$MEM_FILEBACKED $MEM_PURGEABLE" | awk '{ print $1 + $2 }')
#
SWAPINFO=$(sysctl vm.swapusage)
SWAP_USED=$(echo "$SWAPINFO" | awk '/vm.swapusage: / { print substr($7, 1, length($7)) }')
SWAP_FREE=$(echo "$SWAPINFO" | awk '/vm.swapusage: / { print substr($10, 1, length($10)) }')
#
echo "wired.value" $(( MEM_WIRED * PAGESIZE ))
echo "app.value" $(( MEM_APP * PAGESIZE ))
echo "compressed.value" $(( MEM_COMPRESSED * PAGESIZE ))
echo "cached.value" $(( MEM_CACHED * PAGESIZE ))
echo "free.value" $(( MEM_FREE * PAGESIZE ))
echo "swap_used.value" $( dehumanise "$SWAP_USED" | bc )
echo "swap_free.value" $( dehumanise "$SWAP_FREE" | bc )