Last active
February 24, 2024 13:31
-
-
Save CroneKorkN/476778bb669dcb7610ba7f8ac5a930bb to your computer and use it in GitHub Desktop.
zfs arc hit ratio monitor
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 | |
# author: louwrentius | |
# source: http://louwrentius.com/zfs-on-linux-monitor-cache-hit-ratio.html | |
INTERVAL="$1" | |
if [ -z $INTERVAL ] | |
then | |
INTERVAL=5 | |
fi | |
OLDHITS=0 | |
OLDMISS=0 | |
L2OLDHITS=0 | |
L2OLDMISS=0 | |
i=0 | |
while true | |
do | |
RAW=`cat /proc/spl/kstat/zfs/arcstats` | |
HITS=`echo "$RAW" | grep -w hits | awk '{ print $3}'` | |
L2HITS=`echo "$RAW" | grep -w l2_hits | awk '{ print $3}'` | |
MISSES=`echo "$RAW" | grep -w misses | awk '{ print $3}'` | |
L2MISSES=`echo "$RAW" | grep -w l2_misses | awk '{ print $3}'` | |
HITRATE=$(((HITS-OLDHITS)/INTERVAL)) | |
L2HITRATE=$(((L2HITS-L2OLDHITS)/INTERVAL)) | |
MISSRATE=$(((MISSES-OLDMISS)/INTERVAL)) | |
L2MISSRATE=$(((L2MISSES-L2OLDMISS)/INTERVAL)) | |
OLDHITS=$HITS | |
L2OLDHITS=$L2HITS | |
OLDMISS=$MISSES | |
L2OLDMISS=$L2MISSES | |
REQS=$((HITRATE+MISSRATE)) | |
if [ "$HITRATE" != 0 ] && [ "$REQS" != 0 ] | |
then | |
HITPERCENT=`echo "scale=2; (($HITRATE / $REQS) * 100)" | bc` | |
L2HITPERCENT=`echo "scale=2; (($L2HITRATE / $REQS) * 100)" | bc` | |
else | |
HITPERCENT=0 | |
L2HITPERCENT=0 | |
fi | |
if [ "$i" -gt 0 ] | |
then | |
echo "IOPs: $REQS | ARC cache hit ratio: $HITPERCENT % | Hitrate: $HITRATE / Missrate: $MISSRATE | L2ARC $L2HITPERCENT $L2HITRATE / $L2MISSRATE" | |
else | |
echo "..." | |
fi | |
((i++)) | |
sleep $INTERVAL | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice!