Fixing check_varnish monitoring plugin for Varnish 6.5 and newer releases

Written by - 0 comments

Published on - last updated on June 21st 2024 - Listed in Monitoring Varnish


On all my environments with Varnish Cache (or the commercial Varnish Enterprise) I use the monitoring plugin check_varnish.py, which allows to monitor a Varnish process and retrieve Varnish-internal stats (using varnishstat).

This allows to create very helpful graphs, for example to show the growth of HIT vs MISS requests:

Plugin error when using Varnish Cache 6.5 or later

However after upgrading to Varnish Cache 6.5, check_varnish users would see an error message like this:

root@varnish:~# /usr/lib/nagios/plugins/check_varnish.py -f MAIN.n_lru_nuked,MAIN.cache_hit,MAIN.cache_miss
Traceback (most recent call last):
  File "/usr/lib/nagios/plugins/check_varnish.py", line 158, in <module>
    getopts()
  File "/usr/lib/nagios/plugins/check_varnish.py", line 152, in getopts
    varnishversion=int(args.arg_version.replace(".",""))
AttributeError: 'int' object has no attribute 'replace'

The reason for this is that the varnishstat (JSON) output has changed compared to the older versions. The stats counters are now nested under 'counters'.

To cope with this situation, a new parameter (-v / --version) was added to check_varnish.py. This allows the user to define which Varnish version is used for the check (maybe I'll replace this one day with an autodetection), handling the JSON output differently:

    if varnishversion >= 65:
      values.append(json_data['counters'][field]['value'])
    else:
      values.append(json_data[field]['value'])

How to use check_varnish with Varnish 6.5 and newer

A pull request for handling Varnish 6.5 was created in Olivier's repository. Until this is merged, the new check_varnish.py version (v1.7) can be downloaded from my GitHub fork.

To use the plugin with Varnish 6.5 and later, use the -v / --version parameter (the plugin assumes the Varnish version is 6.0):

root@varnish:~# /usr/lib/nagios/plugins/check_varnish.py -f MAIN.n_lru_nuked,MAIN.cache_hit,MAIN.cache_miss -v 6.5
VARNISH OK - MAIN.n_lru_nuked is 0 - MAIN.cache_hit is 344535 - MAIN.cache_miss is 368730 -  | MAIN.n_lru_nuked=0;0;0;; MAIN.cache_hit=344535;0;0;; MAIN.cache_miss=368730;0;0;;

Update: Automatic discovery of Varnish 6.5 and newer

Updated June 21st 2024

The added -v / --version parameters were removed again in v1.8 of the plugin, after discussing an automatic detection in the pull request. The adjusted (and now merged) code auto-detects the newer Varnish versions.

The json output of varnishstat contains a "version" field starting with Varnish 6.5. By checking for this field the plugin now knows that Varnish 6.5 (or newer) is in use.

This means: The check_varnish.py plugin now works out of the box, doesn't matter which Varnish version you run.

Varnish 6.0:

root@varnish:~# /usr/lib/nagios/plugins/check_varnish.py -f MAIN.n_lru_nuked,MAIN.cache_hit,MAIN.cache_miss
VARNISH OK - MAIN.n_lru_nuked is 0 - MAIN.cache_hit is 0 - MAIN.cache_miss is 0 -  | MAIN.n_lru_nuked=0;0;0;; MAIN.cache_hit=0;0;0;; MAIN.cache_miss=0;0;0;; 

Varnish 6.5:

root@varnish:~# /usr/lib/nagios/plugins/check_varnish.py -f MAIN.n_lru_nuked,MAIN.cache_hit,MAIN.cache_miss
VARNISH OK - MAIN.n_lru_nuked is 0 - MAIN.cache_hit is 0 - MAIN.cache_miss is 0 -  | MAIN.n_lru_nuked=0;0;0;; MAIN.cache_hit=0;0;0;; MAIN.cache_miss=0;0;0;; 

The usage remains the same. Much easier and backwards compatible to existing installations.

Which varnishstat fields should be monitored?

If you're new to Varnish monitoring and want to know which fields from the varnishstat output are worth being monitored (and graphed), check out my article from February 2020: Monitoring Varnish with check_varnish from multiple varnishstat fields.


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   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