InfluxDB : Telegraf インストール2026/02/20 |
|
各種メトリクス収集/送信エージェント Telegraf をインストールします。 Telegraf では多くの Input /Output プラグインに対応しており、様々なデータを 収集/送信 可能です。 ⇒ https://docs.influxdata.com/telegraf/v1.27/plugins/ |
|
| [1] | Telegraf をインストールします。 |
|
root@dlp:~ # pkg install -y telegraf
|
| [2] | Telegraf の設定です。 例として、システムの CPU 関連データを取得して、InfluxDB に出力するよう設定します。 |
|
root@dlp:~ #
vi /usr/local/etc/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 = "/usr/local/etc/ssl/telegraf.crt" tls_key = "/usr/local/etc/ssl/telegraf.key" # 自己署名の証明書の場合は [true] insecure_skip_verify = true # CPU 関連メトリクスの読み取り設定 (下例はデフォルト) [[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 # リテンションポリシーを変更する # 下例は 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' 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 ---- --- -- ---- ----------- ---------------- ---------- ------------ --------- ---------- ------------- ----------- ------------ ---------- 2026-02-20T00:09:10Z cpu-total hiroshima-01 dlp.srv.world 0 0 99.64566929133858 0 0.07874015748031496 0 0 0 0.1968503937007874 0.07874015748031496 2026-02-20T00:09:10Z cpu0 hiroshima-01 dlp.srv.world 0 0 99.68503937007874 0 0.07874015748031496 0 0 0 0.23622047244094488 0 2026-02-20T00:09:10Z cpu1 hiroshima-01 dlp.srv.world 0 0 99.60629921259843 0 0.07874015748031496 0 0 0 0.15748031496062992 0.15748031496062992 2026-02-20T00:09:20Z cpu-total hiroshima-01 dlp.srv.world 0 0 99.76377952755905 0 0.07874015748031496 0 0 0 0.11811023622047244 0.03937007874015748 2026-02-20T00:09:20Z cpu0 hiroshima-01 dlp.srv.world 0 0 99.76377952755905 0 0.07874015748031496 0 0 0 0.15748031496062992 0 ..... ..... |
| [3] | その他、メモリー等のシステム関連のメトリクスを InfluxDB に出力する設定です。 |
|
root@dlp:~ #
vi /usr/local/etc/telegraf.conf # 最終行に追記 # メモリー [[inputs.mem]] # スワップ [[inputs.swap]] # ディスク [[inputs.disk]] ignore_fs = ["tmpfs", "devtmpfs", "devfs", "iso9660", "overlay", "aufs", "squashfs"] # ディスク IO [[inputs.diskio]] # プロセス [[inputs.processes]] # システム (Uptime 等) [[inputs.system]] # ネットワーク [[inputs.net]]
root@dlp:~ #
root@dlp:~ # service telegraf restart influx -username admin -password adminpassword -database telegraf -precision rfc3339 -execute 'show measurements' -ssl -unsafeSsl name: measurements name ---- cpu disk diskio mem net processes swap systemroot@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 ---- -- ------ ---- ------ ---- ----------- ------------ ----------- ------------------- ---- ---- ----- ---- ------------ 2026-02-20T00:10:40Z hiroshima-01 gpt/efiboot0 267086848 msdosfs dlp.srv.world 0 0 0 0 rw /boot/efi 268419072 1332224 0.4963224073734969 2026-02-20T00:10:40Z hiroshima-01 zroot 27222093824 zfs dlp.srv.world 53168152 53168159 7 0.000013165774650952275 rw /zroot 27222192128 98304 0.00036111713390960605 2026-02-20T00:10:40Z hiroshima-01 zroot/ROOT/default 27222093824 zfs dlp.srv.world 53168152 53189546 21394 0.040222189525738763 rw / 28493324288 1271230464 4.461502810801829 2026-02-20T00:10:40Z hiroshima-01 zroot/home 27222093824 zfs dlp.srv.world 53168152 53168171 19 0.00003573566598708088 rw /home 27222241280 147456 0.000541674722824292 2026-02-20T00:10:40Z hiroshima-01 zroot/tmp 27222093824 zfs dlp.srv.world 53168152 53168164 12 0.000022569897279131174 rw /tmp 27222200320 106496 0.000391210110674845 2026-02-20T00:10:40Z hiroshima-01 zroot/usr/ports 27222093824 zfs dlp.srv.world 53168152 53168159 7 0.000013165774650952275 rw /usr/ports 27222192128 98304 0.00036111713390960605 2026-02-20T00:10:40Z hiroshima-01 zroot/usr/src 27222093824 zfs dlp.srv.world 53168152 53168159 7 0.000013165774650952275 rw /usr/src 27222192128 98304 0.00036111713390960605 ..... .....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 ---- -- ---- -------- -------- ------- ------- ---------------- ------------ ------------- ---- ---------- --------- ----- ---------------- ----------- ---------- ------ 2026-02-20T00:10:40Z hiroshima-01 dlp.srv.world 6675 0 0 0 vtbd0 35264000 402 2136 0 768025088 1486 22835 2026-02-20T00:10:50Z hiroshima-01 dlp.srv.world 0.04918032786885246 0.29508196721311475 6711 0.36007201440288056 0 0 0 vtbd0 35288576 403 2138 0 769188352 1491 22955 2026-02-20T00:11:00Z hiroshima-01 dlp.srv.world 0.05172413793103448 0.35344827586206895 6752 0.4102872010407285 0 0 0 vtbd0 35288576 403 2138 0 770314752 1497 23071 2026-02-20T00:11:10Z hiroshima-01 dlp.srv.world 0.05263157894736842 0.23684210526315788 6779 0.2700810243072922 0 0 0 vtbd0 35288576 403 2138 0 771441152 1503 23185 2026-02-20T00:11:20Z hiroshima-01 dlp.srv.world 0.0392156862745098 0.30392156862745096 6810 0.3096593746878434 0 0 0 vtbd0 35288576 403 2138 0 772416000 1507 23287 2026-02-20T00:11:30Z hiroshima-01 dlp.srv.world 0.05263157894736842 0.3263157894736842 6841 0.31003100310031 0 0 0 vtbd0 35288576 403 2138 0 773382656 1512 23382 2026-02-20T00:11:40Z hiroshima-01 dlp.srv.world 0.04672897196261682 0.2897196261682243 6872 0.31 0 0 0 vtbd0 35288576 403 2138 0 774382080 1517 23489 ..... .....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 ---- ------ --------- ----------------- -------- ------ -- ---- ---- -------- ------- ----- ---- ------------ ----- 2026-02-20T00:10:40Z 78094336 3011280896 71.18245941876734 2105856 0 hiroshima-01 2731110400 dlp.srv.world 280170496 0 4230369280 1219088384 28.817540581232663 997523456 2026-02-20T00:10:50Z 79810560 3009245184 71.13433804057881 2105856 0 hiroshima-01 2728972288 dlp.srv.world 280272896 0 4230369280 1221124096 28.86566195942119 996061184 2026-02-20T00:11:00Z 80244736 3009110016 71.13114285852605 2105856 0 hiroshima-01 2728787968 dlp.srv.world 280322048 0 4230369280 1221259264 28.868857141473946 996007936 2026-02-20T00:11:10Z 80674816 3008577536 71.11855577771215 2105856 0 hiroshima-01 2728296448 dlp.srv.world 280281088 0 4230369280 1221791744 28.881444222287847 995921920 2026-02-20T00:11:20Z 81522688 3006189568 71.06210756144674 2105856 0 hiroshima-01 2725298176 dlp.srv.world 280891392 0 4230369280 1224179712 28.93789243855326 999161856 2026-02-20T00:11:30Z 82968576 3005648896 71.0493268332357 2105856 0 hiroshima-01 2725298176 dlp.srv.world 280350720 0 4230369280 1224720384 28.950673166764297 996020224 2026-02-20T00:11:40Z 84418560 3005067264 71.03557786803898 2105856 0 hiroshima-01 2724438016 dlp.srv.world 280629248 0 4230369280 1225302016 28.96442213196102 997523456 ..... .....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 ---- ---------- ---------- -- ------- -------- ------ ------- ---- --------- ------------ ------------ ----- 2026-02-20T00:10:40Z 110043023 2721156 hiroshima-01 0 0 0 0 dlp.srv.world vtnet0 77067 39326 -1 2026-02-20T00:10:50Z 110043403 2721156 hiroshima-01 0 0 0 0 dlp.srv.world vtnet0 77074 39326 -1 2026-02-20T00:11:00Z 110043663 2721156 hiroshima-01 0 0 0 0 dlp.srv.world vtnet0 77079 39326 -1 2026-02-20T00:11:10Z 110043871 2721156 hiroshima-01 0 0 0 0 dlp.srv.world vtnet0 77083 39326 -1 2026-02-20T00:11:20Z 110044183 2721156 hiroshima-01 0 0 0 0 dlp.srv.world vtnet0 77089 39326 -1 2026-02-20T00:11:30Z 110044561 2721156 hiroshima-01 0 0 0 0 dlp.srv.world vtnet0 77095 39326 -1 2026-02-20T00:11:40Z 110044881 2721288 hiroshima-01 0 0 0 0 dlp.srv.world vtnet0 77101 39328 -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 ---- ------- -- ---- ---- ------- -------- ------- ----- ------- ---- ------- 2026-02-20T00:10:40Z 14 hiroshima-01 dlp.srv.world 14 3 8 0 41 0 2 0 2026-02-20T00:10:50Z 14 hiroshima-01 dlp.srv.world 15 2 7 0 40 0 2 0 2026-02-20T00:11:00Z 14 hiroshima-01 dlp.srv.world 16 2 6 0 40 0 2 0 2026-02-20T00:11:10Z 14 hiroshima-01 dlp.srv.world 16 3 6 0 41 0 2 0 2026-02-20T00:11:20Z 14 hiroshima-01 dlp.srv.world 18 2 4 0 40 0 2 0 2026-02-20T00:11:30Z 14 hiroshima-01 dlp.srv.world 16 3 6 0 41 0 2 0 2026-02-20T00:11:40Z 14 hiroshima-01 dlp.srv.world 16 3 6 0 41 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 ---- -- ---- ---- -- --- ----- ---- ------------ 2026-02-20T00:10:40Z hiroshima-01 2147483648 dlp.srv.world 0 0 2147483648 0 0 2026-02-20T00:10:50Z hiroshima-01 2147483648 dlp.srv.world 0 0 2147483648 0 0 2026-02-20T00:11:00Z hiroshima-01 2147483648 dlp.srv.world 0 0 2147483648 0 0 2026-02-20T00:11:10Z hiroshima-01 2147483648 dlp.srv.world 0 0 2147483648 0 0 2026-02-20T00:11:20Z hiroshima-01 2147483648 dlp.srv.world 0 0 2147483648 0 0 2026-02-20T00:11:30Z hiroshima-01 2147483648 dlp.srv.world 0 0 2147483648 0 0 2026-02-20T00:11:40Z 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_physical_cpus n_unique_users n_users uptime uptime_format ---- -- ---- ----- ------ ----- ------ --------------- -------------- ------- ------ ------------- 2026-02-20T00:10:40Z hiroshima-01 dlp.srv.world 0.0908203125 0.19384765625 0.2001953125 2 2 1 1 2133 0:35 2026-02-20T00:10:50Z hiroshima-01 dlp.srv.world 0.07666015625 0.19091796875 0.193359375 2 2 1 1 2143 0:35 2026-02-20T00:11:00Z hiroshima-01 dlp.srv.world 0.064453125 0.18798828125 0.1865234375 2 2 1 1 2153 0:35 2026-02-20T00:11:10Z hiroshima-01 dlp.srv.world 0.05419921875 0.18505859375 0.1796875 2 2 1 1 2163 0:36 2026-02-20T00:11:20Z hiroshima-01 dlp.srv.world 0.04541015625 0.18212890625 0.17333984375 2 2 1 1 2173 0:36 2026-02-20T00:11:30Z hiroshima-01 dlp.srv.world 0.0380859375 0.17919921875 0.16748046875 2 2 1 1 2183 0:36 2026-02-20T00:11:40Z hiroshima-01 dlp.srv.world 0.03173828125 0.17626953125 0.16162109375 2 2 1 1 2193 0:36 ..... ..... |
| Sponsored Link |
|
|