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.
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)
0.569616172 = 43616371 / (43616371 + 32955140)
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.
No comments yet.
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 GlusterFS Grafana Graphics HAProxy HTML Hacks Hardware Icinga Icingaweb Icingaweb2 InfluxDB Internet Java KVM Kibana Kodi Kubernetes 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