Skip to content

Instantly share code, notes, and snippets.

@cronnelly
Created November 25, 2012 14:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save cronnelly/4143783 to your computer and use it in GitHub Desktop.
Save cronnelly/4143783 to your computer and use it in GitHub Desktop.
A munin plugin to graph zram usage
#!/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"
@janlam7
Copy link

janlam7 commented Sep 14, 2013

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

@Imroy
Copy link

Imroy commented Jul 22, 2018

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