Running Telegraf on OpenBSD

I tried to run InfluxData Telegraf on OpenBSD 6.2 but it wasn’t available in the Ports nor was I able to compile a binary from sources. But the latter has changed since I have an OpenBSD 6.3 instance running. Here’s how to compile and run Telegraf on OpenBSD.

Get an OpenBSD 6.3/amd64. It may run on other architectures and versions.

Install the required dev tools:

# pkg_add gmake git go
gmake-4.2.1: ok
git-2.16.2: ok
go-1.10: ok

Setup the compile environnement:

# export GOPATH=~/go
# export PATH=$PATH:~/go/bin

Start building the Go dependency management tool:

# go get
# cd $GOPATH/src/
# go install ./...

Then build Telegraf itself:

# go get
# cd $GOPATH/src/
# gmake
dep ensure -vendor-only
go build -ldflags " -X main.commit=c7e2945a -X main.branch=master" ./cmd/telegraf

This will compile the master branch. One should be able to compile a stable branch using checkout and tags stuff from Git. I couldn’t, trying to build 1.7.4.

When the binary’s ready, simply install it:

# gmake install
go build -ldflags " -X main.commit=c7e2945a -X main.branch=master" ./cmd/telegraf
mkdir -p /usr/local/bin/
cp telegraf /usr/local/bin/

I’m using User and Class features of OpenBSD so that Telegraf doesn’t run as root:

# vim /etc/login.conf

# cap_mkdb /etc/login.conf
# groupadd -g xxxx _telegraf
# useradd -u xxxx -g xxxx -c "Telegraf agent" -d /var/telegraf -s /sbin/nologin -L telegraf _telegraf

The default configuration file will go in “/etc”:

# mkdir /etc/telegraf
# chown _telegraf:_telegraf /etc/telegraf
# chmod 0750 /etc/telegraf
# doas -u _telegraf telegraf config > /etc/telegraf/telegraf.conf

Finally, create an rc.d script for easy management:

# cat > /etc/rc.d/telegraf
# Start InfluxData Telegraf agent

daemon_flags="--config /etc/telegraf/telegraf.conf"

. /etc/rc.d/rc.subr


rc_pre() {
    /usr/bin/install -d -o _telegraf -g _telegraf -m 0750 /var/telegraf

rc_cmd $1

# chmod 0755 /etc/rc.d/telegraf
# chown root:wheel /etc/rc.d/telegraf

# rcctl enable telegraf
# rcctl start telegraf

There’s an issue with the rc_check() function when using “start” or “restart”. Couldn’t find why. According to “/etc/rc.d/rc.subr”, “(…) # XXX for unknown reason, rc_check can fail (…)”.

So far, Telegraf runs the Apache, MySQL, PHP-FPM and SNMP input filters and the InfluxDB output filter. And it doesn’t seem to use more resources than Collectd.

Leave a Reply

Your email address will not be published. Required fields are marked *


This site uses Akismet to reduce spam. Learn how your comment data is processed.