FreeBSD 14
Sponsored Link

InfluxDB : Install Telegraf2024/08/26

 

Install Telegraf which can collect or send various metrics.

Telegraf supports many Input /Output plugins, refer to the official site below.

⇒ https://docs.influxdata.com/telegraf/v1.27/plugins/

[1] Install Telegraf.
root@dlp:~ #
pkg install -y telegraf
[2] Configure Telegraf.
As an example, configure it to get CPU related metrics on the system and send them to InfluxDB.
root@dlp:~ #
vi /usr/local/etc/telegraf.conf
# create new

[global_tags]
  # set any tag if you need to add it on data
  dc = "hiroshima-01"

[agent]
  # collection interval for all inputs
  interval = "10s"
  # if set [true], then always collect on :00, :10, :20 ...
  round_interval = true
  # the size of writes that Telegraf sends to output plugins
  metric_batch_size = 1000
  # cost of higher maximum memory usage
  metric_buffer_limit = 10000
  # it is used to jitter the collection by a random amount
  collection_jitter = "0s"
  # flushing interval for all outputs
  flush_interval = "10s"
  # jitter the flush interval by a random amount
  # if flush_interval=10s, flush_jitter=5s, then flushes will happen every 10-15s
  flush_jitter = "0s"

[[outputs.influxdb]]
  # InfluxDB access URL
  urls = ["https://dlp.srv.world:8086"]
  database = "telegraf"
  # if auth is enabled, set admin username and password
  username = "admin"
  password = "adminpassword"
  # if HTTPS is enabled, set the path to certificate
  # it needs [telegraf] user can read certificate
  tls_cert = "/usr/local/etc/ssl/telegraf.crt"
  tls_key = "/usr/local/etc/ssl/telegraf.key"
  # if using self signed certificate, set [true]
  insecure_skip_verify = true

# settings for CPU related metrics
[[inputs.cpu]]
  percpu = true
  totalcpu = true
  collect_cpu_time = false
  report_active = false

root@dlp:~ #
service telegraf enable

telegraf enabled in /etc/rc.conf
root@dlp:~ #
service telegraf start

Starting telegraf
# change retention policy
# follow means 30 days retention (default is infinite)

root@dlp:~ #
influx -username admin -password adminpassword -database telegraf -ssl -unsafeSsl \
-execute 'create retention policy "one_month" on "telegraf" duration 30d replication 1 default'
root@dlp:~ #
influx -username admin -password adminpassword -database telegraf -ssl -unsafeSsl \
-execute 'show retention policies'

name      duration shardGroupDuration replicaN default
----      -------- ------------------ -------- -------
autogen   0s       168h0m0s           1        false
one_month 720h0m0s 24h0m0s            1        true

# verify data

root@dlp:~ #
influx -username admin -password adminpassword -database telegraf -precision rfc3339 \
-execute 'select * from cpu' -ssl -unsafeSsl

name: cpu
time                 cpu       dc           host          usage_guest usage_guest_nice usage_idle        usage_iowait usage_irq            usage_nice usage_softirq usage_steal usage_system         usage_user
----                 ---       --           ----          ----------- ---------------- ----------        ------------ ---------            ---------- ------------- ----------- ------------         ----------
2024-08-26T01:32:20Z cpu-total hiroshima-01 dlp.srv.world 0           0                99.96059889676911 0            0                    0          0             0           0.039401103230890466 0
2024-08-26T01:32:20Z cpu0      hiroshima-01 dlp.srv.world 0           0                99.92119779353821 0            0                    0          0             0           0.07880220646178093  0
2024-08-26T01:32:20Z cpu1      hiroshima-01 dlp.srv.world 0           0                100               0            0                    0          0             0           0                    0
2024-08-26T01:32:30Z cpu-total hiroshima-01 dlp.srv.world 0           0                99.64594807238394 0            0.03933910306845004  0          0             0           0.23603461841070023  0.07867820613690008
2024-08-26T01:32:30Z cpu0      hiroshima-01 dlp.srv.world 0           0                99.8426435877262  0            0.07867820613690008  0          0             0           0.07867820613690008  0
2024-08-26T01:32:30Z cpu1      hiroshima-01 dlp.srv.world 0           0                99.4492525570417  0            0                    0          0             0           0.3933910306845004   0.15735641227380015
.....
.....
[3] For other System related metrics, configure like follows.
root@dlp:~ #
vi /usr/local/etc/telegraf.conf
# add to last line

# memory
[[inputs.mem]]

# swap
[[inputs.swap]]

# disk
[[inputs.disk]]
  ignore_fs = ["tmpfs", "devtmpfs", "devfs", "iso9660", "overlay", "aufs", "squashfs"]

# disk IO
[[inputs.diskio]]

# processes
[[inputs.processes]]

# system (Uptime and so on)
[[inputs.system]]

# networking
[[inputs.net]]

root@dlp:~ #
service telegraf restart

root@dlp:~ #
influx -username admin -password adminpassword -database telegraf -precision rfc3339 -execute 'show measurements' -ssl -unsafeSsl

name: measurements
name
----
cpu
disk
diskio
mem
net
processes
swap
system

root@dlp:~ #
influx -username admin -password adminpassword -database telegraf -precision rfc3339 \
-execute 'select * from disk' -ssl -unsafeSsl

name: disk
time                 dc           device             free        fstype  host          inodes_free inodes_total inodes_used inodes_used_percent     mode path       total       used       used_percent
----                 --           ------             ----        ------  ----          ----------- ------------ ----------- -------------------     ---- ----       -----       ----       ------------
2024-08-26T01:35:10Z hiroshima-01 gpt/efiboot0       271138816   msdosfs dlp.srv.world 510         512          2           0.390625                rw   /boot/efi  272531456   1392640    0.5110015630636047
2024-08-26T01:35:10Z hiroshima-01 zroot              24100720640 zfs     dlp.srv.world 47071720    47071727     7           0.000014870922411663374 rw   /zroot     24100818944 98304      0.00040788655451259344
2024-08-26T01:35:10Z hiroshima-01 zroot/ROOT/default 24100720640 zfs     dlp.srv.world 47071720    47122791     51071       0.108378555081765       rw   /          27387047936 3286327296 11.999567473207492
2024-08-26T01:35:10Z hiroshima-01 zroot/home         24100720640 zfs     dlp.srv.world 47071720    47071746     26          0.000055234832376942214 rw   /home      24100900864 180224     0.0007477894748291513
2024-08-26T01:35:10Z hiroshima-01 zroot/tmp          24100720640 zfs     dlp.srv.world 47071720    47071731     11          0.00002336859037539962  rw   /tmp       24100827136 106496     0.0004418769505255871
2024-08-26T01:35:10Z hiroshima-01 zroot/usr/ports    24100720640 zfs     dlp.srv.world 47071720    47071727     7           0.000014870922411663374 rw   /usr/ports 24100818944 98304      0.00040788655451259344
2024-08-26T01:35:10Z hiroshima-01 zroot/usr/src      24100720640 zfs     dlp.srv.world 47071720    47071727     7           0.000014870922411663374 rw   /usr/src   24100818944 98304      0.00040788655451259344
2024-08-26T01:35:10Z hiroshima-01 zroot/var/audit    24100720640 zfs     dlp.srv.world 47071720    47071729     9           0.000019119756574057436 rw   /var/audit 24100818944 98304      0.00040788655451259344
.....
.....

root@dlp:~ #
influx -username admin -password adminpassword -database telegraf -precision rfc3339 \
-execute 'select * from diskio' -ssl -unsafeSsl

name: diskio
time                 dc           host          io_time iops_in_progress merged_reads merged_writes name  read_bytes read_time reads weighted_io_time write_bytes write_time writes
----                 --           ----          ------- ---------------- ------------ ------------- ----  ---------- --------- ----- ---------------- ----------- ---------- ------
2024-08-26T01:35:10Z hiroshima-01 dlp.srv.world 0       0                0            0             cd0   0          0         0     0                0           0          0
2024-08-26T01:35:10Z hiroshima-01 dlp.srv.world 10425   0                0            0             vtbd0 52308480   1101      4359  0                694554624   6174       32514
2024-08-26T01:35:10Z hiroshima-01 dlp.srv.world 0       0                0            0             pass0 0          0         0     0                0           0          0
2024-08-26T01:35:20Z hiroshima-01 dlp.srv.world 10479   0                0            0             vtbd0 52443648   1108      4364  0                695939072   6181       32665
2024-08-26T01:35:20Z hiroshima-01 dlp.srv.world 0       0                0            0             pass0 0          0         0     0                0           0          0
2024-08-26T01:35:20Z hiroshima-01 dlp.srv.world 0       0                0            0             cd0   0          0         0     0                0           0          0
2024-08-26T01:35:30Z hiroshima-01 dlp.srv.world 0       0                0            0             pass0 0          0         0     0                0           0          0
2024-08-26T01:35:30Z hiroshima-01 dlp.srv.world 0       0                0            0             cd0   0          0         0     0                0           0          0
2024-08-26T01:35:30Z hiroshima-01 dlp.srv.world 10516   0                0            0             vtbd0 52443648   1108      4364  0                696950784   6186       32799
.....
.....

root@dlp:~ #
influx -username admin -password adminpassword -database telegraf -precision rfc3339 \
-execute 'select * from mem' -ssl -unsafeSsl

name: mem
time                 active   available  available_percent buffered cached dc           free       host          inactive  laundry total      used       used_percent       wired
----                 ------   ---------  ----------------- -------- ------ --           ----       ----          --------  ------- -----      ----       ------------       -----
2024-08-26T01:35:10Z 84729856 2958540800 69.93535119203804 107008   0      hiroshima-01 2714509312 dlp.srv.world 244031488 0       4230393856 1271853056 30.06464880796196  1017069568
2024-08-26T01:35:20Z 86134784 2957484032 69.91037082292888 107008   0      hiroshima-01 2713194496 dlp.srv.world 244289536 0       4230393856 1272909824 30.08962917707112  1018314752
2024-08-26T01:35:30Z 87863296 2955874304 69.87231933044865 107008   0      hiroshima-01 2711601152 dlp.srv.world 244273152 0       4230393856 1274519552 30.12768066955135  1017057280
2024-08-26T01:35:40Z 89042944 2954452992 69.83872170222818 107008   0      hiroshima-01 2709823488 dlp.srv.world 244629504 0       4230393856 1275940864 30.16127829777181  1017036800
2024-08-26T01:35:50Z 89833472 2955599872 69.86583218033115 107008   0      hiroshima-01 2711298048 dlp.srv.world 244301824 0       4230393856 1274793984 30.134167819668846 1017061376
2024-08-26T01:36:00Z 91017216 2953039872 69.8053177202799  107008   0      hiroshima-01 2708733952 dlp.srv.world 244305920 0       4230393856 1277353984 30.194682279720105 1017221120
2024-08-26T01:36:20Z 86351872 2958557184 69.93573848458237 107008   0      hiroshima-01 2713083904 dlp.srv.world 245473280 0       4230393856 1271836672 30.06426151541763  1017049088
.....
.....

root@dlp:~ #
influx -username admin -password adminpassword -database telegraf -precision rfc3339 \
-execute 'select * from net' -ssl -unsafeSsl

name: net
time                 bytes_recv bytes_sent dc           drop_in drop_out err_in err_out host          interface packets_recv packets_sent speed
----                 ---------- ---------- --           ------- -------- ------ ------- ----          --------- ------------ ------------ -----
2024-08-26T01:35:10Z 86832329   1848392    hiroshima-01 0       0        0      0       dlp.srv.world vtnet0    50399        27318        -1
2024-08-26T01:35:20Z 86832589   1848434    hiroshima-01 0       0        0      0       dlp.srv.world vtnet0    50404        27319        -1
2024-08-26T01:35:30Z 86832849   1848434    hiroshima-01 0       0        0      0       dlp.srv.world vtnet0    50409        27319        -1
2024-08-26T01:35:40Z 86833469   1848434    hiroshima-01 0       0        0      0       dlp.srv.world vtnet0    50420        27319        -1
2024-08-26T01:35:50Z 86833729   1848434    hiroshima-01 0       0        0      0       dlp.srv.world vtnet0    50425        27319        -1
2024-08-26T01:36:00Z 86833989   1848434    hiroshima-01 0       0        0      0       dlp.srv.world vtnet0    50430        27319        -1
2024-08-26T01:36:20Z 86834814   1848644    hiroshima-01 0       0        0      0       dlp.srv.world vtnet0    50443        27322        -1
.....
.....

root@dlp:~ #
influx -username admin -password adminpassword -database telegraf -precision rfc3339 \
-execute 'select * from processes' -ssl -unsafeSsl

name: processes
time                 blocked dc           host          idle running sleeping stopped total unknown wait zombies
----                 ------- --           ----          ---- ------- -------- ------- ----- ------- ---- -------
2024-08-26T01:35:10Z 16      hiroshima-01 dlp.srv.world 10   2       9        0       39    0       2    0
2024-08-26T01:35:20Z 15      hiroshima-01 dlp.srv.world 10   3       9        0       39    0       2    0
2024-08-26T01:35:30Z 15      hiroshima-01 dlp.srv.world 13   2       6        0       38    0       2    0
2024-08-26T01:35:40Z 15      hiroshima-01 dlp.srv.world 14   3       5        0       39    0       2    0
2024-08-26T01:35:50Z 15      hiroshima-01 dlp.srv.world 14   2       5        0       38    0       2    0
2024-08-26T01:36:00Z 15      hiroshima-01 dlp.srv.world 13   3       6        0       39    0       2    0
2024-08-26T01:36:20Z 15      hiroshima-01 dlp.srv.world 11   3       7        0       38    0       2    0
.....
.....

root@dlp:~ #
influx -username admin -password adminpassword -database telegraf -precision rfc3339 \
-execute 'select * from swap' -ssl -unsafeSsl

name: swap
time                 dc           free       host          in out total      used used_percent
----                 --           ----       ----          -- --- -----      ---- ------------
2024-08-26T01:35:10Z hiroshima-01 2147483648 dlp.srv.world 0  0   2147483648 0    0
2024-08-26T01:35:20Z hiroshima-01 2147483648 dlp.srv.world 0  0   2147483648 0    0
2024-08-26T01:35:30Z hiroshima-01 2147483648 dlp.srv.world 0  0   2147483648 0    0
2024-08-26T01:35:40Z hiroshima-01 2147483648 dlp.srv.world 0  0   2147483648 0    0
2024-08-26T01:35:50Z hiroshima-01 2147483648 dlp.srv.world 0  0   2147483648 0    0
2024-08-26T01:36:00Z hiroshima-01 2147483648 dlp.srv.world 0  0   2147483648 0    0
2024-08-26T01:36:20Z hiroshima-01 2147483648 dlp.srv.world 0  0   2147483648 0    0
.....
.....

root@dlp:~ #
influx -username admin -password adminpassword -database telegraf -precision rfc3339 \
-execute 'select * from system' -ssl -unsafeSsl

name: system
time                 dc           host          load1         load15        load5         n_cpus n_unique_users n_users uptime uptime_format
----                 --           ----          -----         ------        -----         ------ -------------- ------- ------ -------------
2024-08-26T01:35:10Z hiroshima-01 dlp.srv.world 0.15087890625 0.2236328125  0.22314453125 2      1              1       4394    1:13
2024-08-26T01:35:20Z hiroshima-01 dlp.srv.world 0.12744140625 0.220703125   0.21533203125 2      1              1       4404    1:13
2024-08-26T01:35:30Z hiroshima-01 dlp.srv.world 0.18115234375 0.2236328125  0.22412109375 2      1              1       4414    1:13
2024-08-26T01:35:40Z hiroshima-01 dlp.srv.world 0.23291015625 0.2265625     0.23291015625 2      1              1       4424    1:13
2024-08-26T01:35:50Z hiroshima-01 dlp.srv.world 0.1962890625  0.2236328125  0.22509765625 2      1              1       4434    1:13
2024-08-26T01:36:00Z hiroshima-01 dlp.srv.world 0.16552734375 0.220703125   0.21728515625 2      1              1       4444    1:14
2024-08-26T01:36:20Z hiroshima-01 dlp.srv.world 0.24169921875 0.2265625     0.2333984375  2      1              1       4464    1:14
2024-08-26T01:36:30Z hiroshima-01 dlp.srv.world 0.2041015625  0.2236328125  0.2255859375  2      1              1       4474    1:14
2024-08-26T01:36:40Z hiroshima-01 dlp.srv.world 0.17236328125 0.220703125   0.2177734375  2      1              1       4484    1:14
.....
.....
Matched Content