Telegraf 是 InfluxData 开源的一款采集器,可以采集操作系统、各种中间件的监控指标,采集目标列表,看起来是非常丰富,Telegraf是一个大一统的设计,即一个二进制可以采集CPU、内存、mysql、mongodb、redis、snmp等,不像Prometheus的exporter,每个监控对象一个exporter,管理起来略麻烦。一个二进制分发起来确实比较方便。

    这里提供快速安装的教程,Telegraf的更多知识,请参考Telegraf官网,笔者之前也写了一个Telegraf调研笔记,讲解了Telegraf的基本用法,一定要看!!!,大家亦可参考。

    Telegraf下载地址在这里,根据自己的平台选择对应的二进制下载即可。笔者的环境是CentOS,下面是安装脚本,/opt/telegraf/telegraf.conf 是一个经过删减的干净的配置文件,指定了opentsdb output plugin,这个plugin的写入地址配置的是n9e-server,所以,Telegraf采集的数据会被推送给n9e-server,二者贯通:

    1. #!/bin/sh
    2. version=1.20.4
    3. tarball=telegraf-${version}_linux_amd64.tar.gz
    4. wget https://dl.influxdata.com/telegraf/releases/$tarball
    5. tar xzvf $tarball
    6. mkdir -p /opt/telegraf
    7. cp -far telegraf-${version}/usr/bin/telegraf /opt/telegraf
    8. cat <<EOF > /opt/telegraf/telegraf.conf
    9. [global_tags]
    10. [agent]
    11. interval = "10s"
    12. round_interval = true
    13. metric_batch_size = 1000
    14. metric_buffer_limit = 10000
    15. collection_jitter = "0s"
    16. flush_interval = "10s"
    17. flush_jitter = "0s"
    18. precision = ""
    19. hostname = ""
    20. omit_hostname = false
    21. [[outputs.opentsdb]]
    22. host = "http://127.0.0.1"
    23. port = 19000
    24. http_batch_size = 50
    25. http_path = "/opentsdb/put"
    26. debug = false
    27. separator = "_"
    28. [[inputs.cpu]]
    29. percpu = true
    30. totalcpu = true
    31. collect_cpu_time = false
    32. report_active = true
    33. [[inputs.disk]]
    34. ignore_fs = ["tmpfs", "devtmpfs", "devfs", "iso9660", "overlay", "aufs", "squashfs"]
    35. [[inputs.diskio]]
    36. [[inputs.kernel]]
    37. [[inputs.mem]]
    38. [[inputs.processes]]
    39. [[inputs.system]]
    40. fielddrop = ["uptime_format"]
    41. [[inputs.net]]
    42. ignore_protocol_stats = true
    43. EOF
    44. cat <<EOF > /etc/systemd/system/telegraf.service
    45. [Unit]
    46. Description="telegraf"
    47. After=network.target
    48. [Service]
    49. Type=simple
    50. ExecStart=/opt/telegraf/telegraf --config telegraf.conf
    51. WorkingDirectory=/opt/telegraf
    52. SuccessExitStatus=0
    53. LimitNOFILE=65536
    54. StandardOutput=syslog
    55. StandardError=syslog
    56. SyslogIdentifier=telegraf
    57. KillMode=process
    58. KillSignal=SIGQUIT
    59. TimeoutStopSec=5
    60. Restart=always
    61. [Install]
    62. WantedBy=multi-user.target
    63. EOF
    64. systemctl daemon-reload
    65. systemctl enable telegraf
    66. systemctl restart telegraf
    67. systemctl status telegraf

    /opt/telegraf/telegraf.conf的内容是个删减版,只是为了让大家快速跑起来,如果要采集更多监控对象,比如mysql、redis、tomcat等,还是要仔细去阅读从tarball里解压出来的那个配置文件,那里有很详细的注释,也可以参考官方提供的各个采集插件下的README

    💡 Telegraf告警策略 | Telegraf监控大盘