Add sysutils/snmp_exporter, SNMP Exporter for Prometheus

PR:		226223
Submitted by:	Fabian Freyer <fabian.freyer@physik.tu-berlin.de>
Differential Revision:	https://reviews.freebsd.org/D14526
This commit is contained in:
Li-Wen Hsu 2018-02-27 19:57:56 +00:00
parent dd487071e8
commit b499b17096
Notes: svn2git 2021-03-31 03:12:20 +00:00
svn path=/head/; revision=463157
9 changed files with 160 additions and 0 deletions

View File

@ -1130,6 +1130,7 @@
SUBDIR += smenu
SUBDIR += smp_utils
SUBDIR += snap
SUBDIR += snmp_exporter
SUBDIR += snooze
SUBDIR += snowlog
SUBDIR += socket

View File

@ -0,0 +1,37 @@
# $FreeBSD$
PORTNAME= snmp_exporter
PORTVERSION= 0.9.0
DISTVERSIONPREFIX=v
CATEGORIES= sysutils
MAINTAINER= fabian.freyer@physik.tu-berlin.de
COMMENT= SNMP Exporter for Prometheus
LICENSE= APACHE20
LIB_DEPENDS= libnetsnmp.so:net-mgmt/net-snmp
USES= go
USE_GITHUB= yes
USE_RC_SUBR= snmp_exporter
GH_ACCOUNT= prometheus
GO_PKGNAME= github.com/${GH_ACCOUNT}/${PORTNAME}
GO_TARGET= github.com/${GH_ACCOUNT}/${PORTNAME}
do-build:
(cd ${GO_WRKSRC}; ${SETENV} ${MAKE_ENV} ${GO_ENV} ${GO_CMD} install -v ${GO_TARGET})
(cd ${GO_WRKSRC}/generator; ${SETENV} ${MAKE_ENV} ${GO_ENV} ${GO_CMD} install -v ${GO_TARGET}/generator)
post-patch:
@${REINPLACE_CMD} -e 's|/usr/local|${PREFIX}|g' ${GO_WRKSRC}/generator/main.go
do-install:
${MKDIR} ${STAGEDIR}${PREFIX}/etc/snmp_exporter/
${INSTALL_DATA} ${FILESDIR}/generator.yml ${STAGEDIR}${PREFIX}/etc/snmp_exporter/generator.yml
${INSTALL_PROGRAM} ${WRKDIR}/bin/snmp_exporter ${STAGEDIR}${PREFIX}/bin
${INSTALL_PROGRAM} ${WRKDIR}/bin/generator ${STAGEDIR}${PREFIX}/bin/snmp_exporter_generator
.include <bsd.port.mk>

View File

@ -0,0 +1,3 @@
TIMESTAMP = 1519669975
SHA256 (prometheus-snmp_exporter-v0.9.0_GH0.tar.gz) = ac508e8cda680cc46638c68fe71a91df012e3274fb99460fd2866637b51591fd
SIZE (prometheus-snmp_exporter-v0.9.0_GH0.tar.gz) = 3257207

View File

@ -0,0 +1,23 @@
modules:
# Default IF-MIB interfaces table with ifIndex.
if_mib:
walk: [sysUpTime, interfaces, ifXTable]
# Interfaces if ifAlias is unique.
if_mib_ifalias:
walk: [sysUpTime, interfaces, ifXTable]
lookups:
- old_index: ifIndex
new_index: ifAlias
# Interfaces if ifDescr is unique.
if_mib_ifdescr:
walk: [sysUpTime, interfaces, ifXTable]
lookups:
- old_index: ifIndex
new_index: ifDescr
# Interfaces if ifName is unique.
if_mib_ifname:
walk: [sysUpTime, interfaces, ifXTable]
lookups:
- old_index: ifIndex
# Use OID to avoid conflict with Netscaler NS-ROOT-MIB.
new_index: 1.3.6.1.2.1.31.1.1.1.1 # ifName

View File

@ -0,0 +1,20 @@
--- generator/main.go.orig 2018-02-26 16:03:57 UTC
+++ generator/main.go
@@ -21,7 +21,7 @@ func generateConfig(nodes *Node, nameToN
log.Fatal("Unable to determine absolute path for output")
}
- content, err := ioutil.ReadFile("generator.yml")
+ content, err := ioutil.ReadFile("/usr/local/etc/snmp_exporter/generator.yml")
if err != nil {
log.Fatalf("Error reading yml config: %s", err)
}
@@ -65,7 +65,7 @@ func generateConfig(nodes *Node, nameToN
var (
generateCommand = kingpin.Command("generate", "Generate snmp.yml from generator.yml")
- outputPath = generateCommand.Flag("output-path", "Path to to write resulting config file").Default("snmp.yml").Short('o').String()
+ outputPath = generateCommand.Flag("output-path", "Path to to write resulting config file").Default("/usr/local/etc/snmp_exporter/snmp.yml").Short('o').String()
parseErrorsCommand = kingpin.Command("parse_errors", "Debug: Print the parse errors output by NetSNMP")
dumpCommand = kingpin.Command("dump", "Debug: Dump the parsed and prepared MIBs")
)

View File

@ -0,0 +1,7 @@
To generate the snmp.yml configuration file for snmp_exporter,
edit %%ETCDIR%%/generator.yml and add relevant MIBs, then run
snmp_exporter_generator generate
To run snmp_exporter, set the snmp_exporter_enable="YES" rcvar
and point your prometheus instance at port 9116.

View File

@ -0,0 +1,61 @@
#!/bin/sh
# $FreeBSD$
# PROVIDE: snmp_exporter
# REQUIRE: LOGIN
# KEYWORD: shutdown
#
# Add the following lines to /etc/rc.conf.local or /etc/rc.conf
# to enable this service:
#
# snmp_exporter_enable (bool): Set to NO by default.
# Set it to YES to enable snmp_exporter.
# snmp_exporter_user (string): Set user that snmp_exporter will run under
# Default is "nobody".
# snmp_exporter_group (string): Set group that snmp_exporter will run under
# Default is "nobody".
# snmp_exporter_args (string): Set extra arguments to pass to snmp_exporter
# Default is "".
# snmp_exporter_listen_address (string):Set ip:port that snmp_exporter will listen on
# Default is ":9116".
# snmp_exporter_config_file (string) Set the location of the snmp_exporter config
# configuration file.
# Default is "%%PREFIX%%/etc/snmp_exporter/snmp.yml"
. /etc/rc.subr
name=snmp_exporter
rcvar=snmp_exporter_enable
load_rc_config $name
: ${snmp_exporter_enable:="NO"}
: ${snmp_exporter_user:="nobody"}
: ${snmp_exporter_group:="nobody"}
: ${snmp_exporter_args:=""}
: ${snmp_exporter_listen_address:=":9116"}
: ${snmp_exporter_config_file:="%%PREFIX%%/etc/snmp_exporter/snmp.yml"}
pidfile=/var/run/snmp_exporter.pid
command="/usr/sbin/daemon"
procname="%%PREFIX%%/bin/snmp_exporter"
command_args="-p ${pidfile} /usr/bin/env ${procname} \
--web.listen-address=${snmp_exporter_listen_address} \
--config.file=${snmp_exporter_config_file} \
${snmp_exporter_args}"
start_precmd=snmp_exporter_startprecmd
snmp_exporter_startprecmd()
{
if [ ! -e ${pidfile} ]; then
install -o ${snmp_exporter_user} -g ${snmp_exporter_group} /dev/null ${pidfile};
fi
if [ ! -d ${snmp_exporter_textfile_dir} ]; then
install -d -o ${snmp_exporter_user} -g ${snmp_exporter_group} -m 1755 ${snmp_exporter_textfile_dir}
fi
}
load_rc_config $name
run_rc_command "$1"

View File

@ -0,0 +1,5 @@
snmp_exporter is a prometheus exporter for information
gathered from SNMP for use by the Prometheus monitoring
system.
WWW: https://github.com/prometheus/snmp_exporter

View File

@ -0,0 +1,3 @@
bin/snmp_exporter
bin/snmp_exporter_generator
%%ETCDIR%%/generator.yml