-
-
Save cronnelly/4143783 to your computer and use it in GitHub Desktop.
A munin plugin to graph zram usage
This file contains 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 | |
# -*- sh -*- | |
: << =cut | |
=head1 NAME | |
zram - Plugin to monitor zram usage | |
=head1 CONFIGURATION | |
No configuration | |
=head1 AUTHOR | |
Unknown author | |
=head1 LICENSE | |
GPLv2 | |
=head1 MAGIC MARKERS | |
#%# family=auto | |
#%# capabilities=autoconf | |
=cut | |
. $MUNIN_LIBDIR/plugins/plugin.sh | |
if [ "$1" = "autoconf" ]; then | |
if [ -r /sys/block/zram0 ]; then | |
echo yes | |
exit 0 | |
else | |
echo "no (no zram device)" | |
exit 0 | |
fi | |
fi | |
if [ "$1" = "config" ]; then | |
echo 'multigraph zram_usage' | |
echo 'graph_title zram usage' | |
echo 'graph_vlabel bytes' | |
echo 'graph_category system' | |
echo 'disksize.label size' | |
echo 'used.label used' | |
echo 'compressed.label compressed' | |
echo 'memory_used.label memory_used' | |
echo | |
echo 'multigraph zram_efficiency' | |
echo 'graph_title zram efficiency' | |
echo "graph_args -r --lower-limit 0 --upper-limit 100" | |
echo 'graph_vlabel compression efficiency' | |
echo 'graph_category system' | |
echo 'efficiency.label efficiency %' | |
exit 0 | |
fi | |
# Zram Location | |
ZL="/sys/block/zram*" | |
used=$(cat $ZL/orig_data_size | awk '{s+=$1} END {print s}') | |
memory_used=$(cat $ZL/mem_used_total | awk '{s+=$1} END {print s}') | |
disksize=$(cat $ZL/disksize | awk '{s+=$1} END {print s}') | |
compressed=$(cat $ZL/compr_data_size | awk '{s+=$1} END {print s}') | |
efficiency=$(echo "scale=2; 100 - $memory_used * 100 / $used" | bc -l) | |
echo 'multigraph zram_usage' | |
echo "disksize.value $disksize" | |
echo "used.value $used" | |
echo "compressed.value $compressed" | |
echo "memory_used.value $memory_used" | |
echo | |
echo "multigraph zram_efficiency" | |
echo "efficiency.value $efficiency" |
In 2015 several of the sysfs files were moved into a single 'mm_stat' file.
https://gist.github.com/Imroy/54cf25786f53c6fdd67c240812f47cc6
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
I added the following to the config section (after memory_used.label) to make sure the memory usage gets devided by 1024 to get to kilobytes and megabytes. Deviding by 1000 seems to be the munin default.
echo 'graph_args --base 1024'
https://gist.github.com/janlam7/6565257/ccd00607766aafc548d3044849024d4999ee3706
Jan