InfluxDB : Telegraf インストール2022/10/28 |
各種メトリクス収集/送信エージェント Telegraf をインストールします。
Telegraf では多くの Input /Output プラグインに対応しており、様々なデータを 収集/送信 可能です。
⇒ https://docs.influxdata.com/telegraf/v1.24/plugins/
|
|
[1] | Telegraf をインストールします。 |
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 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' 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-10-27T08:31:20Z cpu-total hiroshima-01 dlp.srv.world 0 0 99.89989989991591 0.05005005005006808 0 0 0 0 0 0.050050050050050296 2022-10-27T08:31:20Z cpu0 hiroshima-01 dlp.srv.world 0 0 99.89989989987953 0.1001001001000997 0 0 0 0 0 0 2022-10-27T08:31:20Z cpu1 hiroshima-01 dlp.srv.world 0 0 99.7999999999957 0 0 0 0 0 0.0999999999999615 0.0999999999999615 2022-10-27T08:31:30Z cpu-total hiroshima-01 dlp.srv.world 0 0 99.69969969967498 0.15015015015013178 0 0 0 0 0.05005005005004985 0.10010010010008193 2022-10-27T08:31:30Z cpu0 hiroshima-01 dlp.srv.world 0 0 99.50049950050669 0.19980019980022748 0 0 0 0 0.09990009990011374 0.19980019980024524 2022-10-27T08:31:30Z cpu1 hiroshima-01 dlp.srv.world 0 0 99.70000000001153 0.20000000000006848 0 0 0 0 0 0.10000000000003424 2022-10-27T08:31:40Z cpu-total hiroshima-01 dlp.srv.world 0 0 99.94994994997616 0.050050050050050296 0 0 0 0 0 0 2022-10-27T08:31:40Z cpu0 hiroshima-01 dlp.srv.world 0 0 100 0 0 0 0 0 0 0 2022-10-27T08:31:40Z cpu1 hiroshima-01 dlp.srv.world 0 0 99.89989989987953 0.1001001001000997 0 0 0 0 0 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:~#
root@dlp:~# systemctl restart telegraf
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 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 mode path total used used_percent ---- -- ------ ---- ------ ---- ----------- ------------ ----------- ---- ---- ----- ---- ------------ 2022-10-28T01:08:40Z hiroshima-01 dm-0 20023279616 ext4 dlp.srv.world 1652275 1769472 117197 rw / 28422893568 7073099776 26.103486645482526 2022-10-28T01:08:40Z hiroshima-01 vda2 1658224640 ext4 dlp.srv.world 130752 131072 320 rw /boot 2040373248 257998848 13.463922638234566 2022-10-28T01:08:50Z hiroshima-01 dm-0 20023267328 ext4 dlp.srv.world 1652275 1769472 117197 rw / 28422893568 7073112064 26.103531994714697 2022-10-28T01:08:50Z hiroshima-01 vda2 1658224640 ext4 dlp.srv.world 130752 131072 320 rw /boot 2040373248 257998848 13.463922638234566 ..... .....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-10-28T01:08:40Z hiroshima-01 dlp.srv.world 8796 0 0 0 dm-0 379225088 432 9068 4908 47300608 4476 10454 2022-10-28T01:08:40Z hiroshima-01 dlp.srv.world 8812 0 2362 3126 vda3 380339200 400 6730 5125 47300608 4725 7328 2022-10-28T01:08:40Z hiroshima-01 dlp.srv.world 12 0 0 0 loop0 1106944 3 51 3 0 0 0 2022-10-28T01:08:40Z hiroshima-01 dlp.srv.world 12 0 0 0 loop2 354304 1 43 1 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 ---- --------- ---------------- -- ------------- ---- ---------- ---------------- 2022-10-28T01:08:40Z 1666917503 362548 hiroshima-01 256 dlp.srv.world 196453 913 2022-10-28T01:08:50Z 1666917503 364254 hiroshima-01 256 dlp.srv.world 197646 920 2022-10-28T01:09:00Z 1666917503 365696 hiroshima-01 256 dlp.srv.world 198548 920 2022-10-28T01:09:10Z 1666917503 367043 hiroshima-01 256 dlp.srv.world 199434 920 ..... .....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-10-28T01:08:40Z 76500992 3654725632 88.8464372485761 23785472 398647296 5063028736 650018816 hiroshima-01 450560 3398119424 0 0 dlp.srv.world 2097152 0 0 492388352 0 0 158912512 2494464 1048576 56885248 27918336 28966912 0 3006263296 3006263296 4113530880 292978688 7.122316485442307 0 14073748835531776 14225408 0 0 2022-10-28T01:08:50Z 77434880 3651424256 88.76618074640538 23830528 403968000 5063028736 650018816 hiroshima-01 577536 3391909888 0 0 dlp.srv.world 2097152 0 0 492716032 0 0 159346688 2494464 1048576 62238720 33009664 29229056 0 3006263296 3006263296 4113530880 293822464 7.142828693193134 0 14073748835531776 14274560 0 0 2022-10-28T01:09:00Z 77451264 3651457024 88.76697733699766 23855104 404025344 5063028736 650280960 hiroshima-01 94208 3391909888 0 0 dlp.srv.world 2097152 0 0 494219264 0 0 159444992 2498560 1048576 62242816 33013760 29229056 0 3006263296 3006263296 4113530880 293740544 7.1408372167124705 0 14073748835531776 14274560 0 0 2022-10-28T01:09:10Z 77475840 3650756608 88.74995021308798 23879680 404037632 5063028736 654475264 hiroshima-01 208896 3391135744 0 0 dlp.srv.world 2097152 0 0 496001024 0 0 159514624 2502656 1048576 62242816 33013760 29229056 0 3006263296 3006263296 4113530880 294477824 7.158760505038435 0 14073748835531776 14274560 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 icmpmsg_intype3 icmpmsg_outtype3 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-10-28T02:06:10Z hiroshima-01 dlp.srv.world 0 0 0 15 0 0 2 15 0 0 0 0 0 0 0 0 15 0 0 0 15 0 0 0 0 0 0 15 15 all 64 2 0 0 0 0 0 64367 0 0 65056 0 0 0 48800 0 0 0 0 62 3 6 28 0 0 64096 -1 213 54109 38 5 1 120000 200 43 0 213 0 0 0 223 0 0 0 0 0 0 0 0 0 0 0 2022-10-28T02:06:10Z 335485795 11545329 hiroshima-01 2634 0 0 0 dlp.srv.world enp1s0 59697 40624 2022-10-28T02:06:20Z hiroshima-01 dlp.srv.world 0 0 0 15 0 0 2 15 0 0 0 0 0 0 0 0 15 0 0 0 15 0 0 0 0 0 0 15 15 all 64 2 0 0 0 0 0 64388 0 0 65079 0 0 0 48824 0 0 0 0 62 3 4 28 0 0 64117 -1 216 54133 38 5 1 120000 200 43 0 213 0 0 0 223 0 0 0 0 0 0 0 0 0 0 0 2022-10-28T02:06:20Z 335487074 11546103 hiroshima-01 2639 0 0 0 dlp.srv.world enp1s0 59715 40637 ..... .....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-10-28T01:08:40Z 0 hiroshima-01 0 dlp.srv.world 54 0 0 61 0 115 148 0 0 2022-10-28T01:08:50Z 0 hiroshima-01 0 dlp.srv.world 54 0 0 61 0 115 147 0 0 2022-10-28T01:09:00Z 0 hiroshima-01 0 dlp.srv.world 54 0 0 61 0 115 147 0 0 2022-10-28T01:09:10Z 0 hiroshima-01 0 dlp.srv.world 54 0 0 61 0 115 147 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-10-28T01:08:40Z hiroshima-01 3006263296 dlp.srv.world 0 0 3006263296 0 0 2022-10-28T01:08:50Z hiroshima-01 3006263296 dlp.srv.world 0 0 3006263296 0 0 2022-10-28T01:09:00Z hiroshima-01 3006263296 dlp.srv.world 0 0 3006263296 0 0 2022-10-28T01:09:10Z hiroshima-01 3006263296 dlp.srv.world 0 0 3006263296 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-10-28T01:08:40Z hiroshima-01 dlp.srv.world 0.24 0.02 0.05 2 1 1817 0:30 2022-10-28T01:08:50Z hiroshima-01 dlp.srv.world 0.36 0.03 0.08 2 1 1827 0:30 2022-10-28T01:09:00Z hiroshima-01 dlp.srv.world 0.31 0.03 0.08 2 1 1837 0:30 2022-10-28T01:09:10Z hiroshima-01 dlp.srv.world 0.26 0.02 0.08 2 1 1847 0:30 ..... ..... |
Sponsored Link |