Telegraf is an agent written in Go for collecting metrics and writing them into InfluxDB or other possible outputs. This guide will get you up and running with Telegraf. It walks you through the download, installation, and configuration processes, and it shows how to use Telegraf to get data into InfluxDB.
Follow the instructions in the Telegraf section on the Downloads page.
Note: Telegraf will start automatically using the default configuration when installed from a deb package.
/usr/local/etc/telegraf.conf
/etc/telegraf/telegraf.conf
Before starting the Telegraf server you need to edit and/or create an initial configuration that specifies your desired inputs (where the metrics come from) and outputs (where the metrics go). There are several ways to create and edit the configuration file. Here, we’ll generate a configuration file and simultaneously specify the desired inputs with the -input-filter
flag and the desired output with the -output-filter
flag.
In the example below, we create a configuration file called telegraf.conf
with two inputs: one that reads metrics about the system’s cpu usage (cpu
) and one that reads metrics about the system’s memory usage (mem
). We specify InfluxDB as the desired output.
telegraf -sample-config -input-filter cpu:mem -output-filter influxdb > telegraf.conf
Start the Telegraf server and direct it to the relevant configuration file:
telegraf -config telegraf.conf
sudo service telegraf start
systemctl start telegraf
Once Telegraf is up and running it will start collecting data and writing them to the desired output.
Returning to our sample configuration, we show what the cpu
and mem
data look like in InfluxDB below. Note that we used the default input and output configuration settings to get these data.
telegraf
database:> SHOW MEASUREMENTS name: measurements ------------------ name cpu mem
> SHOW FIELD KEYS name: cpu --------- fieldKey fieldType usage_guest float usage_guest_nice float usage_idle float usage_iowait float usage_irq float usage_nice float usage_softirq float usage_steal float usage_system float usage_user float name: mem --------- fieldKey fieldType active integer available integer available_percent float buffered integer cached integer free integer inactive integer total integer used integer used_percent float
usage_idle
in the measurement cpu_usage_idle
:> SELECT usage_idle FROM cpu WHERE cpu = 'cpu-total' LIMIT 5 name: cpu --------- time usage_idle 2016-01-16T00:03:00Z 97.56189047261816 2016-01-16T00:03:10Z 97.76305923519121 2016-01-16T00:03:20Z 97.32533433320835 2016-01-16T00:03:30Z 95.68857785553611 2016-01-16T00:03:40Z 98.63715928982245
Notice that the timestamps occur at rounded ten second intervals (that is, :00
, :10
, :20
, and so on) - this is a configurable setting.
That’s it! You now have the foundation for using Telegraf to collect metrics and write them to your output of choice.
© 2015 InfluxData, Inc.
Licensed under the MIT license.
https://docs.influxdata.com/telegraf/v1.3/introduction/getting_started/