InfluxDB : Install Telegraf2022/10/28 |
Install Telegraf which can collect or send various metrics.
Telegraf supports many Input /Output plugins, refer to the official site below.
⇒ https://docs.influxdata.com/telegraf/v1.24/plugins/
|
|
[1] | Install Telegraf. |
root@dlp:~# apt -y install telegraf
|
[2] | Configure Telegraf. As an example, configure it to get CPU related metrics on the system and send them to InfluxDB. |
root@dlp:~#
mv /etc/telegraf/telegraf.conf /etc/telegraf/telegraf.conf.org root@dlp:~# vi /etc/telegraf/telegraf.conf # create new [global_tags] # set any tag if you need to add it on data dc = "hiroshima-01" [agent] # collection interval for all inputs interval = "10s" # if set [true], then always collect on :00, :10, :20 ... round_interval = true # the size of writes that Telegraf sends to output plugins metric_batch_size = 1000 # cost of higher maximum memory usage metric_buffer_limit = 10000 # it is used to jitter the collection by a random amount collection_jitter = "0s" # flushing interval for all outputs flush_interval = "10s" # jitter the flush interval by a random amount # if flush_interval=10s, flush_jitter=5s, then flushes will happen every 10-15s flush_jitter = "0s" [[outputs.influxdb]] # InfluxDB access URL url = "https://dlp.srv.world:8086" database = "telegraf" # if auth is enabled, set admin username and password username = "admin" password = "adminpassword" # if HTTPS is enabled, set the path to certificate # it needs [_telegraf] user can read certificate tls_cert = "/etc/telegraf/server.crt" tls_key = "/etc/telegraf/server.key" # if using self signed certificate, set [true] insecure_skip_verify = true # settings for CPU related metrics [[inputs.cpu]] percpu = true totalcpu = true collect_cpu_time = false report_active = false
root@dlp:~#
systemctl restart telegraf
# change retention policy # follow means 30 days retention (default is infinite) 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 # verify data 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] | For other System related metrics, configure like follows. |
root@dlp:~#
vi /etc/telegraf/telegraf.conf # add to the end # memory [[inputs.mem]] # swap [[inputs.swap]] # disk [[inputs.disk]] ignore_fs = ["tmpfs", "devtmpfs", "devfs", "iso9660", "overlay", "aufs", "squashfs"] # disk IO [[inputs.diskio]] # kernel statistics (/proc/stat) [[inputs.kernel]] # processes [[inputs.processes]] # system (Uptime and so on) [[inputs.system]] # networking [[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 |
|