TrueNas/telegraf
(→TrueNAS telegraf setup) |
|||
Line 3: | Line 3: | ||
Setup and configure telegraf for TrueNAS (and probably any other FreeBSD OS) | Setup and configure telegraf for TrueNAS (and probably any other FreeBSD OS) | ||
− | =Download and extract telegraf tar.gz= | + | =Dependencies= |
+ | ==Download and extract telegraf tar.gz== | ||
Find the latest telegraf release here<br> | Find the latest telegraf release here<br> | ||
[https://github.com/influxdata/telegraf/releases https://github.com/influxdata/telegraf/releases]<br> | [https://github.com/influxdata/telegraf/releases https://github.com/influxdata/telegraf/releases]<br> | ||
Download and extract it on a vm with GNUtar (ubuntu, centos, etc) as tar included with FreeBSD will not unpack it. | Download and extract it on a vm with GNUtar (ubuntu, centos, etc) as tar included with FreeBSD will not unpack it. | ||
− | =Copy files over= | + | ==Copy files over== |
You only need (2) files, the binary and conf file. Copy them over to TrueNAS. | You only need (2) files, the binary and conf file. Copy them over to TrueNAS. | ||
<nowiki>~$ ./telegraf-[version]/usr/bin/telegraf | <nowiki>~$ ./telegraf-[version]/usr/bin/telegraf | ||
Line 89: | Line 90: | ||
Add the following lines to /etc/rc.conf to enable telegrafb: | Add the following lines to /etc/rc.conf to enable telegrafb: | ||
<nowiki>telegraf_enable="YES"</nowiki> | <nowiki>telegraf_enable="YES"</nowiki> | ||
+ | |||
+ | ==Create post init startup task== | ||
+ | In the GUI go to:<br> | ||
+ | <code>Tasks > Init/Shutdown Scripts</code><br> | ||
+ | and create a Command type with the following: | ||
+ | <nowiki>ln -s /usr/local/telegraf-1.23.4_freebsd_amd64/telegraf.init /usr/local/etc/rc.d/telegraf; service telegraf start</nowiki> | ||
+ | Select <code>Post Init</code> and Enable it. |
Latest revision as of 21:39, 11 September 2022
Contents |
[edit] 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)
[edit] Dependencies
[edit] 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.
[edit] 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
[edit] TrueNAS telegraf setup
[edit] 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
[edit] 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"
[edit] 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"
[edit] 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"
[edit] Create post init startup task
In the GUI go to:
Tasks > Init/Shutdown Scripts
and create a Command type with the following:
ln -s /usr/local/telegraf-1.23.4_freebsd_amd64/telegraf.init /usr/local/etc/rc.d/telegraf; service telegraf start
Select Post Init
and Enable it.