InfluxDB : Telegraf インストール2023/07/06 |
各種メトリクス収集/送信エージェント 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 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 ---- --- -- ---- ----------- ---------------- ---------- ------------ --------- ---------- ------------- ----------- ------------ ---------- 2023-07-06T00:40:50Z cpu-total hiroshima-01 dlp.srv.world 0 0 99.84962406015165 0.05012531328320741 0 0 0 0 0.05012531328320741 0.05012531328320741 2023-07-06T00:40:50Z cpu0 hiroshima-01 dlp.srv.world 0 0 99.89969909729425 0 0 0 0 0 0.10030090270812425 0 2023-07-06T00:40:50Z cpu1 hiroshima-01 dlp.srv.world 0 0 99.69969969970224 0.2002002002002003 0 0 0 0 0 0.1001001001001046 2023-07-06T00:41:00Z cpu-total hiroshima-01 dlp.srv.world 0 0 99.6996996996977 0.25025025025024344 0 0 0 0 0.0500500500500478 0 2023-07-06T00:41:00Z cpu0 hiroshima-01 dlp.srv.world 0 0 100 0 0 0 0 0 0 0 2023-07-06T00:41:00Z cpu1 hiroshima-01 dlp.srv.world 0 0 99.49949949949769 0.40040040040039127 0 0 0 0 0.10010010010010004 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 label mode path total used used_percent ---- -- ------ ---- ------ ---- ----------- ------------ ----------- ----- ---- ---- ----- ---- ------------ 2023-07-06T00:42:10Z hiroshima-01 dm-0 26850648064 ext4 dlp.srv.world 1836871 1872304 35433 debian--vg-root rw / 30006984704 1606123520 5.644081990323362 2023-07-06T00:42:10Z hiroshima-01 vda1 390417408 ext2 dlp.srv.world 124088 124440 352 rw /boot 476286976 60337152 13.385810672664078 2023-07-06T00:42:20Z hiroshima-01 dm-0 26850643968 ext4 dlp.srv.world 1836871 1872304 35433 debian--vg-root rw / 30006984704 1606127616 5.644096384085451 2023-07-06T00:42:20Z hiroshima-01 vda1 390417408 ext2 dlp.srv.world 124088 124440 352 rw /boot 476286976 60337152 13.385810672664078 2023-07-06T00:42:30Z hiroshima-01 dm-0 26850627584 ext4 dlp.srv.world 1836871 1872304 35433 debian--vg-root rw / 30006984704 1606144000 5.644153959133806 2023-07-06T00:42:30Z hiroshima-01 vda1 390417408 ext2 dlp.srv.world 124088 124440 352 rw /boot 476286976 60337152 13.385810672664078 2023-07-06T00:42:40Z hiroshima-01 dm-0 26850615296 ext4 dlp.srv.world 1836871 1872304 35433 debian--vg-root rw / 30006984704 1606156288 5.644197140420074 2023-07-06T00:42:40Z hiroshima-01 vda1 390417408 ext2 dlp.srv.world 124088 124440 352 rw /boot 476286976 60337152 13.385810672664078 2023-07-06T00:42:50Z hiroshima-01 dm-0 26850611200 ext4 dlp.srv.world 1836871 1872304 35433 debian--vg-root rw / 30006984704 1606160384 5.644211534182162 2023-07-06T00:42:50Z hiroshima-01 vda1 390417408 ext2 dlp.srv.world 124088 124440 352 rw /boot 476286976 60337152 13.385810672664078 ..... .....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 ---- -- ---- ------- ---------------- ------------ ------------- ---- ---------- --------- ----- ---------------- ----------- ---------- ------ 2023-07-06T00:42:10Z hiroshima-01 dlp.srv.world 12852 1 0 0 dm-0 216466432 1468 7177 10496 652558336 8772 14078 2023-07-06T00:42:10Z hiroshima-01 dlp.srv.world 12864 0 1765 6816 vda5 219669504 875 5543 12099 652558336 10967 7676 2023-07-06T00:42:10Z hiroshima-01 dlp.srv.world 20 0 0 0 dm-1 2351104 4 108 4 0 0 0 2023-07-06T00:42:10Z hiroshima-01 dlp.srv.world 60 0 31 0 vda1 4510720 26 181 37 1024 5 2 2023-07-06T00:42:10Z hiroshima-01 dlp.srv.world 8 0 0 0 vda2 2048 0 2 0 0 0 0 2023-07-06T00:42:10Z hiroshima-01 dlp.srv.world 12912 0 1796 6816 vda 226467840 907 5827 19087 652559360 10987 7683 2023-07-06T00:42:20Z hiroshima-01 dlp.srv.world 8 0 0 0 vda2 2048 0 2 0 0 0 0 2023-07-06T00:42:20Z hiroshima-01 dlp.srv.world 12944 0 1796 6833 vda 226467840 907 5827 19143 652682240 11015 7702 2023-07-06T00:42:20Z hiroshima-01 dlp.srv.world 20 0 0 0 dm-1 2351104 4 108 4 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 ---- --------- ---------------- -- ------------- ---- ---------- ---------------- 2023-07-06T00:42:10Z 1688600262 326271 hiroshima-01 256 dlp.srv.world 197483 2241 2023-07-06T00:42:20Z 1688600262 327887 hiroshima-01 256 dlp.srv.world 198368 2246 2023-07-06T00:42:30Z 1688600262 329862 hiroshima-01 256 dlp.srv.world 199985 2255 2023-07-06T00:42:40Z 1688600262 331479 hiroshima-01 256 dlp.srv.world 200899 2260 2023-07-06T00:42:50Z 1688600262 332989 hiroshima-01 256 dlp.srv.world 201781 2261 2023-07-06T00:43:00Z 1688600262 334920 hiroshima-01 256 dlp.srv.world 202809 2266 2023-07-06T00:43:10Z 1688600262 336435 hiroshima-01 256 dlp.srv.world 203543 2266 2023-07-06T00:43:20Z 1688600262 337797 hiroshima-01 256 dlp.srv.world 204260 2266 2023-07-06T00:43:30Z 1688600262 339376 hiroshima-01 256 dlp.srv.world 205095 2266 ..... .....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 ---- ------ --------- ----------------- -------- ------ ------------ ------------ -- ----- ---- --------- ---------- ---- -------------- --------------- ---------------- -------- -------- --------- ------ ----------- ------ ---- ------------ ---------- ----------- --------- ---------- ----- ---- ------------ ------------- ------------- ------------ ---------- -------------- 2023-07-06T00:42:10Z 247738368 3720712192 90.6681505584557 21102592 597368832 3079430144 298844160 hiroshima-01 73728 3334131712 0 0 dlp.srv.world 2097152 0 0 416002048 0 0 133947392 1642496 589824 59518976 35606528 23912448 0 1027600384 1027600384 4103659520 151056384 3.6810164991465957 0 14073748835531776 19406848 0 0 2023-07-06T00:42:20Z 247754752 3708395520 90.36801181790052 21135360 602419200 3079430144 298844160 hiroshima-01 253952 3319271424 0 0 dlp.srv.world 2097152 0 0 418578432 0 0 135032832 1646592 589824 64823296 40636416 24186880 0 1027600384 1027600384 4103659520 160833536 3.9192709632986316 0 14073748835531776 19439616 0 0 2023-07-06T00:42:30Z 332931072 3719110656 90.6291235389821 21159936 602492928 3079430144 294649856 hiroshima-01 503808 3329859584 0 0 dlp.srv.world 2097152 0 0 329220096 0 0 134438912 1650688 589824 64827392 40640512 24186880 0 1027600384 1027600384 4103659520 150147072 3.6588579356603153 0 14073748835531776 19390464 0 0 2023-07-06T00:42:40Z 332947456 3713957888 90.50355834589318 21184512 602537984 3079430144 294649856 hiroshima-01 454656 3324661760 0 0 dlp.srv.world 2097152 0 0 331956224 0 0 135307264 1654784 589824 64864256 40677376 24186880 0 1027600384 1027600384 4103659520 155275264 3.7838242486550153 0 14073748835531776 19423232 0 0 2023-07-06T00:42:50Z 335060992 3709534208 90.39575992893289 21192704 602558464 3079430144 298844160 hiroshima-01 131072 3320209408 0 0 dlp.srv.world 2097152 0 0 332398592 0 0 135311360 1658880 589824 64864256 40677376 24186880 0 1027600384 1027600384 4103659520 159698944 3.8916226656152992 0 14073748835531776 19423232 0 0 2023-07-06T00:43:00Z 335077376 3709304832 90.39017038138681 21213184 602570752 3079430144 298844160 hiroshima-01 126976 3319951360 0 0 dlp.srv.world 2097152 0 0 334651392 0 0 135442432 1662976 589824 64864256 40677376 24186880 0 1027600384 1027600384 4103659520 159924224 3.8971123998123507 0 14073748835531776 19423232 0 0 2023-07-06T00:43:10Z 337203200 3709345792 90.39116851487718 21237760 602583040 3079430144 303038464 hiroshima-01 163840 3319951360 0 0 dlp.srv.world 2097152 0 0 334774272 0 0 135507968 1667072 589824 64864256 40677376 24186880 0 1027600384 1027600384 4103659520 159887360 3.896214079671015 0 14073748835531776 19423232 0 0 2023-07-06T00:43:20Z 339316736 3709370368 90.39176739497141 21254144 602591232 3079430144 303038464 hiroshima-01 20480 3319951360 0 0 dlp.srv.world 2097152 0 0 331501568 0 0 135573504 1667072 589824 64864256 40677376 24186880 0 1027600384 1027600384 4103659520 159862784 3.8956151995767914 0 14073748835531776 19423232 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 ---- ---------- ---------- -- ------- -------- ------ ------- ---- ------------------- ---------------- ----------------- ------------------- --------------- ------------ ------------- ----------- ---------------- ---------------- ----------------- ---------------- -------------------- ----------------- -------------------- ----------------- -------------------- ---------------- ------------- -------------- ------------ ----------------- ----------------- ------------------ ----------------- --------------------- ------------------ --------- ------------- ------------- ---------------- -------------- ------------ ---------- --------------- ------------- ------------- -------------- ------------- ------------------ -------------- -------------- -------------- ------------- ----------- ------------- --------------- ------------ ------------ --------------- ---------------- ------------- --------------- ---------------- ---------- ---------- ----------- ----------- ----------- ---------------- --------------- ---------------- ---------- ---------- ---------------- ---------------- --------------- ------------ ------------- ----------- ---------------- ---------------- ---------------- -------------------- -------------------- ------------------- ---------------- ----------------- --------------- -------------------- -------------------- -------------------- 2023-07-06T00:42: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 14113 0 0 14329 0 0 1 10452 0 0 0 0 53 3 2 12 0 0 14831 -1 15 11178 36 0 1 120000 200 8 0 52 0 0 0 52 0 0 0 0 0 0 0 0 0 0 0 2023-07-06T00:42:10Z 62162348 710362 hiroshima-01 1934 0 0 0 dlp.srv.world enp1s0 16385 10271 2023-07-06T00:42: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 14134 0 0 14350 0 0 1 10473 0 0 0 0 54 3 2 13 0 0 14871 -1 16 11218 37 0 1 120000 200 8 0 52 0 0 0 52 0 0 0 0 0 0 0 0 0 0 0 2023-07-06T00:42:20Z 62162692 710446 hiroshima-01 1939 0 0 0 dlp.srv.world enp1s0 16392 10273 2023-07-06T00:42: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 all 64 2 0 0 0 0 0 14173 0 0 14392 0 0 1 10512 0 0 0 0 55 3 2 14 0 0 14908 -1 17 11255 38 0 1 120000 200 8 0 54 0 0 0 54 0 0 0 0 0 0 0 0 0 0 0 2023-07-06T00:42:30Z 62163866 710614 hiroshima-01 1944 0 0 0 dlp.srv.world enp1s0 16402 10275 2023-07-06T00:42: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 all 64 2 0 0 0 0 0 14187 0 0 14407 0 0 1 10526 0 0 0 0 56 3 2 15 0 0 14941 -1 18 11288 39 0 1 120000 200 8 0 54 0 0 0 54 0 0 0 0 0 0 0 0 0 0 0 2023-07-06T00:42:40Z 62164343 710614 hiroshima-01 1949 0 0 0 dlp.srv.world enp1s0 16408 10275 2023-07-06T00:42:50Z 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 14208 0 0 14428 0 0 1 10547 0 0 0 0 56 3 2 15 0 0 14962 -1 18 11309 39 0 1 120000 200 8 0 54 0 0 0 54 0 0 0 0 0 0 0 0 0 0 0 2023-07-06T00:42:50Z 62164673 710614 hiroshima-01 1954 0 0 0 dlp.srv.world enp1s0 16414 10275 ..... .....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 ---- ------- -- ---- ---- ---- ------ ------- -------- ------- ----- ------------- ------- ------- 2023-07-06T00:42:10Z 0 hiroshima-01 0 dlp.srv.world 50 0 0 55 0 105 121 0 0 2023-07-06T00:42:20Z 1 hiroshima-01 0 dlp.srv.world 50 0 0 54 0 105 121 0 0 2023-07-06T00:42:30Z 1 hiroshima-01 0 dlp.srv.world 50 0 0 54 0 105 120 0 0 2023-07-06T00:42:40Z 1 hiroshima-01 0 dlp.srv.world 50 0 0 54 0 105 120 0 0 2023-07-06T00:42:50Z 1 hiroshima-01 0 dlp.srv.world 50 0 0 54 0 105 121 0 0 2023-07-06T00:43:00Z 1 hiroshima-01 0 dlp.srv.world 50 0 0 54 0 105 121 0 0 2023-07-06T00:43:10Z 1 hiroshima-01 0 dlp.srv.world 50 0 0 54 0 105 121 0 0 2023-07-06T00:43:20Z 1 hiroshima-01 0 dlp.srv.world 50 0 0 54 0 105 121 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 ---- -- ---- ---- -- --- ----- ---- ------------ 2023-07-06T00:42:10Z hiroshima-01 1027600384 dlp.srv.world 0 0 1027600384 0 0 2023-07-06T00:42:20Z hiroshima-01 1027600384 dlp.srv.world 0 0 1027600384 0 0 2023-07-06T00:42:30Z hiroshima-01 1027600384 dlp.srv.world 0 0 1027600384 0 0 2023-07-06T00:42:40Z hiroshima-01 1027600384 dlp.srv.world 0 0 1027600384 0 0 2023-07-06T00:42:50Z hiroshima-01 1027600384 dlp.srv.world 0 0 1027600384 0 0 2023-07-06T00:43:00Z hiroshima-01 1027600384 dlp.srv.world 0 0 1027600384 0 0 2023-07-06T00:43:10Z hiroshima-01 1027600384 dlp.srv.world 0 0 1027600384 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 ---- -- ---- ----- ------ ----- ------ -------------- ------- ------ ------------- 2023-07-06T00:42:10Z hiroshima-01 dlp.srv.world 0 0 0 2 1 1 3868 1:04 2023-07-06T00:42:20Z hiroshima-01 dlp.srv.world 0 0 0 2 1 1 3878 1:04 2023-07-06T00:42:30Z hiroshima-01 dlp.srv.world 0 0 0 2 1 1 3888 1:04 2023-07-06T00:42:40Z hiroshima-01 dlp.srv.world 0 0 0 2 1 1 3898 1:04 2023-07-06T00:42:50Z hiroshima-01 dlp.srv.world 0 0 0 2 1 1 3908 1:05 2023-07-06T00:43:00Z hiroshima-01 dlp.srv.world 0 0 0 2 1 1 3918 1:05 2023-07-06T00:43:10Z hiroshima-01 dlp.srv.world 0 0 0 2 1 1 3928 1:05 ..... ..... |
Sponsored Link |
|