/ grafana

zswap metrics with Telegraf

A couple of weeks ago I discover zswap. zswap is a Linux kernel a compressed write-back cache for swapped pages. I activated this on my VPS.

Active zswap runtime

echo 1 > /sys/module/zswap/parameters/enabled

or reboot persistent, add the following line to /etc/default/grub


With a system that is running pretty normal you won't notice this effect right away. So we need some stats about zswap to see what it is doing. These stats about zswap are available in the kernel. You can find them in /sys/kernel/debug/zswap

$:/sys/kernel/debug/zswap# grep . *

As I love stats, I want to add these to Grafana. Normaly I use telegraf to collect statistics and insert them to influxDB. So I created a small plugin to collect these stats. All that is needed is on my GitHub page.

Grafana screenshot zswap telegraf

Grafana screenshot zswap

install telegraf plugin

Download the swap.conf and swap.sh from my GitHub and place them in the telegraf.d dir.

Make sure you put the next part in /etc/sudoers

telegraf ALL = NOPASSWD: /etc/telegraf/telegraf.d/zswap.sh

When run with:

telegraf --test --config /etc/telegraf/telegraf.d/zswap.conf

It should produce:

* Plugin: inputs.exec, Collection 1
> zswap,host=birdofprey pool_limit_hit=0,reject_kmemcache_fail=0,stored_pages=62742,written_back_pages=0,reject_reclaim_fail=0,duplicate_entry=0,pool_total_size=128495616,reject_alloc_fail=0,reject_compress_poor=2762 1498400744000000000


service telegraf restart

After this it should log the statistics of zswap in InfluxDB. Now you can setup a dashboard for zswap in Grafana.

Dennis Kruyt

Dennis Kruyt

Dennis works as a Technical Consultant. When not consumed by work, he enjoys dabbling in photography, electronics, demotica, IoT and whatever other technologies are currently tickling his fancy.

Read More