summaryrefslogtreecommitdiffabout
authorSergey Poznyakoff <gray@gnu.org.ua>2016-04-27 11:26:04 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2016-04-27 12:02:18 (GMT)
commit94973146c58df26b20e17e2e5b1274216ca88969 (patch) (unidiff)
tree17538cc2991af0acec5bebfe6a826ef67cd9fc95
parent319c154c46214fdc5d8f8b498ae5a23bc8d03072 (diff)
downloadvarnish-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.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--NEWS11
-rwxr-xr-xbootstrap84
-rw-r--r--configure.ac20
-rw-r--r--src/betab.c8
-rw-r--r--src/varnish-mib.840
-rw-r--r--src/varnish_mib.mib2c39
-rw-r--r--src/vcli.c4
7 files changed, 172 insertions, 34 deletions
diff --git a/NEWS b/NEWS
index cb6b102..f12c539 100644
--- a/NEWS
+++ b/NEWS
@@ -1,9 +1,14 @@
1Varnish-mib NEWS -- history of user-visible changes. 2015-02-25 1Varnish-mib NEWS -- history of user-visible changes. 2016-04-27
2Copyright (C) 2014-2015 Sergey Poznyakoff 2Copyright (C) 2014-2016 Sergey Poznyakoff
3See the end of file for copying conditions. 3See the end of file for copying conditions.
4 4
5Please send Varnish-mib bug reports to <gray@gnu.org> 5Please send Varnish-mib bug reports to <gray@gnu.org>
6 6
7Version 1.1.90 (Git)
8
9* Support for Varnish 4.1
10
11
7Version 1.1, 2015-02-25 12Version 1.1, 2015-02-25
8 13
9* Don't exit if unable to open Varnish memory file 14* Don't exit if unable to open Varnish memory file
@@ -16,7 +21,7 @@ Initial release.
16 21
17* Copyright information: 22* Copyright information:
18 23
19Copyright (C) 2014-2015 Sergey Poznyakoff 24Copyright (C) 2014-2016 Sergey Poznyakoff
20 25
21 Permission is granted to anyone to make or distribute verbatim copies 26 Permission is granted to anyone to make or distribute verbatim copies
22 of this document as received, in any medium, provided that the 27 of this document as received, in any medium, provided that the
diff --git a/bootstrap b/bootstrap
index c55c2b2..25bc72e 100755
--- a/bootstrap
+++ b/bootstrap
@@ -1,7 +1,77 @@
1#!/bin/sh 1#!/usr/bin/perl
2for dir in m4 build-aux 2use strict;
3do 3use autodie;
4 test -d $dir || mkdir $dir 4
5done 5my $mib2c_config = 'src/varnish_mib.mib2c';
6> ChangeLog 6
7autoreconf -f -i -s 7die "This file must be run from the varnish-mib top level source directory"
8 unless -r $mib2c_config;
9
10print "$0: creating ancillary directories and files\n";
11foreach my $dir ('m4', 'build-aux') {
12 mkdir($dir) unless -d $dir;
13}
14
15unless (-f 'ChangeLog') {
16 open(my $fd, '>', 'ChangeLog');
17 print $fd <<EOT
18This file is a placeholder. It will be filled with actual data by the first
19run of make.
20EOT
21;
22 close $fd;
23}
24
25print "$0: generating m4/varnish_mib.m4\n";
26open(my $fd, '<', $mib2c_config);
27my $prog;
28while (<$fd>) {
29 if (defined($prog)) {
30 last if /^\@endperl\@/;
31 $prog .= $_;
32 } else {
33 if (/^\@startperl\@/) {
34 $prog = "no strict \"vars\";\n";
35 }
36 }
37}
38
39my %vars;
40eval $prog;
41die $@ if $@;
42die "$mib2c_config does not declare translation table"
43 unless exists $vars{'varnish_translate_table'};
44
45open(my $fd, '>', 'm4/varnish_mib.m4');
46print $fd <<'EOT';
47AC_DEFUN([AC_CHECK_VSC_C_MAIN_MEMBERS],
48[save_CFLAGS="$CFLAGS"
49CFLAGS="$CFLAGS $VARNISHAPI_CFLAGS"
50EOT
51;
52
53foreach my $member (sort
54 map { $_->[1] }
55 grep { $_->[0] eq 'MAIN' }
56 values %{$vars{'varnish_translate_table'}}) {
57 print $fd <<EOT
58 AC_CHECK_MEMBERS([struct VSC_C_main.$member],,,
59[#include <stddef.h>
60#include <stdlib.h>
61#include <stdint.h>
62#include <limits.h>
63#include <vapi/vsc.h>
64#include <vapi/vsm.h>
65#include <vcli.h>])
66EOT
67;
68}
69print $fd <<'EOT'
70CFLAGS="$save_CFLAGS"
71])
72EOT
73;
74close $fd;
75
76print "$0: reconfiguring\n";
77exec('autoreconf -f -i -s');
diff --git a/configure.ac b/configure.ac
index d571518..cf0bf05 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,5 +1,5 @@
1# This file is part of Varnish-mib -*- autoconf -*- 1# This file is part of Varnish-mib -*- autoconf -*-
2# Copyright (C) 2014-2015 Sergey Poznyakoff 2# Copyright (C) 2014-2016 Sergey Poznyakoff
3# 3#
4# Varnish-mib is free software; you can redistribute it and/or modify 4# Varnish-mib is free software; you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by 5# it under the terms of the GNU General Public License as published by
@@ -15,7 +15,7 @@
15# along with Varnish-mib. If not, see <http://www.gnu.org/licenses/>. 15# along with Varnish-mib. If not, see <http://www.gnu.org/licenses/>.
16 16
17AC_PREREQ(2.69) 17AC_PREREQ(2.69)
18AC_INIT([varnish-mib], 1.1, [gray@gnu.org]) 18AC_INIT([varnish-mib], 1.1.90, [gray@gnu.org])
19AC_CONFIG_SRCDIR(src/varnish_mib.mib2c) 19AC_CONFIG_SRCDIR(src/varnish_mib.mib2c)
20AM_CONFIG_HEADER(config.h) 20AM_CONFIG_HEADER(config.h)
21AC_CONFIG_AUX_DIR([build-aux]) 21AC_CONFIG_AUX_DIR([build-aux])
@@ -43,6 +43,22 @@ PKG_PROG_PKG_CONFIG
43# Checks for Varnish 43# Checks for Varnish
44PKG_CHECK_MODULES([VARNISHAPI], [varnishapi >= 4.0]) 44PKG_CHECK_MODULES([VARNISHAPI], [varnishapi >= 4.0])
45 45
46varnishapi_version() {
47 AC_DEFINE_UNQUOTED([VARNISHAPI_MAJOR],[$1],[Varnish API major version number])
48 AC_DEFINE_UNQUOTED([VARNISHAPI_MINOR],[$2],[Varnish API minor version number])
49 AC_DEFINE_UNQUOTED([VARNISHAPI_PATCH],[$3],[Varnish API patchlevel])
50}
51
52v=$($PKG_CONFIG --modversion varnishapi)
53if test -n "$v"; then
54 save_IFS=$IFS
55 IFS='.'
56 varnishapi_version $v
57 IFS=$save_IFS
58fi
59
60AC_CHECK_VSC_C_MAIN_MEMBERS
61
46# Check for Net-SNMP 62# Check for Net-SNMP
47AC_PATH_PROG([NET_SNMP_CONFIG], net-snmp-config, none, $PATH) 63AC_PATH_PROG([NET_SNMP_CONFIG], net-snmp-config, none, $PATH)
48if test "$NET_SNMP_CONFIG" = "none"; then 64if test "$NET_SNMP_CONFIG" = "none"; then
diff --git a/src/betab.c b/src/betab.c
index b583958..49e02f7 100644
--- a/src/betab.c
+++ b/src/betab.c
@@ -59,7 +59,13 @@ create_entry(netsnmp_tdata *table_data, long idx,
59#define VSC_POINT_TYPE(p) ((p)->section->fantom->type) 59#define VSC_POINT_TYPE(p) ((p)->section->fantom->type)
60#define VSC_POINT_IDENT(p) ((p)->section->fantom->ident) 60#define VSC_POINT_IDENT(p) ((p)->section->fantom->ident)
61#define VSC_POINT_NAME(p) ((p)->desc->name) 61#define VSC_POINT_NAME(p) ((p)->desc->name)
62#define VSC_POINT_FMT(p) ((p)->desc->fmt) 62#if VARNISHAPI_MINOR == 0
63# define VSC_POINT_FMT(p) ((p)->desc->fmt)
64#elif VARNISHAPI_MINOR == 1
65# define VSC_POINT_FMT(p) ((p)->desc->ctype)
66#else
67# error "unsupported Varnish API minor number"
68#endif
63 69
64struct betab_priv { 70struct betab_priv {
65 int err; 71 int err;
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,5 +1,5 @@
1.\" This file is part of Varnish-mib -*- nroff -*- 1.\" This file is part of Varnish-mib -*- nroff -*-
2.\" Copyright (C) 2014-2015 Sergey Poznyakoff 2.\" Copyright (C) 2014-2016 Sergey Poznyakoff
3.\" 3.\"
4.\" Varnish-mib is free software; you can redistribute it and/or modify 4.\" Varnish-mib is free software; you can redistribute it and/or modify
5.\" it under the terms of the GNU General Public License as published by 5.\" it under the terms of the GNU General Public License as published by
@@ -13,7 +13,7 @@
13.\" 13.\"
14.\" You should have received a copy of the GNU General Public License 14.\" You should have received a copy of the GNU General Public License
15.\" along with Varnish-mib. If not, see <http://www.gnu.org/licenses/>. 15.\" along with Varnish-mib. If not, see <http://www.gnu.org/licenses/>.
16.TH VARNISH-MIB 8 "November 28, 2014" "varnish-mib" 16.TH VARNISH-MIB 8 "April 27, 2016" "varnish-mib"
17.SH NAME 17.SH NAME
18varnish\-mib \- net-snmp module for obtaining Varnish Cache statistics 18varnish\-mib \- net-snmp module for obtaining Varnish Cache statistics
19.SH SYNOPSIS 19.SH SYNOPSIS
@@ -27,15 +27,24 @@ that provides access to Varnish Cache statistics. The module is
27loaded into 27loaded into
28.BR snmpd (8) 28.BR snmpd (8)
29as shown above (actual path can of course differ, depending on how 29as shown above (actual path can of course differ, depending on how
30the package was configured). 30the package was configured). Varnish version \fB4.0\fR and \fB4.1\fR
31are supported.
32.PP
33When using with \fBVarnish\fR version \fB4.1\fR, make sure the
34\fB_.vsm\fR file is readable for \fBsnmpd\fR. This file is normally
35located in \fB/var/lib/varnish/\fIHOSTNAME\fR and has mode \fB640\fR.
36Its owner is determined by the \fB\-j\fR (\fB\-\-jail\fR)
37\fBvarnishd\fR option. There are two ways to ensure it is readable:
38either make sure \fBsnmpd\fR and \fBvarnishd\fR run with the same user
39group, or use \fBsetfacl\fR(1) to tune access to that file.
31.PP 40.PP
32The module obtains most of the data using Varnish API. Information 41The module obtains most of the data using Varnish API. Information
33about available bans (\fBbanTable\fR subtree) as well as the mechanism 42about available bans (\fBbanTable\fR subtree) as well as the mechanism
34for setting bans (\fBclientBan\fR OID) are implemented via \fBvarnishd\fR 43for setting bans (\fBclientBan\fR OID) are implemented via \fBvarnishd\fR
35administrative interface. For these to work, the module must have 44administrative interface. For these to work, the module must have
36read access to Varnish secret file. In other words, the secret file 45read access to Varnish secret file. In other words, the secret file
37must be readable either by the user \fBsnmpd\fR runs as, or by one 46must be readable either by the user \fBsnmpd\fR runs as, or by its
38of this user's groups. 47group.
39.SH CONFIGURATION OPTIONS 48.SH CONFIGURATION OPTIONS
40Configuration statements specific to 49Configuration statements specific to
41.B varnish\-mib 50.B varnish\-mib
@@ -93,6 +102,17 @@ passes the request to the backend and this decision itself has been cached.
93Number of misses. A cache miss indicates the object was fetched from 102Number of misses. A cache miss indicates the object was fetched from
94the backend before delivering it to the client. 103the backend before delivering it to the client.
95.TP 104.TP
105.B clientRequests400
106Client requests received, subject to 400 errors.
107.TP
108.B clientRequests411
109Client requests received, subject to 411 errors. This variable is
110available only in Varnish version \fR4.0\fR.
111.TP
112.B clientRequests413
113Client requests received, subject to 413 errors. This variable is
114available only in Varnish version \fR4.0\fR.
115.TP
96.B clientBan 116.B clientBan
97A write-only OID. When set, invalidates the cache using the supplied 117A write-only OID. When set, invalidates the cache using the supplied
98value as argument to ban. When read, returns an empty string. E.g., 118value as argument to ban. When read, returns an empty string. E.g.,
@@ -128,7 +148,8 @@ the pool of connections. It has not yet been used, but it might be,
128unless the backend closes it. 148unless the backend closes it.
129.TP 149.TP
130.B backendConnUnused 150.B backendConnUnused
131Number of unused backend connections. 151Number of unused backend connections. This variable is available only
152in Varnish version \fR4.0\fR.
132.TP 153.TP
133.B backendConnRetry 154.B backendConnRetry
134Backend connections retried. 155Backend connections retried.
@@ -237,7 +258,7 @@ Number of sessions dropped because session queue was full.
237Number of sessions closed. 258Number of sessions closed.
238.TP 259.TP
239.B sessPipeline 260.B sessPipeline
240Session pipeline. 261Session pipeline. This variable is available only in Varnish version \fR4.0\fR.
241.TP 262.TP
242.B sessReadAhead 263.B sessReadAhead
243Session read-ahead. 264Session read-ahead.
@@ -252,7 +273,8 @@ Number of sessions dropped for thread.
252Number of session accept failures. 273Number of session accept failures.
253.TP 274.TP
254.B sessPipeOverflow 275.B sessPipeOverflow
255Number of session pipe overflows. 276Number of session pipe overflows. This variable is available only in
277Varnish version \fR4.0\fR.
256.SS Branch \(dqthreads\(dq 278.SS Branch \(dqthreads\(dq
257.TP 279.TP
258.B threadsPools 280.B threadsPools
@@ -357,7 +379,7 @@ Sergey Poznyakoff
357.SH "BUG REPORTS" 379.SH "BUG REPORTS"
358Report bugs to <gray@gnu.org>. 380Report bugs to <gray@gnu.org>.
359.SH COPYRIGHT 381.SH COPYRIGHT
360Copyright \(co 2014 Sergey Poznyakoff 382Copyright \(co 2014-2016 Sergey Poznyakoff
361.br 383.br
362.na 384.na
363License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> 385License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
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,5 +1,5 @@
1# This file is part of varnish-mib -*- c -*- 1# This file is part of varnish-mib -*- c -*-
2# Copyright (C) 2014-2015 Sergey Poznyakoff 2# Copyright (C) 2014-2016 Sergey Poznyakoff
3# 3#
4# Varnish-mib is free software; you can redistribute it and/or modify 4# Varnish-mib is free software; you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by 5# it under the terms of the GNU General Public License as published by
@@ -24,9 +24,7 @@
24*/ 24*/
25@enddefine@ 25@enddefine@
26@startperl@ 26@startperl@
27$vars{'varnish_translate'} = sub { 27$vars{'varnish_translate_table'} = {
28 my $name = shift;
29 my %trans = (
30 uptime => [ 'MAIN', 'uptime' ], 28 uptime => [ 'MAIN', 'uptime' ],
31 clientAcceptedConnections => [ 'MAIN', 'sess_conn' ], 29 clientAcceptedConnections => [ 'MAIN', 'sess_conn' ],
32 clientRequestsReceived => [ 'MAIN', 'client_req' ], 30 clientRequestsReceived => [ 'MAIN', 'client_req' ],
@@ -102,9 +100,12 @@ $vars{'varnish_translate'} = sub {
102 bansPersistedBytes => [ 'MAIN', 'bans_persisted_bytes' ], 100 bansPersistedBytes => [ 'MAIN', 'bans_persisted_bytes' ],
103 bansPersistedFragmentation => [ 'MAIN', 'bans_persisted_fragmentation' ], 101 bansPersistedFragmentation => [ 'MAIN', 'bans_persisted_fragmentation' ],
104 102
105 ); 103};
104
105$vars{'varnish_translate'} = sub {
106 my $name = shift;
106 107
107 my $r = $trans{$name}; 108 my $r = $vars{'varnish_translate_table'}->{$name};
108 if (!defined($r)) { 109 if (!defined($r)) {
109 print STDERR "no translation for $name!\n"; 110 print STDERR "no translation for $name!\n";
110 exit(1); 111 exit(1);
@@ -117,6 +118,13 @@ $vars{'varnish_translate'} = sub {
117 } else { 118 } else {
118 delete $vars{$setkw}; 119 delete $vars{$setkw};
119 } 120 }
121 if ($vars{'varnish_type'} eq 'MAIN') {
122 $vars{'varnish_if'} = "#if HAVE_STRUCT_VSC_C_MAIN_" . uc($vars{'varnish_member'});
123 $vars{'varnish_endif'} = '#endif';
124 } else {
125 delete $vars{'varnish_if'};
126 delete $vars{'varnish_endif'}
127 }
120 return 0; 128 return 0;
121}; 129};
122 130
@@ -224,6 +232,10 @@ varnish_get_vsm_data()
224*/ 232*/
225 233
226@foreach $i scalar@ 234@foreach $i scalar@
235 @startperl@
236 &{$vars{'varnish_translate'}}($vars{'i'});
237 @endperl@
238$varnish_if
227static int 239static int
228handle_$i(netsnmp_mib_handler *handler, 240handle_$i(netsnmp_mib_handler *handler,
229 netsnmp_handler_registration *reginfo, 241 netsnmp_handler_registration *reginfo,
@@ -234,10 +246,6 @@ handle_$i(netsnmp_mib_handler *handler,
234 int ret; 246 int ret;
235 @end@ 247 @end@
236 248
237 @startperl@
238 &{$vars{'varnish_translate'}}($vars{'i'});
239 @endperl@
240
241 if (!varnish_get_vsm_data()) 249 if (!varnish_get_vsm_data())
242 return SNMP_ERR_NOSUCHNAME; 250 return SNMP_ERR_NOSUCHNAME;
243 251
@@ -359,6 +367,7 @@ handle_$i(netsnmp_mib_handler *handler,
359 367
360 return SNMP_ERR_NOERROR; 368 return SNMP_ERR_NOERROR;
361} 369}
370$varnish_endif
362@end@ 371@end@
363 372
364@foreach $i table@ 373@foreach $i table@
@@ -543,7 +552,12 @@ void
543init_$modulename(void) 552init_$modulename(void)
544{ 553{
545 @foreach $i scalar@ 554 @foreach $i scalar@
555 @startperl@
556 &{$vars{'varnish_translate'}}($vars{'i'});
557 @endperl@
558$varnish_if
546 const oid ${i}_oid[] = { $i.commaoid }; 559 const oid ${i}_oid[] = { $i.commaoid };
560$varnish_endif
547 @end@ 561 @end@
548 562
549 DEBUGMSGTL(("$modulename", "Initializing\n")); 563 DEBUGMSGTL(("$modulename", "Initializing\n"));
@@ -567,6 +581,10 @@ init_$modulename(void)
567 snmp_log(LOG_ERR,"can't register config handler\n"); 581 snmp_log(LOG_ERR,"can't register config handler\n");
568 582
569 @foreach $i scalar@ 583 @foreach $i scalar@
584 @startperl@
585 &{$vars{'varnish_translate'}}($vars{'i'});
586 @endperl@
587$varnish_if
570 netsnmp_register_scalar( 588 netsnmp_register_scalar(
571 netsnmp_create_handler_registration("$i", handle_$i, 589 netsnmp_create_handler_registration("$i", handle_$i,
572 ${i}_oid, OID_LENGTH(${i}_oid), 590 ${i}_oid, OID_LENGTH(${i}_oid),
@@ -577,6 +595,7 @@ init_$modulename(void)
577 HANDLER_CAN_RWRITE 595 HANDLER_CAN_RWRITE
578 @end@ 596 @end@
579 )); 597 ));
598$varnish_endif
580 @end@ 599 @end@
581 @foreach $i table@ 600 @foreach $i table@
582 initialize_table_$i(); 601 initialize_table_$i();
diff --git a/src/vcli.c b/src/vcli.c
index 736d9b3..c204cf3 100644
--- a/src/vcli.c
+++ b/src/vcli.c
@@ -439,7 +439,7 @@ vcli_connect(struct VSM_data *vd, struct vcli_conn *conn)
439 snmp_log(LOG_ERR, "no -T arg in shared memory\n"); 439 snmp_log(LOG_ERR, "no -T arg in shared memory\n");
440 return SNMP_ERR_GENERR; 440 return SNMP_ERR_GENERR;
441 } 441 }
442 DEBUGMSGTL(("varnish_mib:vcli", "-T '%s'\n", vt.b)); 442 DEBUGMSGTL(("varnish_mib:vcli", "-T '%s'\n", (char*) vt.b));
443 443
444 s = strdup(vt.b); 444 s = strdup(vt.b);
445 if (!s) { 445 if (!s) {
@@ -489,7 +489,7 @@ vcli_connect(struct VSM_data *vd, struct vcli_conn *conn)
489 snmp_log(LOG_ERR, "no -S arg in shared memory\n"); 489 snmp_log(LOG_ERR, "no -S arg in shared memory\n");
490 return SNMP_ERR_GENERR; 490 return SNMP_ERR_GENERR;
491 } 491 }
492 DEBUGMSGTL(("varnish_mib:vcli", "-S '%s'\n", vt.b)); 492 DEBUGMSGTL(("varnish_mib:vcli", "-S '%s'\n", (char*) vt.b));
493 s = strdup(vt.b); 493 s = strdup(vt.b);
494 if (!s) { 494 if (!s) {
495 snmp_log(LOG_ERR, "out of memory\n"); 495 snmp_log(LOG_ERR, "out of memory\n");

Return to:

Send suggestions and report system problems to the System administrator.