本文主要是介绍centos7.9 安装telegraf,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
下载解压软件
# 系统环境: centos7.9
# 软件名:telegraf-1.28.2_linux_amd64.tar.gzuseradd -M -s /sbin/nologin telegraf
cd /opt
wget https://dl.influxdata.com/telegraf/releases/telegraf-1.28.2_linux_amd64.tar.gz
tar -zxvf telegraf-1.28.2_linux_amd64.tar.gz
ln -s /opt/telegraf-1.28.2 /opt/telegraf
ln -s /opt/telegraf/usr/bin/telegraf /usr/bin/
生成配置文件
# 备份原始配置文件
mv /opt/telegraf/etc/telegraf/telegraf.conf /opt/telegraf/etc/telegraf/telegraf.conf.bak# 生成自定义配置文件
# 开启input插件:cpu:disk:diskio:kernel:mem:net:processes:swap:system
# 开启output插件:prometheus_client
telegraf --input-filter cpu:disk:diskio:kernel:mem:net:processes:swap:system --output-filter prometheus_client config | grep -Ev '#|^$' > /opt/telegraf/etc/telegraf/telegraf.conf
修改为最终配置文件
cat /opt/telegraf/etc/telegraf/telegraf.conf
[global_tags]
[agent]interval = "10s"round_interval = truemetric_batch_size = 1000metric_buffer_limit = 10000collection_jitter = "0s"flush_interval = "10s"flush_jitter = "0s"precision = "0s"hostname = ""omit_hostname = false
[[inputs.cpu]]percpu = truetotalcpu = truecollect_cpu_time = falsereport_active = falsecore_tags = false
[[inputs.disk]]# 设置不收及指标数据的文件系统ignore_fs = ["tmpfs", "devtmpfs", "devfs", "iso9660", "overlay", "aufs", "squashfs"]
[[inputs.diskio]]
[[inputs.kernel]]
[[inputs.mem]]
[[inputs.processes]]
[[inputs.swap]]
[[inputs.system]]
[[inputs.net]]ignore_protocol_stats = true
#[[inputs.nstat]]
# proc_net_netstat = "/proc/net/netstat"
# proc_net_snmp = "/proc/net/snmp"
# proc_net_snmp6 = "/proc/net/snmp6"
# dump_zeros = true[[outputs.prometheus_client]]listen = ":9273"# 排除插件自身的指标数据collectors_exclude = ["gocollector", "process"]
设置开机自启
cat /etc/systemd/system/telegraf.service
[Unit]
Description=Telegraf
Documentation=https://github.com/influxdata/telegraf
After=network-online.target
Wants=network-online.target[Service]
Type=notify
#EnvironmentFile=-/etc/default/telegraf
WorkingDirectory=/opt/telegraf
User=telegraf
ExecStart=/usr/bin/telegraf -config /opt/telegraf/etc/telegraf/telegraf.conf -config-directory /opt/telegraf/etc/telegraf/telegraf.d
ExecReload=/bin/kill -HUP $MAINPID
Restart=on-failure
RestartForceExitStatus=SIGPIPE
KillMode=mixed
TimeoutStopSec=5
LimitMEMLOCK=8M:8M[Install]
WantedBy=multi-user.target
systemctl daemon-reload
systemctl enable telegraf
systemctl start telegraf
自定义日志文件路径
cat /etc/rsyslog.d/telegraf.conf
### telegraf Rules ###
if $programname == 'telegraf' then {action(type="omfile" file="/var/log/telegraf/telegraf.log")stop
}
# 创建日志目录
mkdir /var/log/telegraf/
systemctl restart rsyslog.service
systemctl restart telegraf
这篇关于centos7.9 安装telegraf的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!