Add collectd-unbound dated 20150830, a collectd plugin to handle
the output from "unbound-control stats". Based on the code from https://github.com/falzm/collectd-unbound but chenaged from requiring unbound be configured with statistics-cumulative: no to instead requiring statistics-cumulative: yes ...and we want all the stats to be collected, and some of those are counters and some are gauges.
This commit is contained in:
parent
4a1c0c406d
commit
9b0b879ea1
15
collectd-unbound/DESCR
Normal file
15
collectd-unbound/DESCR
Normal file
|
@ -0,0 +1,15 @@
|
|||
This utility allows you to access Unbound statistics from collectd
|
||||
using the exec plugin. It hasn't been thoroughly tested, use it at
|
||||
your own risk...
|
||||
|
||||
Once the collectd-unbound binary is compiled, copy it wherever you
|
||||
want and add the following lines to you collectd configuration:
|
||||
|
||||
LoadPlugin exec
|
||||
<Plugin "exec">
|
||||
Exec "unbound" "/usr/pkg/bin/collectd-unbound"
|
||||
</Plugin>
|
||||
|
||||
Note: the utility executes the command unbound-control stats to
|
||||
fetch the statistics: make sure the user specified in your exec
|
||||
plugin block has the permissions to execute the command.
|
24
collectd-unbound/Makefile
Normal file
24
collectd-unbound/Makefile
Normal file
|
@ -0,0 +1,24 @@
|
|||
# $NetBSD$
|
||||
#
|
||||
|
||||
DISTNAME= collectd-unbound
|
||||
PKGNAME= ${DISTNAME}-20150830
|
||||
CATEGORIES= sysutils
|
||||
MASTER_SITES= ${MASTER_SITE_GITHUB:=falzm/}
|
||||
GITHUB_PROJECT= ${DISTNAME}
|
||||
GITHUB_TAG= e751f86301
|
||||
|
||||
MAINTAINER= pkgsrc-users@NetBSD.org
|
||||
HOMEPAGE= https://github.com/falzm/collectd-unbound
|
||||
COMMENT= Collectd plugin for submitting unbound statistics
|
||||
LICENSE= modified-bsd
|
||||
|
||||
GO_SRCPATH= github.com/falzm/collectd-unbound
|
||||
GO_DIST_BASE= ${DISTNAME}-${GITHUB_TAG}*
|
||||
|
||||
DEPENDS+= go-collectd-[0-9]*:../../sysutils/go-collectd
|
||||
DEPENDS+= collectd-[0-9]*:../../sysutils/collectd
|
||||
|
||||
.include "../../sysutils/go-collectd/buildlink3.mk"
|
||||
.include "../../lang/go/go-package.mk"
|
||||
.include "../../mk/bsd.pkg.mk"
|
2
collectd-unbound/PLIST
Normal file
2
collectd-unbound/PLIST
Normal file
|
@ -0,0 +1,2 @@
|
|||
@comment $NetBSD$
|
||||
bin/collectd-unbound
|
6
collectd-unbound/distinfo
Normal file
6
collectd-unbound/distinfo
Normal file
|
@ -0,0 +1,6 @@
|
|||
$NetBSD$
|
||||
|
||||
SHA1 (collectd-unbound-e751f86301.tar.gz) = 5de9eb486314f28f789f79fb69fa464409ea1ce1
|
||||
RMD160 (collectd-unbound-e751f86301.tar.gz) = ecb3b6e4e858de57c7913dba3617bf468611ddf1
|
||||
Size (collectd-unbound-e751f86301.tar.gz) = 2639 bytes
|
||||
SHA1 (patch-collectd-unbound.go) = 8c9b7aee55b78897fe49bdec46a28020ee409071
|
64
collectd-unbound/patches/patch-collectd-unbound.go
Normal file
64
collectd-unbound/patches/patch-collectd-unbound.go
Normal file
|
@ -0,0 +1,64 @@
|
|||
$NetBSD$
|
||||
|
||||
Change from requiring unbound be configured with
|
||||
|
||||
statistics-cumulative: no
|
||||
|
||||
to instead requiring
|
||||
|
||||
statistics-cumulative: yes
|
||||
|
||||
...and we want all the stats to be collected, and some
|
||||
of those are counters and some are gauges.
|
||||
|
||||
--- collectd-unbound.go.orig 2015-03-21 07:56:41.000000000 +0000
|
||||
+++ collectd-unbound.go
|
||||
@@ -33,7 +33,8 @@ func unboundStats(interval time.Duration
|
||||
scanner := bufio.NewScanner(buf)
|
||||
for scanner.Scan() {
|
||||
line := scanner.Text()
|
||||
- if !strings.HasPrefix(line, "total.") {
|
||||
+ // Skip per-thread statistics:
|
||||
+ if strings.HasPrefix(line, "thread") {
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -43,7 +44,6 @@ func unboundStats(interval time.Duration
|
||||
}
|
||||
|
||||
metric := fields[0]
|
||||
- metric = strings.TrimPrefix(metric, "total.")
|
||||
metric = strings.Replace(metric, ".", "_", -1)
|
||||
|
||||
value, err := strconv.ParseFloat(fields[1], 64)
|
||||
@@ -51,19 +51,28 @@ func unboundStats(interval time.Duration
|
||||
log.Printf("error: unable to parse metric value: %v", err)
|
||||
continue
|
||||
}
|
||||
+ vartype := "counter"
|
||||
+ if strings.Contains(fields[1], ".") {
|
||||
+ vartype = "gauge"
|
||||
+ }
|
||||
+ if strings.HasPrefix(metric, "total_requestlist") {
|
||||
+ vartype = "gauge"
|
||||
+ }
|
||||
+ if strings.HasPrefix(metric, "total_recursion") {
|
||||
+ vartype = "gauge"
|
||||
+ }
|
||||
|
||||
vl := api.ValueList{
|
||||
Identifier: api.Identifier{
|
||||
Host: exec.Hostname(),
|
||||
Plugin: "unbound",
|
||||
- Type: "gauge",
|
||||
+ Type: vartype,
|
||||
TypeInstance: metric,
|
||||
},
|
||||
Time: now,
|
||||
Interval: interval,
|
||||
Values: []api.Value{api.Gauge(value)},
|
||||
}
|
||||
-
|
||||
exec.Putval.Write(vl)
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue