TrueNas/telegraf

From r00tedvw.com wiki
(Difference between revisions)
Jump to: navigation, search
(Final steps)
(TrueNAS telegraf setup)
Line 14: Line 14:
  
 
=TrueNAS telegraf setup=
 
=TrueNAS telegraf setup=
 +
==Create dir and copy files==
 
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</nowiki>
 
~$ cp /tmp/telegraf* /usr/local/telegraf-[version]_freebsd_amd64</nowiki>
 +
 +
==Modify telegraf.conf==
 +
update the conf file to use prometheus instead of influxdb
 +
<nowiki>~$ vim /tmp/telegraf-1.23.4_freebsd_amd64/etc/telegraf/telegraf.conf</nowiki>
 +
comment
 +
<nowiki># [[outputs.influxdb]]</nowiki>
 +
 +
uncomment
 +
<nowiki>[[outputs.prometheus_client]]
 +
  listen = ":9100"
 +
  path = "/metrics"</nowiki>
  
 
==Create the init script==
 
==Create the init script==

Revision as of 02:11, 11 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 dir and copy files

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

Modify telegraf.conf

update the conf file to use prometheus instead of influxdb

~$ vim /tmp/telegraf-1.23.4_freebsd_amd64/etc/telegraf/telegraf.conf

comment

# [[outputs.influxdb]]

uncomment

[[outputs.prometheus_client]]
  listen = ":9100"
  path = "/metrics"

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

make the init executable

~$ chmod +x /usr/local/telegraf-1.23.4_freebsd_amd64/telegraf.init

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

Add the following lines to /etc/rc.conf to enable telegrafb:

telegraf_enable="YES"
Personal tools
Namespaces

Variants
Actions
Navigation
Mediawiki
Confluence
DevOps Tools
Open Source Products
Ubuntu
Ubuntu 22
Mac OSX
Oracle Linux
AWS
Windows
OpenVPN
Grafana
InfluxDB2
TrueNas
MagicMirror
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
Politics
Volkswagen
Covid
NCDMV
Toolbox