Debian 13 trixie

InfluxDB : Telegraf インストール2025/09/16

 

各種メトリクス収集/送信エージェント Telegraf をインストールします。

Telegraf では多くの Input /Output プラグインに対応しており、様々なデータを 収集/送信 可能です。

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

[1] Telegraf をインストールします。
root@dlp:~#
curl -fsSL https://repos.influxdata.com/influxdata-archive_compat.key -o /etc/apt/keyrings/influxdata-archive_compat.key

root@dlp:~#
echo "deb [signed-by=/etc/apt/keyrings/influxdata-archive_compat.key] https://repos.influxdata.com/debian stable main" | tee /etc/apt/sources.list.d/influxdata.list

root@dlp:~#
apt update

root@dlp:~#
apt -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
  urls = ["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
----                 ---       --           ----          ----------- ---------------- ----------        ------------        --------- ---------- ------------- ----------- ------------        ----------
2025-09-16T00:15:30Z cpu-total hiroshima-01 dlp.srv.world 0           0                99.89994997498985 0.10005002501250522 0         0          0             0           0                   0
2025-09-16T00:15:30Z cpu0      hiroshima-01 dlp.srv.world 0           0                99.80000000000018 0.20000000000000018 0         0          0             0           0                   0
2025-09-16T00:15:30Z cpu1      hiroshima-01 dlp.srv.world 0           0                100               0                   0         0          0             0           0                   0
2025-09-16T00:15:40Z cpu-total hiroshima-01 dlp.srv.world 0           0                99.69954932398397 0.20030045067601165 0         0          0             0           0.10015022533800359 0
2025-09-16T00:15:40Z cpu0      hiroshima-01 dlp.srv.world 0           0                99.59919839679395 0.3006012024048116  0         0          0             0           0.10020040080160533 0
2025-09-16T00:15:40Z cpu1      hiroshima-01 dlp.srv.world 0           0                99.69999999999801 0.19999999999998663 0         0          0             0           0.09999999999999332 0
.....
.....
[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 inodes_used_percent label           mode path  total       used       used_percent
----                 --           ------ ----        ------ ----          ----------- ------------ ----------- ------------------- -----           ---- ----  -----       ----       ------------
2025-09-16T00:17:10Z hiroshima-01 dm-0   25762136064 ext4   dlp.srv.world 1762587     1803360      40773       2.2609462336970987  debian--vg-root rw   /     28892237824 1636511744 5.972965364816883
2025-09-16T00:17:10Z hiroshima-01 vda1   778899456   ext4   dlp.srv.world 62104       62464        360         0.5763319672131147                  rw   /boot 988057600   141213696  15.347427182521134
2025-09-16T00:17:20Z hiroshima-01 dm-0   25762131968 ext4   dlp.srv.world 1762587     1803360      40773       2.2609462336970987  debian--vg-root rw   /     28892237824 1636515840 5.972980314459758
2025-09-16T00:17:20Z hiroshima-01 vda1   778899456   ext4   dlp.srv.world 62104       62464        360         0.5763319672131147                  rw   /boot 988057600   141213696  15.347427182521134
2025-09-16T00:17:30Z hiroshima-01 dm-0   25762111488 ext4   dlp.srv.world 1762587     1803360      40773       2.2609462336970987  debian--vg-root rw   /     28892237824 1636536320 5.973055062674136
2025-09-16T00:17:30Z hiroshima-01 vda1   778899456   ext4   dlp.srv.world 62104       62464        360         0.5763319672131147                  rw   /boot 988057600   141213696  15.347427182521134
.....
.....

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

name: diskio
time                 dc           host          io_await            io_svctm            io_time io_util             iops_in_progress merged_reads merged_writes name read_bytes read_time reads weighted_io_time write_bytes write_time writes
----                 --           ----          --------            --------            ------- -------             ---------------- ------------ ------------- ---- ---------- --------- ----- ---------------- ----------- ---------- ------
2025-09-16T00:17:10Z hiroshima-01 dlp.srv.world                                         8100                        1                0            0             dm-0 323978240  1100      9708  10620            690057216   9376       16823
2025-09-16T00:17:10Z hiroshima-01 dlp.srv.world                                         8096                        1                1833         8411          vda5 326394880  977       7997  16203            690057216   15078      8844
2025-09-16T00:17:10Z hiroshima-01 dlp.srv.world                                         0                           0                0            0             dm-1 1548288    0         96    0                0           0          0
2025-09-16T00:17:10Z hiroshima-01 dlp.srv.world                                         52                          0                22           7             vda1 3163136    7         190   53               81920       44         16
2025-09-16T00:17:10Z hiroshima-01 dlp.srv.world                                         0                           0                0            0             vda2 2048       0         2     0                0           0          0
2025-09-16T00:17:10Z hiroshima-01 dlp.srv.world                                         8012                        0                1855         8418          vda  331038720  989       8277  23246            690139136   15130      8866
2025-09-16T00:17:20Z hiroshima-01 dlp.srv.world                                         0       0                   0                0            0             vda2 2048       0         2     0                0           0          0
.....
.....

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
----                 ---------  ---------------- --           ------------- ----          ---------- ----------------
2025-09-16T00:17:10Z 1757979376 288119           hiroshima-01 256           dlp.srv.world 243108     2129
2025-09-16T00:17:20Z 1757979376 289793           hiroshima-01 256           dlp.srv.world 244322     2135
2025-09-16T00:17:30Z 1757979376 291419           hiroshima-01 256           dlp.srv.world 245394     2140
2025-09-16T00:17:40Z 1757979376 293480           hiroshima-01 256           dlp.srv.world 247114     2145
2025-09-16T00:17:50Z 1757979376 294656           hiroshima-01 256           dlp.srv.world 247985     2145
2025-09-16T00:18:00Z 1757979376 295721           hiroshima-01 256           dlp.srv.world 248688     2145
2025-09-16T00:18:10Z 1757979376 297507           hiroshima-01 256           dlp.srv.world 249794     2158
.....
.....

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
----                 ------    ---------  ----------------- -------- ------    ------------ ------------ --           -----  ----       --------- ---------- ----          -------------- --------------- ---------------- --------  -------- --------- ------    ----------- ------ ----     ------------ ---------- ----------- ---------  ---------- -----      ----      ------------       ------------- -------------     ------------ ---------- --------------
2025-09-16T00:17:10Z 146546688 3731394560 90.78203383006839 25042944 759160832 3703496704   231534592    hiroshima-01 507904 3178065920 0         0          dlp.srv.world 2097152        0               0                662913024 0        0         166367232 1871872     565248 63184896 33382400     29802496   0           1648357376 1648357376 4110278656 148008960 3.6009470984149257 0             14073748835531776 15949824     0          0
2025-09-16T00:17:20Z 151674880 3720056832 90.50619540282575 25075712 764174336 3703496704   231534592    hiroshima-01 606208 3164184576 0         0          dlp.srv.world 2097152        0               0                662958080 0        0         166936576 1875968     565248 68808704 38375424     30433280   0           1648357376 1648357376 4110278656 156844032 3.8158977803377425 0             14073748835531776 15982592     0          0
2025-09-16T00:17:30Z 152768512 3715411968 90.39318934195394 25124864 764178432 3703496704   235728896    hiroshima-01 524288 3159478272 0         0          dlp.srv.world 2097152        0               0                663019520 0        0         167006208 1880064     565248 68808704 38375424     30433280   0           1648357376 1648357376 4110278656 161497088 3.92910314643154   0             14073748835531776 15982592     0          0
2025-09-16T00:17:40Z 154791936 3713626112 90.34974080355879 25141248 764190720 3703496704   235728896    hiroshima-01 102400 3157671936 0         0          dlp.srv.world 2097152        0               0                663040000 0        0         167071744 1884160     565248 68808704 38375424     30433280   0           1648357376 1648357376 4110278656 163274752 3.9723523796046982 0             14073748835531776 15982592     0          0
2025-09-16T00:17:50Z 156229632 3713134592 90.33778249023902 25149440 764207104 3703496704   239923200    hiroshima-01 151552 3157155840 0         0          dlp.srv.world 2097152        0               0                663064576 0        0         167075840 1888256     565248 68812800 38375424     30437376   0           1648357376 1648357376 4110278656 163766272 3.984310692924465  0             14073748835531776 15982592     0          0
2025-09-16T00:18:00Z 160620544 3708452864 90.22387955586824 25165824 764219392 3703496704   239923200    hiroshima-01 159744 3152445440 0         0          dlp.srv.world 2097152        0               0                663093248 0        0         167469056 1892352     565248 68812800 38375424     30437376   0           1648357376 1648357376 4110278656 168448000 4.098213627295249  0             14073748835531776 15982592     0          0
2025-09-16T00:18:10Z 160772096 3699113984 89.99667160279266 25190400 764276736 3703496704   239923200    hiroshima-01 102400 3143024640 0         0          dlp.srv.world 2097152        0               0                663138304 0        0         167550976 1978368     565248 68816896 38375424     30441472   0           1648357376 1648357376 4110278656 177786880 4.325421580370827  0             14073748835531776 15982592     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_outratelimitglobal icmp_outratelimithost 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_outtransmits ip_reasmfails ip_reasmoks ip_reasmreqds ip_reasmtimeout packets_recv packets_sent speed 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
----                 ---------- ---------- --           ------- -------- ------ ------- ----          ------------------- ---------------- ----------------- ------------------- --------------- ------------ ------------- ----------- ---------------- ---------------- ----------------- ---------------- -------------------- ----------------- -------------------- ----------------- -------------------- ---------------- ------------- -------------- ------------ ----------------- ----------------------- --------------------- ----------------- ------------------ ----------------- --------------------- ------------------ --------- ------------- ------------- ---------------- -------------- ------------ ---------- --------------- ------------- ------------- -------------- ------------- ------------------ -------------- -------------- -------------- --------------- ------------- ----------- ------------- --------------- ------------ ------------ ----- --------------- ---------------- ------------- --------------- ---------------- ---------- ---------- ----------- ----------- ----------- ---------------- --------------- ---------------- ---------- ---------- ---------------- ---------------- --------------- ------------ ------------- ----------- ---------------- ---------------- ---------------- -------------------- -------------------- ------------------- ---------------- ----------------- --------------- -------------------- -------------------- --------------------
2025-09-16T00:17: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                 0                     0                  all       64            2             0                0              0            0          0               17511         0             0              17668         0                  0              5              14830          14830           0             0           0             0                                               60              6                2             16              0                0          18425      -1          26          15749       45               0               1                120000     200        0                0                39              0            0             0           39               0                0                0                    0                    0                   0                0                 0               0                    0                    0
2025-09-16T00:17:10Z 88055832   974098     hiroshima-01 1229    0        0      0       dlp.srv.world                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      enp1s0                                                                                                                                                                                                                                                                                                         19069        14572        -1                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
2025-09-16T00:17: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                 0                     0                  all       64            2             0                0              0            0          0               17528         0             0              17685         0                  0              5              14847          14847           0             0           0             0                                               61              6                2             17              0                0          18461      -1          27          15785       46               0               1                120000     200        0                0                39              0            0             0           39               0                0                0                    0                    0                   0                0                 0               0                    0                    0
2025-09-16T00:17:20Z 88056356   974182     hiroshima-01 1234    0        0      0       dlp.srv.world                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      enp1s0                                                                                                                                                                                                                                                                                                         19079        14574        -1                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
2025-09-16T00:17:30Z                       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                 0                     0                  all       64            2             0                0              0            0          0               17549         0             0              17712         0                  0              5              14868          14868           0             0           0             0                                               62              6                2             18              0                0          18501      -1          28          15825       47               0               1                120000     200        0                0                39              0            0             0           39               0                0                0                    0                    0                   0                0                 0               0                    0                    0
2025-09-16T00:17:30Z 88059060   974182     hiroshima-01 1239    0        0      0       dlp.srv.world                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      enp1s0                                                                                                                                                                                                                                                                                                         19096        14574        -1                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
2025-09-16T00:17:40Z                       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                 0                     0                  all       64            2             0                0              0            0          0               17570         0             0              17733         0                  0              5              14889          14889           0             0           0             0                                               63              6                2             19              0                0          18541      -1          29          15865       48               0               1                120000     200        0                0                39              0            0             0           39               0                0                0                    0                    0                   0                0                 0               0                    0                    0
.....
.....

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
----                 ------- --           ---- ----          ---- ------ ------- -------- ------- ----- ------------- ------- -------
2025-09-16T00:17:10Z 0       hiroshima-01 0    dlp.srv.world 58   0      0       62       0       120   135           0       0
2025-09-16T00:17:20Z 1       hiroshima-01 0    dlp.srv.world 58   0      0       61       0       120   135           0       0
2025-09-16T00:17:30Z 1       hiroshima-01 0    dlp.srv.world 57   0      1       61       0       120   135           0       0
2025-09-16T00:17:40Z 1       hiroshima-01 0    dlp.srv.world 57   0      1       61       0       120   135           0       0
2025-09-16T00:17:50Z 1       hiroshima-01 0    dlp.srv.world 58   0      0       61       0       120   135           0       0
2025-09-16T00:18:00Z 1       hiroshima-01 0    dlp.srv.world 57   0      1       61       0       120   135           0       0
2025-09-16T00:18:10Z 1       hiroshima-01 0    dlp.srv.world 58   0      0       61       0       120   135           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
----                 --           ----       ----          -- --- -----      ---- ------------
2025-09-16T00:17:10Z hiroshima-01 1648357376 dlp.srv.world 0  0   1648357376 0    0
2025-09-16T00:17:20Z hiroshima-01 1648357376 dlp.srv.world 0  0   1648357376 0    0
2025-09-16T00:17:30Z hiroshima-01 1648357376 dlp.srv.world 0  0   1648357376 0    0
2025-09-16T00:17:40Z hiroshima-01 1648357376 dlp.srv.world 0  0   1648357376 0    0
2025-09-16T00:17:50Z hiroshima-01 1648357376 dlp.srv.world 0  0   1648357376 0    0
2025-09-16T00:18:00Z hiroshima-01 1648357376 dlp.srv.world 0  0   1648357376 0    0
2025-09-16T00:18:10Z hiroshima-01 1648357376 dlp.srv.world 0  0   1648357376 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 uptime uptime_format
----                 --           ----          ----- ------ ----- ------ ------ -------------
2025-09-16T00:17:10Z hiroshima-01 dlp.srv.world 0     0      0     2      2454    0:40
2025-09-16T00:17:20Z hiroshima-01 dlp.srv.world 0     0      0     2      2464    0:41
2025-09-16T00:17:30Z hiroshima-01 dlp.srv.world 0     0      0     2      2474    0:41
2025-09-16T00:17:40Z hiroshima-01 dlp.srv.world 0     0      0     2      2484    0:41
2025-09-16T00:17:50Z hiroshima-01 dlp.srv.world 0     0      0     2      2494    0:41
2025-09-16T00:18:00Z hiroshima-01 dlp.srv.world 0     0      0     2      2504    0:41
2025-09-16T00:18:10Z hiroshima-01 dlp.srv.world 0     0      0     2      2514    0:41
.....
.....
関連コンテンツ