diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2016-04-27 14:26:04 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2016-04-27 15:02:18 +0300 |
commit | 94973146c58df26b20e17e2e5b1274216ca88969 (patch) | |
tree | 17538cc2991af0acec5bebfe6a826ef67cd9fc95 | |
parent | 319c154c46214fdc5d8f8b498ae5a23bc8d03072 (diff) | |
download | varnish-mib-94973146c58df26b20e17e2e5b1274216ca88969.tar.gz varnish-mib-94973146c58df26b20e17e2e5b1274216ca88969.tar.bz2 |
Support for Varnish 4.1
* NEWS: Update.
* bootstrap: Rewrite as a Perl script; create m4/varnish_mib.m4
from src/varnish_mib.mib2c
* configure.ac: Version 1.1.90
Use AC_CHECK_VSC_C_MAIN_MEMBERS
Define VARNISHAPI_MAJOR, VARNISHAPI_MINOR and
VARNISHAPI_PATCH for use in preprocessor directives.
* src/betab.c [VARNISHAPI_MINOR] (VSC_POINT_FMT): Define
depending on Varnish API minor version.
* src/varnish_mib.mib2c (varnish_translate_table): New variable.
It is used both by varnish_translate in this module, and by
bootstrap to produce a list of macros checking for members of
struct VSC_C_main.
Output preprocessor conditionals in right places.
* src/vcli.c (vcli_connect): Fix cc warnings.
* src/varnish-mib.8: Update.
-rw-r--r-- | NEWS | 11 | ||||
-rwxr-xr-x | bootstrap | 84 | ||||
-rw-r--r-- | configure.ac | 20 | ||||
-rw-r--r-- | src/betab.c | 8 | ||||
-rw-r--r-- | src/varnish-mib.8 | 40 | ||||
-rw-r--r-- | src/varnish_mib.mib2c | 39 | ||||
-rw-r--r-- | src/vcli.c | 4 |
7 files changed, 172 insertions, 34 deletions
@@ -1,25 +1,30 @@ -Varnish-mib NEWS -- history of user-visible changes. 2015-02-25 -Copyright (C) 2014-2015 Sergey Poznyakoff +Varnish-mib NEWS -- history of user-visible changes. 2016-04-27 +Copyright (C) 2014-2016 Sergey Poznyakoff See the end of file for copying conditions. Please send Varnish-mib bug reports to <gray@gnu.org> +Version 1.1.90 (Git) + +* Support for Varnish 4.1 + + Version 1.1, 2015-02-25 * Don't exit if unable to open Varnish memory file Version 1.0, 2014-11-28 Initial release. * Copyright information: -Copyright (C) 2014-2015 Sergey Poznyakoff +Copyright (C) 2014-2016 Sergey Poznyakoff Permission is granted to anyone to make or distribute verbatim copies of this document as received, in any medium, provided that the copyright notice and this permission notice are preserved, thus giving the recipient permission to redistribute in turn. @@ -1,7 +1,77 @@ -#!/bin/sh -for dir in m4 build-aux -do - test -d $dir || mkdir $dir -done -> ChangeLog -autoreconf -f -i -s +#!/usr/bin/perl +use strict; +use autodie; + +my $mib2c_config = 'src/varnish_mib.mib2c'; + +die "This file must be run from the varnish-mib top level source directory" + unless -r $mib2c_config; + +print "$0: creating ancillary directories and files\n"; +foreach my $dir ('m4', 'build-aux') { + mkdir($dir) unless -d $dir; +} + +unless (-f 'ChangeLog') { + open(my $fd, '>', 'ChangeLog'); + print $fd <<EOT +This file is a placeholder. It will be filled with actual data by the first +run of make. +EOT +; + close $fd; +} + +print "$0: generating m4/varnish_mib.m4\n"; +open(my $fd, '<', $mib2c_config); +my $prog; +while (<$fd>) { + if (defined($prog)) { + last if /^\@endperl\@/; + $prog .= $_; + } else { + if (/^\@startperl\@/) { + $prog = "no strict \"vars\";\n"; + } + } +} + +my %vars; +eval $prog; +die $@ if $@; +die "$mib2c_config does not declare translation table" + unless exists $vars{'varnish_translate_table'}; + +open(my $fd, '>', 'm4/varnish_mib.m4'); +print $fd <<'EOT'; +AC_DEFUN([AC_CHECK_VSC_C_MAIN_MEMBERS], +[save_CFLAGS="$CFLAGS" +CFLAGS="$CFLAGS $VARNISHAPI_CFLAGS" +EOT +; + +foreach my $member (sort + map { $_->[1] } + grep { $_->[0] eq 'MAIN' } + values %{$vars{'varnish_translate_table'}}) { + print $fd <<EOT + AC_CHECK_MEMBERS([struct VSC_C_main.$member],,, +[#include <stddef.h> +#include <stdlib.h> +#include <stdint.h> +#include <limits.h> +#include <vapi/vsc.h> +#include <vapi/vsm.h> +#include <vcli.h>]) +EOT +; +} +print $fd <<'EOT' +CFLAGS="$save_CFLAGS" +]) +EOT +; +close $fd; + +print "$0: reconfiguring\n"; +exec('autoreconf -f -i -s'); diff --git a/configure.ac b/configure.ac index d571518..cf0bf05 100644 --- a/configure.ac +++ b/configure.ac @@ -1,8 +1,8 @@ # This file is part of Varnish-mib -*- autoconf -*- -# Copyright (C) 2014-2015 Sergey Poznyakoff +# Copyright (C) 2014-2016 Sergey Poznyakoff # # Varnish-mib is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3, or (at your option) # any later version. # @@ -12,13 +12,13 @@ # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with Varnish-mib. If not, see <http://www.gnu.org/licenses/>. AC_PREREQ(2.69) -AC_INIT([varnish-mib], 1.1, [gray@gnu.org]) +AC_INIT([varnish-mib], 1.1.90, [gray@gnu.org]) AC_CONFIG_SRCDIR(src/varnish_mib.mib2c) AM_CONFIG_HEADER(config.h) AC_CONFIG_AUX_DIR([build-aux]) AC_CONFIG_MACRO_DIR([m4]) AC_CANONICAL_SYSTEM @@ -40,12 +40,28 @@ AC_PROG_MAKE_SET # Check for pkg-config PKG_PROG_PKG_CONFIG # Checks for Varnish PKG_CHECK_MODULES([VARNISHAPI], [varnishapi >= 4.0]) +varnishapi_version() { + AC_DEFINE_UNQUOTED([VARNISHAPI_MAJOR],[$1],[Varnish API major version number]) + AC_DEFINE_UNQUOTED([VARNISHAPI_MINOR],[$2],[Varnish API minor version number]) + AC_DEFINE_UNQUOTED([VARNISHAPI_PATCH],[$3],[Varnish API patchlevel]) +} + +v=$($PKG_CONFIG --modversion varnishapi) +if test -n "$v"; then + save_IFS=$IFS + IFS='.' + varnishapi_version $v + IFS=$save_IFS +fi + +AC_CHECK_VSC_C_MAIN_MEMBERS + # Check for Net-SNMP AC_PATH_PROG([NET_SNMP_CONFIG], net-snmp-config, none, $PATH) if test "$NET_SNMP_CONFIG" = "none"; then AC_MSG_ERROR([cannot find Net-SNMP (net-snmp-config not found)]) fi AC_SUBST(NET_SNMP_CONFIG) diff --git a/src/betab.c b/src/betab.c index b583958..49e02f7 100644 --- a/src/betab.c +++ b/src/betab.c @@ -56,13 +56,19 @@ create_entry(netsnmp_tdata *table_data, long idx, return entry; } #define VSC_POINT_TYPE(p) ((p)->section->fantom->type) #define VSC_POINT_IDENT(p) ((p)->section->fantom->ident) #define VSC_POINT_NAME(p) ((p)->desc->name) -#define VSC_POINT_FMT(p) ((p)->desc->fmt) +#if VARNISHAPI_MINOR == 0 +# define VSC_POINT_FMT(p) ((p)->desc->fmt) +#elif VARNISHAPI_MINOR == 1 +# define VSC_POINT_FMT(p) ((p)->desc->ctype) +#else +# error "unsupported Varnish API minor number" +#endif struct betab_priv { int err; long idx; struct backendTable_entry ent; netsnmp_tdata *table; diff --git a/src/varnish-mib.8 b/src/varnish-mib.8 index 4559b0c..0c54e6f 100644 --- a/src/varnish-mib.8 +++ b/src/varnish-mib.8 @@ -1,8 +1,8 @@ .\" This file is part of Varnish-mib -*- nroff -*- -.\" Copyright (C) 2014-2015 Sergey Poznyakoff +.\" Copyright (C) 2014-2016 Sergey Poznyakoff .\" .\" Varnish-mib is free software; you can redistribute it and/or modify .\" it under the terms of the GNU General Public License as published by .\" the Free Software Foundation; either version 3, or (at your option) .\" any later version. .\" @@ -10,13 +10,13 @@ .\" but WITHOUT ANY WARRANTY; without even the implied warranty of .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the .\" GNU General Public License for more details. .\" .\" You should have received a copy of the GNU General Public License .\" along with Varnish-mib. If not, see <http://www.gnu.org/licenses/>. -.TH VARNISH-MIB 8 "November 28, 2014" "varnish-mib" +.TH VARNISH-MIB 8 "April 27, 2016" "varnish-mib" .SH NAME varnish\-mib \- net-snmp module for obtaining Varnish Cache statistics .SH SYNOPSIS In \fBsnmpd.conf\fR(5): .PP .B dlmod varnish_mib /usr/lib/snmp/varnish\-mib.so @@ -24,21 +24,30 @@ In \fBsnmpd.conf\fR(5): Dynamically loadable object module for .B net-snmp that provides access to Varnish Cache statistics. The module is loaded into .BR snmpd (8) as shown above (actual path can of course differ, depending on how -the package was configured). +the package was configured). Varnish version \fB4.0\fR and \fB4.1\fR +are supported. +.PP +When using with \fBVarnish\fR version \fB4.1\fR, make sure the +\fB_.vsm\fR file is readable for \fBsnmpd\fR. This file is normally +located in \fB/var/lib/varnish/\fIHOSTNAME\fR and has mode \fB640\fR. +Its owner is determined by the \fB\-j\fR (\fB\-\-jail\fR) +\fBvarnishd\fR option. There are two ways to ensure it is readable: +either make sure \fBsnmpd\fR and \fBvarnishd\fR run with the same user +group, or use \fBsetfacl\fR(1) to tune access to that file. .PP The module obtains most of the data using Varnish API. Information about available bans (\fBbanTable\fR subtree) as well as the mechanism for setting bans (\fBclientBan\fR OID) are implemented via \fBvarnishd\fR administrative interface. For these to work, the module must have read access to Varnish secret file. In other words, the secret file -must be readable either by the user \fBsnmpd\fR runs as, or by one -of this user's groups. +must be readable either by the user \fBsnmpd\fR runs as, or by its +group. .SH CONFIGURATION OPTIONS Configuration statements specific to .B varnish\-mib must appear in the .B snmpd.conf file below the @@ -90,12 +99,23 @@ Number of hits for pass. A cache hit for pass indicates that Varnish passes the request to the backend and this decision itself has been cached. .TP .B clientCacheMisses Number of misses. A cache miss indicates the object was fetched from the backend before delivering it to the client. .TP +.B clientRequests400 +Client requests received, subject to 400 errors. +.TP +.B clientRequests411 +Client requests received, subject to 411 errors. This variable is +available only in Varnish version \fR4.0\fR. +.TP +.B clientRequests413 +Client requests received, subject to 413 errors. This variable is +available only in Varnish version \fR4.0\fR. +.TP .B clientBan A write-only OID. When set, invalidates the cache using the supplied value as argument to ban. When read, returns an empty string. E.g., to invalidate caches of all \fBpng\fR images: .EE @@ -125,13 +145,14 @@ whenever Varnish reuses a recycled connection. Number of backend connection recycles. This counter is increased whenever Varnish has keep-alive connection that is put back into the pool of connections. It has not yet been used, but it might be, unless the backend closes it. .TP .B backendConnUnused -Number of unused backend connections. +Number of unused backend connections. This variable is available only +in Varnish version \fR4.0\fR. .TP .B backendConnRetry Backend connections retried. .TP .B backendRequests Total backend requests made. @@ -234,13 +255,13 @@ Number of times session was queued waiting for a thread. Number of sessions dropped because session queue was full. .TP .B sessClosed Number of sessions closed. .TP .B sessPipeline -Session pipeline. +Session pipeline. This variable is available only in Varnish version \fR4.0\fR. .TP .B sessReadAhead Session read-ahead. .TP .B sessHerd Session herd. @@ -249,13 +270,14 @@ Session herd. Number of sessions dropped for thread. .TP .B sessFail Number of session accept failures. .TP .B sessPipeOverflow -Number of session pipe overflows. +Number of session pipe overflows. This variable is available only in +Varnish version \fR4.0\fR. .SS Branch \(dqthreads\(dq .TP .B threadsPools Number of thread pools. .TP .B threadsTotal @@ -354,13 +376,13 @@ implementation-specific management. It is not used currently. .BR varnishstat (1). .SH AUTHORS Sergey Poznyakoff .SH "BUG REPORTS" Report bugs to <gray@gnu.org>. .SH COPYRIGHT -Copyright \(co 2014 Sergey Poznyakoff +Copyright \(co 2014-2016 Sergey Poznyakoff .br .na License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> .br .ad This is free software: you are free to change and redistribute it. diff --git a/src/varnish_mib.mib2c b/src/varnish_mib.mib2c index a5367e0..9d49ce9 100644 --- a/src/varnish_mib.mib2c +++ b/src/varnish_mib.mib2c @@ -1,8 +1,8 @@ # This file is part of varnish-mib -*- c -*- -# Copyright (C) 2014-2015 Sergey Poznyakoff +# Copyright (C) 2014-2016 Sergey Poznyakoff # # Varnish-mib is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3, or (at your option) # any later version. # @@ -21,15 +21,13 @@ buffer-read-only: t End: vi: set ro: */ @enddefine@ @startperl@ -$vars{'varnish_translate'} = sub { - my $name = shift; - my %trans = ( +$vars{'varnish_translate_table'} = { uptime => [ 'MAIN', 'uptime' ], clientAcceptedConnections => [ 'MAIN', 'sess_conn' ], clientRequestsReceived => [ 'MAIN', 'client_req' ], clientCacheHits => [ 'MAIN', 'cache_hit' ], clientCacheHitsPass => [ 'MAIN', 'cache_hitpass' ], clientCacheMisses => [ 'MAIN', 'cache_miss' ], @@ -99,27 +97,37 @@ $vars{'varnish_translate'} = sub { bansLurkerObjKilled => [ 'MAIN', 'bans_lurker_obj_killed' ], bansDups => [ 'MAIN', 'bans_dups' ], bansLurkerContention => [ 'MAIN', 'bans_lurker_contention' ], bansPersistedBytes => [ 'MAIN', 'bans_persisted_bytes' ], bansPersistedFragmentation => [ 'MAIN', 'bans_persisted_fragmentation' ], - ); +}; + +$vars{'varnish_translate'} = sub { + my $name = shift; - my $r = $trans{$name}; + my $r = $vars{'varnish_translate_table'}->{$name}; if (!defined($r)) { print STDERR "no translation for $name!\n"; exit(1); } $vars{'varnish_type'} = $r->[0]; $vars{'varnish_member'} = $r->[1]; if ($#{$r} == 2) { @vars{keys %{$r->[2]}} = values %{$r->[2]}; } else { delete $vars{$setkw}; } + if ($vars{'varnish_type'} eq 'MAIN') { + $vars{'varnish_if'} = "#if HAVE_STRUCT_VSC_C_MAIN_" . uc($vars{'varnish_member'}); + $vars{'varnish_endif'} = '#endif'; + } else { + delete $vars{'varnish_if'}; + delete $vars{'varnish_endif'} + } return 0; }; %field_dim_tab = ( vbeIPv4 => 4, vbeIPv6 => 16 @@ -221,26 +229,26 @@ varnish_get_vsm_data() An instance handler only hands us one request at a time, unwrapping any eventual GETNEXT requests. */ @foreach $i scalar@ + @startperl@ + &{$vars{'varnish_translate'}}($vars{'i'}); + @endperl@ +$varnish_if static int handle_$i(netsnmp_mib_handler *handler, netsnmp_handler_registration *reginfo, netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { @if $i.settable@ int ret; @end@ - @startperl@ - &{$vars{'varnish_translate'}}($vars{'i'}); - @endperl@ - if (!varnish_get_vsm_data()) return SNMP_ERR_NOSUCHNAME; switch(reqinfo->mode) { case MODE_GET: @if $varnish_type eq 'MAIN'@ @@ -356,12 +364,13 @@ handle_$i(netsnmp_mib_handler *handler, snmp_log(LOG_ERR, "unknown mode (%d) in handle_${i}\n", reqinfo->mode ); return SNMP_ERR_GENERR; } return SNMP_ERR_NOERROR; } +$varnish_endif @end@ @foreach $i table@ ## Determine the first/last column names @eval $first_column = "-"@ @eval $last_column = "-"@ @@ -540,13 +549,18 @@ initialize_table_$i(void) /** Initializes the $name module */ void init_$modulename(void) { @foreach $i scalar@ + @startperl@ + &{$vars{'varnish_translate'}}($vars{'i'}); + @endperl@ +$varnish_if const oid ${i}_oid[] = { $i.commaoid }; +$varnish_endif @end@ DEBUGMSGTL(("$modulename", "Initializing\n")); if (!register_config_handler("snmpd", "varnishBanTableTimeout", varnish_ban_table_timeout_parser, @@ -564,22 +578,27 @@ init_$modulename(void) varnish_vcli_timeout_parser, NULL, "varnishCLIPortTimeout SECONDS")) snmp_log(LOG_ERR,"can't register config handler\n"); @foreach $i scalar@ + @startperl@ + &{$vars{'varnish_translate'}}($vars{'i'}); + @endperl@ +$varnish_if netsnmp_register_scalar( netsnmp_create_handler_registration("$i", handle_$i, ${i}_oid, OID_LENGTH(${i}_oid), @if !$i.settable@ HANDLER_CAN_RONLY @end@ @if $i.settable@ HANDLER_CAN_RWRITE @end@ )); +$varnish_endif @end@ @foreach $i table@ initialize_table_$i(); @end@ varnish_snmp_init(); } @@ -436,13 +436,13 @@ vcli_connect(struct VSM_data *vd, struct vcli_conn *conn) memset(conn, 0, sizeof(*conn)); if (!VSM_Get(vd, &vt, "Arg", "-T", "")) { snmp_log(LOG_ERR, "no -T arg in shared memory\n"); return SNMP_ERR_GENERR; } - DEBUGMSGTL(("varnish_mib:vcli", "-T '%s'\n", vt.b)); + DEBUGMSGTL(("varnish_mib:vcli", "-T '%s'\n", (char*) vt.b)); s = strdup(vt.b); if (!s) { snmp_log(LOG_ERR, "out of memory\n"); return SNMP_ERR_GENERR; } @@ -486,13 +486,13 @@ vcli_connect(struct VSM_data *vd, struct vcli_conn *conn) return SNMP_ERR_GENERR; if (!VSM_Get(vd, &vt, "Arg", "-S", "")) { snmp_log(LOG_ERR, "no -S arg in shared memory\n"); return SNMP_ERR_GENERR; } - DEBUGMSGTL(("varnish_mib:vcli", "-S '%s'\n", vt.b)); + DEBUGMSGTL(("varnish_mib:vcli", "-S '%s'\n", (char*) vt.b)); s = strdup(vt.b); if (!s) { snmp_log(LOG_ERR, "out of memory\n"); return SNMP_ERR_GENERR; } conn->secret = s; |