CentOS Stream 9
Sponsored Link

InfluxDB : Telegraf インストール2022/11/16

 
各種メトリクス収集/送信エージェント Telegraf をインストールします。
Telegraf では多くの Input /Output プラグインに対応しており、様々なデータを 収集/送信 可能です。
⇒ https://docs.influxdata.com/telegraf/v1.24/plugins/
[1] InfluxDB のリポジトリから Telegraf をインストールします。
[root@dlp ~]#
dnf -y install telegraf
[2] Telegraf の設定です。
例として、システムの CPU 関連データを取得して、InfluxDB に出力するよう設定します。
[root@dlp ~]#
mv /etc/telegraf/telegraf.conf /etc/telegraf/telegraf.conf.org

[root@dlp ~]#
vi /etc/telegraf/telegraf.conf
# 新規作成

[global_tags]
  # メトリクスにタグを付加する場合は任意の値を設定
  dc = "hiroshima-01"

[agent]
  # データを収集する間隔
  interval = "10s"
  # [true] の場合 収集時間は :00, :10, :20 ...
  round_interval = true
  # バッチ処理で Outoput に送信する際のメトリクスサイズ
  metric_batch_size = 1000
  # 使用するメモリーの上限値
  metric_buffer_limit = 10000
  # メトリクス収集の遅延時間 - 各プラグインがメトリクス収集の際に設定値の範囲内でスリープ
  collection_jitter = "0s"
  # Output データを出力する間隔
  flush_interval = "10s"
  # データを出力する際の遅延時間
  # flush_interval=10s, flush_jitter=5s の場合 10-15s 毎にデータフラッシュ
  flush_jitter = "0s"

[[outputs.influxdb]]
  # InfluxDB アクセス URL
  url = "https://dlp.srv.world:8086"
  database = "telegraf"
  # 認証を有効にしている場合は管理者ユーザー名とパスワードを指定
  username = "admin"
  password = "adminpassword"
  # HTTPS を有効にしている場合は証明書へのパス
  # InfluxDB と同じ証明書でよいが [telegraf] ユーザーが要読み取り可
  tls_cert = "/etc/telegraf/server.crt"
  tls_key = "/etc/telegraf/server.key"
  # 自己署名の証明書の場合は [true]
  insecure_skip_verify = true

# CPU 関連メトリクスの読み取り設定 (下例はデフォルト)
[[inputs.cpu]]
  percpu = true
  totalcpu = true
  collect_cpu_time = false
  report_active = false

[root@dlp ~]#
systemctl restart telegraf
# リテンションポリシーを変更する
# 下例は 30 日 (デフォルトは無期限)

[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

# データ確認

[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
----                 ---       --           ----          ----------- ---------------- ----------        ------------ ---------            ---------- -------------        ----------- ------------         ----------
2022-11-16T02:00:00Z cpu-total hiroshima-01 dlp.srv.world 0           0                99.79999999999563 0            0.050000000000001155 0          0                    0           0.049999999999998934 0.09999999999999787
2022-11-16T02:00:00Z cpu0      hiroshima-01 dlp.srv.world 0           0                99.79999999999568 0            0                    0          0                    0           0.09999999999997967  0.09999999999997967
2022-11-16T02:00:00Z cpu1      hiroshima-01 dlp.srv.world 0           0                99.80000000001382 0            0.10000000000000009  0          0                    0           0                    0.10000000000001563
2022-11-16T02:00:10Z cpu-total hiroshima-01 dlp.srv.world 0           0                99.89999999999782 0            0.049999999999998934 0          0                    0           0                    0.050000000000007816
2022-11-16T02:00:10Z cpu0      hiroshima-01 dlp.srv.world 0           0                100               0            0                    0          0                    0           0                    0
2022-11-16T02:00:10Z cpu1      hiroshima-01 dlp.srv.world 0           0                99.70059880238868 0            0.09980039920159255  0          0.09980039920159255  0           0.09980039920159033  0
2022-11-16T02:00:20Z cpu-total hiroshima-01 dlp.srv.world 0           0                99.950000000008   0            0                    0          0                    0           0.049999999999998934 0
2022-11-16T02:00:20Z cpu0      hiroshima-01 dlp.srv.world 0           0                100               0            0                    0          0                    0           0                    0
2022-11-16T02:00:20Z cpu1      hiroshima-01 dlp.srv.world 0           0                99.89999999999782 0            0                    0          0                    0           0.10000000000000231  0
2022-11-16T02:00:30Z cpu-total hiroshima-01 dlp.srv.world 0           0                99.8999499749853  0            0                    0          0                    0           0.05002501250625716  0.05002501250624827
2022-11-16T02:00:30Z cpu0      hiroshima-01 dlp.srv.world 0           0                99.80019980019544 0            0.09990009990009781  0          0                    0           0                    0.09990009990010447
2022-11-16T02:00:30Z cpu1      hiroshima-01 dlp.srv.world 0           0                99.89999999999782 0            0                    0          0                    0           0                    0.09999999999999787
.....
.....
[3] その他、メモリー等のシステム関連のメトリクスを InfluxDB に出力する設定です。
[root@dlp ~]#
vi /etc/telegraf/telegraf.conf
# 最終行に追記

# メモリー
[[inputs.mem]]

# スワップ
[[inputs.swap]]

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

# ディスク IO
[[inputs.diskio]]

# カーネルの統計情報 (/proc/stat)
[[inputs.kernel]]

# プロセス
[[inputs.processes]]

# システム (Uptime 等)
[[inputs.system]]

# ネットワーク
[[inputs.net]]

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

name: measurements
name
----
cpu
disk
diskio
kernel
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 mode path  total       used       used_percent
----                 --           ------ ----        ------ ----          ----------- ------------ ----------- ---- ----  -----       ----       ------------
2022-11-16T02:03:00Z hiroshima-01 dm-0   25495433216 xfs    dlp.srv.world 13577580    13629440     51860       rw   /     27899465728 2404032512 8.616768992774313
2022-11-16T02:03:00Z hiroshima-01 vda1   757981184   xfs    dlp.srv.world 523917      524288       371         rw   /boot 1063256064  305274880  28.711322731755423
2022-11-16T02:03:10Z hiroshima-01 dm-0   25495322624 xfs    dlp.srv.world 13577580    13629440     51860       rw   /     27899465728 2404143104 8.61716538746186
2022-11-16T02:03:10Z hiroshima-01 vda1   757981184   xfs    dlp.srv.world 523917      524288       371         rw   /boot 1063256064  305274880  28.711322731755423
2022-11-16T02:03:20Z hiroshima-01 dm-0   25495318528 xfs    dlp.srv.world 13577580    13629440     51860       rw   /     27899465728 2404147200 8.617180068746585
2022-11-16T02:03:20Z hiroshima-01 vda1   757981184   xfs    dlp.srv.world 523917      524288       371         rw   /boot 1063256064  305274880  28.711322731755423
.....
.....

[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
----                 --           ----          ------- ---------------- ------------ ------------- ---- ---------- --------- ----- ---------------- ----------- ---------- ------
2022-11-16T02:03:00Z hiroshima-01 dlp.srv.world 13177   1                0            0             dm-0 252901376  2318      11293 12195            503194624   9877       9105
2022-11-16T02:03:00Z hiroshima-01 dlp.srv.world 13213   0                13           790           vda2 256813056  2216      11407 16812            503194624   14596      8651
2022-11-16T02:03:00Z hiroshima-01 dlp.srv.world 9       0                0            0             dm-1 2404352    6         99    6                0           0          0
2022-11-16T02:03:00Z hiroshima-01 dlp.srv.world 21      0                0            0             vda1 6401024    6         106   8                2097152     1          2
2022-11-16T02:03:00Z hiroshima-01 dlp.srv.world 13232   0                13           790           vda  264426496  2225      11585 25444            505291776   14597      8653
2022-11-16T02:03:10Z hiroshima-01 dlp.srv.world 21      0                0            0             vda1 6401024    6         106   8                2097152     1          2
.....
.....

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

name: kernel
time                 boot_time  context_switches dc           entropy_avail host          interrupts processes_forked
----                 ---------  ---------------- --           ------------- ----          ---------- ----------------
2022-11-16T02:03:00Z 1668555444 940929           hiroshima-01 256           dlp.srv.world 552198     2025
2022-11-16T02:03:10Z 1668555444 943046           hiroshima-01 256           dlp.srv.world 553347     2026
2022-11-16T02:03:20Z 1668555444 945242           hiroshima-01 256           dlp.srv.world 554512     2035
2022-11-16T02:03:30Z 1668555444 947061           hiroshima-01 256           dlp.srv.world 555476     2035
2022-11-16T02:03:40Z 1668555444 948722           hiroshima-01 256           dlp.srv.world 556320     2035
.....
.....

[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    commit_limit committed_as dc           dirty  free       high_free high_total host          huge_page_size huge_pages_free huge_pages_total inactive  low_free low_total mapped    page_tables shared  slab     sreclaimable sunreclaim swap_cached swap_free  swap_total total      used      used_percent       vmalloc_chunk vmalloc_total     vmalloc_used write_back write_back_tmp
----                 ------    ---------  ----------------- -------- ------    ------------ ------------ --           -----  ----       --------- ---------- ----          -------------- --------------- ---------------- --------  -------- --------- ------    ----------- ------  ----     ------------ ---------- ----------- ---------  ---------- -----      ----      ------------       ------------- -------------     ------------ ---------- --------------
2022-11-16T02:03:00Z 269897728 3601453056 87.69904716688494 2772992  636461056 5274521600   563654656    hiroshima-01 16384 3204259840 0         0          dlp.srv.world 2097152        0               0                469143552 0        0         157589504 2539520     8953856 84459520 43089920     41369600   0           3221221376 3221221376 4106604544 263110656 6.407012245296927  0             14073748835531776 14114816     0          0
2022-11-16T02:03:10Z 269901824 3597451264 87.60159945900065 2772992  642347008 5274521600   563654656    hiroshima-01 12288 3197267968 0         0          dlp.srv.world 2097152        0               0                470036480 0        0         158642176 2547712     8953856 90746880 48881664     41865216   0           3221221376 3221221376 4106604544 264216576 6.433942522808449  0             14073748835531776 14114816     0          0
2022-11-16T02:03:20Z 269901824 3587268608 87.35364142235751 2772992  642359296 5274521600   576237568    hiroshima-01 40960 3187073024 0         0          dlp.srv.world 2097152        0               0                473702400 0        0         159121408 2551808     8953856 90746880 48881664     41865216   0           3221221376 3221221376 4106604544 274399232 6.68190055945158   0             14073748835531776 14147584     0          0
2022-11-16T02:03:30Z 269901824 3587280896 87.3539406476632  2772992  642371584 5274521600   576237568    hiroshima-01 28672 3187073024 0         0          dlp.srv.world 2097152        0               0                473952256 0        0         159215616 2560000     8953856 90746880 48881664     41865216   0           3221221376 3221221376 4106604544 274386944 6.681601334145896  0             14073748835531776 14147584     0          0
2022-11-16T02:03:40Z 269901824 3587035136 87.34795614154953 2772992  642383872 5274521600   576237568    hiroshima-01 28672 3186814976 0         0          dlp.srv.world 2097152        0               0                474071040 0        0         159215616 2560000     8953856 90746880 48881664     41865216   0           3221221376 3221221376 4106604544 274632704 6.687585840259568  0             14073748835531776 14147584     0          0
.....
.....

[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          icmp_inaddrmaskreps icmp_inaddrmasks icmp_incsumerrors icmp_indestunreachs icmp_inechoreps icmp_inechos icmp_inerrors icmp_inmsgs icmp_inparmprobs icmp_inredirects icmp_insrcquenchs icmp_intimeexcds icmp_intimestampreps icmp_intimestamps icmp_outaddrmaskreps icmp_outaddrmasks icmp_outdestunreachs icmp_outechoreps icmp_outechos icmp_outerrors icmp_outmsgs icmp_outparmprobs icmp_outredirects icmp_outsrcquenchs icmp_outtimeexcds icmp_outtimestampreps icmp_outtimestamps interface ip_defaultttl ip_forwarding ip_forwdatagrams ip_fragcreates ip_fragfails ip_fragoks ip_inaddrerrors ip_indelivers ip_indiscards ip_inhdrerrors ip_inreceives ip_inunknownprotos ip_outdiscards ip_outnoroutes ip_outrequests ip_reasmfails ip_reasmoks ip_reasmreqds ip_reasmtimeout packets_recv packets_sent tcp_activeopens tcp_attemptfails tcp_currestab tcp_estabresets tcp_incsumerrors tcp_inerrs tcp_insegs tcp_maxconn tcp_outrsts tcp_outsegs tcp_passiveopens tcp_retranssegs tcp_rtoalgorithm tcp_rtomax tcp_rtomin udp_ignoredmulti udp_incsumerrors udp_indatagrams udp_inerrors udp_memerrors udp_noports udp_outdatagrams udp_rcvbuferrors udp_sndbuferrors udplite_ignoredmulti udplite_incsumerrors udplite_indatagrams udplite_inerrors udplite_memerrors udplite_noports udplite_outdatagrams udplite_rcvbuferrors udplite_sndbuferrors
----                 ---------- ---------- --           ------- -------- ------ ------- ----          ------------------- ---------------- ----------------- ------------------- --------------- ------------ ------------- ----------- ---------------- ---------------- ----------------- ---------------- -------------------- ----------------- -------------------- ----------------- -------------------- ---------------- ------------- -------------- ------------ ----------------- ----------------- ------------------ ----------------- --------------------- ------------------ --------- ------------- ------------- ---------------- -------------- ------------ ---------- --------------- ------------- ------------- -------------- ------------- ------------------ -------------- -------------- -------------- ------------- ----------- ------------- --------------- ------------ ------------ --------------- ---------------- ------------- --------------- ---------------- ---------- ---------- ----------- ----------- ----------- ---------------- --------------- ---------------- ---------- ---------- ---------------- ---------------- --------------- ------------ ------------- ----------- ---------------- ---------------- ---------------- -------------------- -------------------- ------------------- ---------------- ----------------- --------------- -------------------- -------------------- --------------------
2022-11-16T02:03:00Z                       hiroshima-01                                 dlp.srv.world 0                   0                0                 0                   0               0            0             0           0                0                0                 0                0                    0                 0                    0                 0                    0                0             0              0            0                 0                 0                  0                 0                     0                  all       64            2             0                0              0            0          0               27608         0             0              28625         0                  0              2              22325          0             0           0             0                                         93              15               2             16              0                0          28933      -1          58          23650       51               0               1                120000     200        0                0                113             0            0             0           113              0                0                0                    0                    0                   0                0                 0               0                    0                    0
2022-11-16T02:03:00Z 122385983  1479337    hiroshima-01 4370    0        0      0       dlp.srv.world                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        enp1s0                                                                                                                                                                                                                                                                                         33002        22077                                                                                                                                                                                                                                                                                                                                                                                                                  
2022-11-16T02:03:10Z                       hiroshima-01                                 dlp.srv.world 0                   0                0                 0                   0               0            0             0           0                0                0                 0                0                    0                 0                    0                 0                    0                0             0              0            0                 0                 0                  0                 0                     0                  all       64            2             0                0              0            0          0               27636         0             0              28653         0                  0              2              22353          0             0           0             0                                         93              15               2             16              0                0          28961      -1          58          23678       51               0               1                120000     200        0                0                113             0            0             0           113              0                0                0                    0                    0                   0                0                 0               0                    0                    0
2022-11-16T02:03:10Z 122386327  1479421    hiroshima-01 4375    0        0      0       dlp.srv.world                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        enp1s0                                                                                                                                                                                                                                                                                         33009        22079                                                                                                                                                                                                                                                                                                                                                                                                                  
2022-11-16T02:03:20Z                       hiroshima-01                                 dlp.srv.world 0                   0                0                 0                   0               0            0             0           0                0                0                 0                0                    0                 0                    0                 0                    0                0             0              0            0                 0                 0                  0                 0                     0                  all       64            2             0                0              0            0          0               27664         0             0              28689         0                  0              2              22381          0             0           0             0                                         94              15               2             17              0                0          29013      -1          59          23730       52               0               1                120000     200        0                0                113             0            0             0           113              0                0                0                    0                    0                   0                0                 0               0                    0                    0
2022-11-16T02:03:20Z 122388323  1479421    hiroshima-01 4380    0        0      0       dlp.srv.world                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        enp1s0                                                                                                                                                                                                                                                                                         33022        22079                                                                                                                                                                                                                                                                                                                                                                                                                  
.....
.....

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

name: processes
time                 blocked dc           dead host          idle paging running sleeping stopped total total_threads unknown zombies
----                 ------- --           ---- ----          ---- ------ ------- -------- ------- ----- ------------- ------- -------
2022-11-16T02:03:00Z 0       hiroshima-01 0    dlp.srv.world 65   0      0       59       0       124   153           0       0
2022-11-16T02:03:10Z 0       hiroshima-01 0    dlp.srv.world 65   0      0       59       0       124   153           0       0
2022-11-16T02:03:20Z 1       hiroshima-01 0    dlp.srv.world 64   0      0       59       0       124   154           0       0
2022-11-16T02:03:30Z 0       hiroshima-01 0    dlp.srv.world 65   0      0       59       0       124   154           0       0
2022-11-16T02:03:40Z 0       hiroshima-01 0    dlp.srv.world 65   0      0       59       0       124   154           0       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
----                 --           ----       ----          -- --- -----      ---- ------------
2022-11-16T02:03:00Z hiroshima-01 3221221376 dlp.srv.world 0  0   3221221376 0    0
2022-11-16T02:03:10Z hiroshima-01 3221221376 dlp.srv.world 0  0   3221221376 0    0
2022-11-16T02:03:20Z hiroshima-01 3221221376 dlp.srv.world 0  0   3221221376 0    0
2022-11-16T02:03:30Z hiroshima-01 3221221376 dlp.srv.world 0  0   3221221376 0    0
2022-11-16T02:03:40Z hiroshima-01 3221221376 dlp.srv.world 0  0   3221221376 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_users uptime uptime_format
----                 --           ----          ----- ------ ----- ------ ------- ------ -------------
2022-11-16T02:03:00Z hiroshima-01 dlp.srv.world 0.01  0      0.02  2      1       8736    2:25
2022-11-16T02:03:10Z hiroshima-01 dlp.srv.world 0     0      0.02  2      1       8746    2:25
2022-11-16T02:03:20Z hiroshima-01 dlp.srv.world 0     0      0.02  2      1       8756    2:25
2022-11-16T02:03:30Z hiroshima-01 dlp.srv.world 0     0      0.02  2      1       8766    2:26
2022-11-16T02:03:40Z hiroshima-01 dlp.srv.world 0     0      0.02  2      1       8776    2:26
.....
.....
関連コンテンツ