TrueNas/telegraf

From r00tedvw.com wiki
(Difference between revisions)
Jump to: navigation, search
(Created page with "=Overview= reference: [https://blog.victormendonca.com/2020/10/28/how-to-install-telegraf-on-freenas/ https://blog.victormendonca.com/2020/10/28/how-to-install-telegraf-on-fre...")
 
(TrueNAS telegraf setup)
Line 16: Line 16:
 
Create the directory your files will live in.  I chose <code>/usr/local/telegraf-[version]_freebsd_amd64</code> because <code>/usr/local/</code> is the closest thing to <code>/opt/</code> in freebsd
 
Create the directory your files will live in.  I chose <code>/usr/local/telegraf-[version]_freebsd_amd64</code> because <code>/usr/local/</code> is the closest thing to <code>/opt/</code> in freebsd
 
  <nowiki>~$ sudo mkdir /usr/local/telegraf-[version]_freebsd_amd64
 
  <nowiki>~$ sudo mkdir /usr/local/telegraf-[version]_freebsd_amd64
~$ cp /tmp/telegraf* /usr/local/telegraf-[version]_freebsd_amd64
+
~$ cp /tmp/telegraf* /usr/local/telegraf-[version]_freebsd_amd64</nowiki>
  
 
==Create the init script==
 
==Create the init script==

Revision as of 23:54, 10 September 2022

Contents

Overview

reference: https://blog.victormendonca.com/2020/10/28/how-to-install-telegraf-on-freenas/
Setup and configure telegraf for TrueNAS (and probably any other FreeBSD OS)

Download and extract telegraf tar.gz

Find the latest telegraf release here
https://github.com/influxdata/telegraf/releases
Download and extract it on a vm with GNUtar (ubuntu, centos, etc) as tar included with FreeBSD will not unpack it.

Copy files over

You only need (2) files, the binary and conf file. Copy them over to TrueNAS.

~$ ./telegraf-[version]/usr/bin/telegraf
./telegraf-[version]/etc/telegraf/telegraf.conf

TrueNAS telegraf setup

Create the directory your files will live in. I chose /usr/local/telegraf-[version]_freebsd_amd64 because /usr/local/ is the closest thing to /opt/ in freebsd

~$ sudo mkdir /usr/local/telegraf-[version]_freebsd_amd64
~$ cp /tmp/telegraf* /usr/local/telegraf-[version]_freebsd_amd64

Create the init script

Modify the telegraf conf and bin dir vars.

~$ sudo vim /usr/local/telegraf-1.23.4_freebsd_amd64/telegraf.init
#!/bin/sh
# $FreeBSD$

# PROVIDE: telegraf
# REQUIRE: DAEMON NETWORKING
# BEFORE: LOGIN
# KEYWORD: shutdown

# Add the following lines to /etc/rc.conf to enable telegrafb:
# telegraf_enable="YES"
#
# telegraf_enable (bool): Set to YES to enable telegraf
# Default: NO
# telegraf_conf (str): telegraf configuration file
# Default: ${PREFIX}/etc/telegraf.conf
# telegraf_flags (str): Extra flags passed to telegraf

. /etc/rc.subr

name="telegraf"
rcvar=telegraf_enable

load_rc_config "${name}"
: ${telegraf_enable:="YES"}
: ${telegraf_flags:="-quiet"}
: ${telegraf_conf:="/usr/local/telegraf-1.23.4_freebsd_amd64/telegraf.conf"}
: ${telegraf_bindir:="/usr/local/telegraf-1.23.4_freebsd_amd64"}

pidfile="/var/run/${name}.pid"
command=/usr/sbin/daemon
command_args="-crP ${pidfile} ${telegraf_bindir}/${name} ${telegraf_flags} -config=${telegraf_conf}"

telegraf_prestart() {
# Have to empty rc_flags so they don't get passed to daemon(8)
  touch $pidfile
  rc_flags=""
}

telegraf_start() {
  ${command} ${command_args} ${rc_arg} >> /var/log/telegraf.log 2>&1
}

start_precmd="${name}_prestart"
start_cmd="${name}_start"

run_rc_command "$1"

Final steps

create a symlink for telegraf.init

~ ln -s /usr/local/telegraf-1.23.4_freebsd_amd64/telegraf.init /usr/local/etc/rc.d/telegraf

test the service

~$ service telegraf start
Personal tools
Namespaces

Variants
Actions
Navigation
Mediawiki
Confluence
DevOps Tools
Ubuntu
Ubuntu 22
Mac OSX
Oracle Linux
AWS
Windows
OpenVPN
Grafana
InfluxDB2
TrueNas
OwnCloud
Pivotal
osTicket
OTRS
phpBB
WordPress
VmWare ESXI 5.1
Crypto currencies
HTML
CSS
Python
Java Script
PHP
Raspberry Pi
Canvas LMS
Kaltura Media Server
Plex Media Server
MetaSploit
Zoneminder
ShinobiCE
Photoshop CS2
Fortinet
Uploaded
Certifications
General Info
Games
Meal Plans
NC Statutes
2020 Election
Volkswagen
Covid
NCDMV
Toolbox