diff --git a/plugins/varnish/varnish4_multigraph b/plugins/varnish/varnish similarity index 87% rename from plugins/varnish/varnish4_multigraph rename to plugins/varnish/varnish index 0d268358..bda5d86f 100755 --- a/plugins/varnish/varnish4_multigraph +++ b/plugins/varnish/varnish @@ -1,19 +1,43 @@ -#!/usr/bin/python3 -tt -# -*- coding: utf-8 -*- +#!/usr/bin/env python3 +# pylint: disable=invalid-name +# pylint: enable=invalid-name -""" Munin plugin to monitor Varnish 4 status. +"""Munin plugin to monitor Varnish status. -Copyright 2016, Kim B. Heino, b@bbbs.net, Foobar Oy -License GPLv2+ +=head1 NAME + +varnish - monitor Varnish status + +=head1 APPLICABLE SYSTEMS + +Systems running Varnish cache. + +=head1 CONFIGURATION + +No configuration is required for this plugin. + +=head1 NOTES + +This plugin is tested on Varnish 4 but it should also work with v5 and v6. + +=head1 AUTHOR + +Kim B. Heino This is based heavily on varnish4_ plugin from Munin contrib by Kristian Lyngstol / Redpill Linpro AS. -#%# capabilities=autoconf -#%# family=auto +=head1 LICENSE + +GPLv2 + +=head1 MAGIC MARKERS + + #%# family=auto + #%# capabilities=autoconf + +=cut """ -# pylint: disable=invalid-name -# pylint: enable=invalid-name import json import subprocess @@ -41,12 +65,6 @@ def get_values(): return {} -def autoconf(): - """Print "yes" or "no".""" - status = 'yes' if get_values() else 'no' - print(status) - - def config(): """Print plugin config.""" # pylint: disable=too-many-statements @@ -192,18 +210,16 @@ def config(): print('n_objectcore.label Number of object cores') print('n_objectcore.type GAUGE') print('n_objecthead.label Number of object heads') - print( - 'n_objecthead.info Each object head can have one or more object ' - 'attached, typically based on the Vary: header') + print('n_objecthead.info Each object head can have one or more object ' + 'attached, typically based on the Vary: header') print('n_objecthead.type GAUGE') # request_rate print('multigraph varnish_request_rate') print('graph_category webserver') print('graph_title Request rates') - print( - 'graph_order cache_hit cache_hitpass cache_miss backend_conn ' - 'backend_unhealthy client_req client_conn') + print('graph_order cache_hit cache_hitpass cache_miss backend_conn ' + 'backend_unhealthy client_req client_conn') print('client_req.label Good client requests received') print('client_req.min 0') print('client_req.colour 111111') @@ -238,10 +254,9 @@ def config(): print('cache_hitpass.min 0') print('cache_hitpass.draw STACK') print('cache_hitpass.colour FFFF00') - print( - 'cache_hitpass.info Hitpass are cached passes: An entry in the ' - 'cache instructing Varnish to pass. Typically achieved after a ' - 'pass in vcl_fetch.') + print('cache_hitpass.info Hitpass are cached passes: An entry in the ' + 'cache instructing Varnish to pass. Typically achieved after a ' + 'pass in vcl_fetch.') print('cache_hitpass.type DERIVE') print('cache_hit.label Cache hits') print('cache_hit.min 0') @@ -288,9 +303,8 @@ def config(): print('s_resp_hdrbytes.min 0') print('s_resp_hdrbytes.draw STACK') print('s_resp_hdrbytes.cdef s_resp_hdrbytes,8,*') - print( - 's_resp_hdrbytes.info HTTP Header traffic. TCP/IP overhead is not ' - 'included.') + print('s_resp_hdrbytes.info HTTP Header traffic. TCP/IP overhead is not ' + 'included.') print('s_resp_hdrbytes.type DERIVE') # uptime @@ -324,8 +338,7 @@ def fetch(): 'backend_reuse', 'backend_req', ): - print('{0}.value {1}'.format( - key, data['MAIN.' + key]['value'])) + print('{0}.value {1}'.format(key, data['MAIN.' + key]['value'])) # bad print('multigraph varnish_bad') @@ -344,12 +357,10 @@ def fetch(): 'threads_limited', 'fetch_failed', ): - print('{0}.value {1}'.format( - key, data['MAIN.' + key]['value'])) + print('{0}.value {1}'.format(key, data['MAIN.' + key]['value'])) print('SMA_Transient_c_fail.value {0}'.format( data['SMA.Transient.c_fail']['value'])) - print('SMF_s0_c_fail.value {0}'.format( - data['SMF.s0.c_fail']['value'])) + print('SMF_s0_c_fail.value {0}'.format(data['SMF.s0.c_fail']['value'])) # expunge print('multigraph varnish_expunge') @@ -357,8 +368,7 @@ def fetch(): 'n_lru_nuked', 'n_expired', ): - print('{0}.value {1}'.format( - key, data['MAIN.' + key]['value'])) + print('{0}.value {1}'.format(key, data['MAIN.' + key]['value'])) # hit_rate print('multigraph varnish_hit_rate') @@ -380,14 +390,10 @@ def fetch(): data['SMA.Transient.g_bytes']['value'])) print('SMA_Transient_g_space.value {0}'.format( data['SMA.Transient.g_space']['value'])) - print('SMF_s0_g_bytes.value {0}'.format( - data['SMF.s0.g_bytes']['value'])) - print('sms_nbytes.value {0}'.format( - data['MAIN.sms_nbytes']['value'])) - print('sms_balloc.value {0}'.format( - data['MAIN.sms_balloc']['value'])) - print('SMF_s0_g_space.value {0}'.format( - data['SMF.s0.g_space']['value'])) + print('SMF_s0_g_bytes.value {0}'.format(data['SMF.s0.g_bytes']['value'])) + print('sms_nbytes.value {0}'.format(data['MAIN.sms_nbytes']['value'])) + print('sms_balloc.value {0}'.format(data['MAIN.sms_balloc']['value'])) + print('SMF_s0_g_space.value {0}'.format(data['SMF.s0.g_space']['value'])) print('SMA_Transient_c_bytes.value {0}'.format( data['SMA.Transient.c_bytes']['value'])) @@ -399,8 +405,7 @@ def fetch(): 'n_objectcore', 'n_objecthead', ): - print('{0}.value {1}'.format( - key, data['MAIN.' + key]['value'])) + print('{0}.value {1}'.format(key, data['MAIN.' + key]['value'])) # request_rate print('multigraph varnish_request_rate') @@ -415,8 +420,7 @@ def fetch(): 'cache_hitpass', 'cache_hit', ): - print('{0}.value {1}'.format( - key, data['MAIN.' + key]['value'])) + print('{0}.value {1}'.format(key, data['MAIN.' + key]['value'])) # threads print('multigraph varnish_threads') @@ -427,8 +431,7 @@ def fetch(): 'threads_limited', 'threads', ): - print('{0}.value {1}'.format( - key, data['MAIN.' + key]['value'])) + print('{0}.value {1}'.format(key, data['MAIN.' + key]['value'])) # transfer_rates print('multigraph varnish_transfer_rates') @@ -436,8 +439,7 @@ def fetch(): 's_resp_bodybytes', 's_resp_hdrbytes', ): - print('{0}.value {1}'.format( - key, data['MAIN.' + key]['value'])) + print('{0}.value {1}'.format(key, data['MAIN.' + key]['value'])) # uptime print('multigraph varnish_uptime') @@ -446,7 +448,7 @@ def fetch(): if __name__ == '__main__': if len(sys.argv) > 1 and sys.argv[1] == 'autoconf': - autoconf() + print('yes' if get_values() else 'no (varnish is not running)') elif len(sys.argv) > 1 and sys.argv[1] == 'config': config() else: