机器数据采集工具:telegraf的介绍安装

前言

Telegraf 是一个用 Go 编写的用于收集机器数据的代理程序。它可部署到机器上收集系统和服务的统计数据,并通过配置写入到 InfluxDB 数据库,然后在通过Grafana或者Chrongraf用于数据展示。

核心功能

  • 完全由GO编写,编译产物仅为一个二进制程序,安装运行无需外部依赖

  • 运行时内存占用很小

  • 对于当前大部分流行的服务来说,telegraf已经有现成的插件支持

  • 插件系统可以支持对其他服务轻松扩展

安装&配置

1. MacOs(默认安装最新版本telegraf)

brew update
brew install telegraf

2. Ubuntu & Debian

wget https://dl.influxdata.com/telegraf/releases/telegraf_1.15.2-1_amd64.deb sudo dpkg -i telegraf_1.15.2-1_amd64.deb

3. RedHat & CentOS

wget https://dl.influxdata.com/telegraf/releases/telegraf-1.15.2-1.x86_64.rpm sudo yum localinstall telegraf-1.15.2-1.x86_64.rpm

4. Windows Binaries (64-bit)

wget https://dl.influxdata.com/telegraf/releases/telegraf-1.15.2_windows_amd64.zip unzip telegraf-1.15.2_windows_amd64.zip

5. 二进制方式

1)Linux Binaries (64-bit)

wget https://dl.influxdata.com/telegraf/releases/telegraf-1.15.2_linux_amd64.tar.gz tar xf telegraf-1.15.2_linux_amd64.tar.gz

2)Linux Binaries (32-bit)

wget https://dl.influxdata.com/telegraf/releases/telegraf-1.15.2_linux_i386.tar.gz tar xf telegraf-1.15.2_linux_i386.tar.gz

配置文件地址

MacOS: /usr/local/etc/telegraf.conf

Linux debian and RPM package: /etc/telegraf/telegraf.conf

如果你是二进制包的安装方式,可以生成一个telegraf.conf

#配置生成一个telegraf.conf,该配置收集系统的cpu和内存信息,然后输出到influxdb
telegraf -sample-config -input-filter cpu:mem -output-filter influxdb > telegraf.conf

配置文件内容

 

[[outputs.influxdb]]

urls = ["http://localhost:8086"]

#influxdb中的数据库名,不存在则自动创建

database = "telegraf"

#写influxDB超时时间

timeout = "5s"

# 收集cpu的配置

[[inputs.cpu]]

## Whether to report per-cpu stats or not

percpu = true

## Whether to report total system cpu stats or not

totalcpu = true

## If true, collect raw CPU time metrics.

collect_cpu_time = false

## If true, compute and report the sum of all non-idle CPU states.

report_active = false

 

# 收集disk的信息

[[inputs.disk]]

## By default stats will be gathered for all mount points.

## Set mount_points will restrict the stats to only the specified mount points.

mount_points = ["/data"]

 

## Ignore mount points by filesystem type.

ignore_fs = ["tmpfs", "devtmpfs", "devfs", "iso9660", "overlay", "aufs", "squashfs"]

 

 

# 收集硬盘的io

[[inputs.diskio]]

## By default, telegraf will gather stats for all devices including

## disk partitions.

## Setting devices will restrict the stats to the specified devices.

devices = ["sda", "sdb", "vd*"]

## Uncomment the following line if you need disk serial numbers.

# skip_serial_number = false

#

## On systems which support it, device metadata can be added in the form of

## tags.

## Currently only Linux is supported via udev properties. You can view

## available properties for a device by running:

## 'udevadm info -q property -n /dev/sda'

## Note: Most, but not all, udev properties can be accessed this way. Properties

## that are currently inaccessible include DEVTYPE, DEVNAME, and DEVPATH.

# device_tags = ["ID_FS_TYPE", "ID_FS_USAGE"]

#

## Using the same metadata source as device_tags, you can also customize the

## name of the device via templates.

## The 'name_templates' parameter is a list of templates to try and apply to

## the device. The template may contain variables in the form of '$PROPERTY' or

## '${PROPERTY}'. The first template which does not contain any variables not

## present for the device is used as the device name tag.

## The typical use case is for LVM volumes, to get the VG/LV name instead of

## the near-meaningless DM-0 name.

# name_templates = ["$ID_FS_LABEL","$DM_VG_NAME/$DM_LV_NAME"]

# 收集内存信息

[[inputs.mem]]

interval = "10m"

 

# 收集进程状态

[[inputs.processes]]

interval = "10m"

fielddrop = ["wait","idle","unknown"]

 

# 收集swap分区信息

[[inputs.swap]]

interval = "1h"

fieldpass = ["used_percent"]

 

# 收集系统运行信息

[[inputs.system]]

## Uncomment to remove deprecated metrics.

interval = "2m"

fielddrop = ["uptime_format"]

启动方式

1. MacOS启动方式

brew services start telegraf

2. Linux debian and RPM package

sudo systemctl start telegraf 或者 sudo service telegraf start

3.二进制启动方式

nohup telegraf -config /usr/local/etc/telegraf.conf &

启动后,查看日志没有报错即可

传送门:2021最新测试资料与大厂招聘合集

博主:测试生财(一个不为996而996的测开码农)

座右铭:专注测试开发与自动化运维,努力读书思考写作,为内卷的人生奠定财务自由。

内容范畴:技术提升,职场杂谈,事业发展,阅读写作,投资理财,健康人生。

csdn:https://blog.csdn.net/ccgshigao

博客园:https://www.cnblogs.com/qa-freeroad/

51cto:https://blog.51cto.com/14900374

微信公众号:测试生财(定期分享独家内容和资源)

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

公众号-测试生财

点赞和关注比打赏更重要

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值