Telegraf 介绍
安装
wget https://dl.influxdata.com/telegraf/releases/telegraf-1.18.3-1.x86_64.rpm
sudo yum localinstall telegraf-1.18.3-1.x86_64.rpm
配置
- 配置
/etc/telegraf/telegraf.conf
,参考
[agent]
## Default data collection interval for all inputs
interval = "10m"
[[outputs.influxdb]] # 配置数据库
urls = ["http://127.0.0.1:8086"]
database = "telegraf"
username = "telegraf"
password = "metricsmetricsmetricsmetrics"
- 通过 Telegraf 的
inputs.exec
插件执行,配置如下:
# Read metrics from one or more commands that can output to stdout
[[inputs.exec]]
## Commands array
commands = [
"/tmp/test.sh",
]
## Timeout for each command to complete.
timeout = "5s"
## measurement name suffix (for separating different commands)
name_suffix = "_mycollector"
## Data format to consume.
## Each data format has its own unique set of configuration options, read
## more about them here:
## https://github.com/influxdata/telegraf/blob/master/docs/DATA_FORMATS_INPUT.md
data_format = "influx"
- 其中,采集脚本
/tmp/test.sh
,也可以使用 python 等封装为 InfluxDB Line Protocol
格式
#!/bin/sh
echo 'example,tag1=a,tag2=b i=42i,j=43i,k=44i'
# echo 'example,tag1=a,tag2=b i=42i,j=43i,k=44i to_timestap("2021-05-30")'
systemctl start telegraf.service