Monitoring Varnish Cache Hit Rate (Ratio) with check_varnish

Written by - 0 comments

Published on - Listed in Varnish Monitoring


Personally I have been using check_varnish.py to monitor Varnish Cache (and Plus) for a long time. In the past I've also contributed a couple of times in this open source monitoring plugin and described how to use check_varnish and create graphs from Varnish statistics.

The Cache Hit Rate

As I was implementing a different cache/memory backend, I wanted to compare the Cache Hit Rate before and after the cache changes. The Cache Hit Rate (sometimes also named Cache Hit Ratio) is a very important value telling you how many of your requests are served from the cache. As Arianna Aondio describes it:

The cache hit rate is the percentage of requests that result in cache hits. In Varnish it is evaluated as cache_hit / (cache_hit + cache_miss). The higher the hit rate the more effective your cache is.

However varnishstat does not show this object. It needs to be calculcated manually using the MAIN.cache_hit and MAIN.cache_miss values.

root@varnish:~# varnishstat -n varnish3 -1 | grep MAIN.cache
MAIN.cache_hit                  43616371        27.82 Cache hits
MAIN.cache_hit_grace            14902812         9.51 Cache grace hits
MAIN.cache_hitpass                     0         0.00 Cache hits for pass.
MAIN.cache_hitmiss               2043449         1.30 Cache hits for miss.
MAIN.cache_miss                 32955140        21.02 Cache misses

Using these values and the formula mentioned above this results in:

Cache Hit Rate = cache_hit / (cache_hit + cache_miss)
therefore
0.569616172 = 43616371 / (43616371 + 32955140)

Adding Cache Hit Rate calculation in check_varnish

Of course this can be automated. We already have the check_varnish monitoring plugin doing most of the work. It just needs to obtain the values of MAIN.cache_hit and MAIN.cache_miss and apply the formula. VoilĂ , the Cache Hit Rate value is there.

The next version (most likely 1.5) of check_varnish will be able to calculate the Cache Hit Rate by applying the -r or --hitratio parameter to the plugin:

root@varnish:~# /usr/lib/nagios/plugins/check_varnish.py -n varnish3 -f MAIN.cache_hit,MAIN.cache_miss -r
VARNISH OK - MAIN.cache_hit is 43629247 - MAIN.cache_miss is 32964372 - Cache Hit Rate is 0.57 -  | MAIN.cache_hit=43629247;0;0;; MAIN.cache_miss=32964372;0;0;; hitrate=0.57;0;0;;

Requirement for this is that both MAIN.cache_hit and MAIN.cache_miss are mentioned in the fields (-f) list. The plugin will exit with a state unknown in this (human) error is made:

root@varnish:~# /usr/lib/nagios/plugins/check_varnish.py -n varnish3 -f MAIN.backend_fail -r
VARNISH UNKNOWN - Must use MAIN.cache_hit and MAIN.cache_miss in field list to calculate hit ratio

The pull request with the code changes was sent in today.


Add a comment

Show form to leave a comment

Comments (newest first)

No comments yet.

RSS feed

Blog Tags:

  AWS   Android   Ansible   Apache   Apple   Atlassian   BSD   Backup   Bash   Bluecoat   CMS   Chef   Cloud   Coding   Consul   Containers   CouchDB   DB   DNS   Database   Databases   Docker   ELK   Elasticsearch   Filebeat   FreeBSD   Galera   Git   GlusterFS   Grafana   Graphics   HAProxy   HTML   Hacks   Hardware   Icinga   Icingaweb   Icingaweb2   Influx   Internet   Java   KVM   Kibana   Kodi   Kubernetes   LVM   LXC   Linux   Logstash   Mac   Macintosh   Mail   MariaDB   Minio   MongoDB   Monitoring   Multimedia   MySQL   NFS   Nagios   Network   Nginx   OSSEC   OTRS   Office   PGSQL   PHP   Perl   Personal   PostgreSQL   Postgres   PowerDNS   Proxmox   Proxy   Python   Rancher   Rant   Redis   Roundcube   SSL   Samba   Seafile   Security   Shell   SmartOS   Solaris   Surveillance   Systemd   TLS   Tomcat   Ubuntu   Unix   VMWare   VMware   Varnish   Virtualization   Windows   Wireless   Wordpress   Wyse   ZFS   Zoneminder   


Update cookies preferences