Telegraf is an agent for collecting metrics and writing them into InfluxDB or other possible outputs.
In this playground, you've got Telegraf and InfluxDB already installed and configured.
The configuration file is located at
/etc/telegraf/telegraf.conf. It enables several inputs such as
mem that read metrics about the system’s cpu and memory usage. It also specifies InfluxDB as the desired output.
You can view and edit the config using
How to use it
Run a single collection of metrics and print them to stdout:
Collect metrics only from
mem inputs and print them to stdout:
telegraf --input-filter cpu:mem --test
Start the Telegraf service
sudo service telegraf start
Once Telegraf is up and running, it will start collecting metrics and writing them to the local InfluxDB every 10 seconds.
You can check Telegraf and InfluxDB logs at
Explore metrics in InfluxDB
Enter the interactive InfluxDB shell and connect to the
influx -database telegraf
Once in the InfluxDB shell, list all measurements in the database:
> SHOW MEASUREMENTS name: measurements name ---- cpu disk diskio kernel mem processes swap system
List all field keys by measurement:
> 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 ...
Select a data sample in the field
usage_idle in the measurement
> SELECT usage_idle FROM cpu WHERE cpu = 'cpu-total' LIMIT 5 name: cpu time usage_idle ---- ---------- 1555419650000000000 99.74840657497393 1555419660000000000 99.83283182882222 1555419670000000000 99.81608426684404 1555419680000000000 99.81602274627767 1555419690000000000 99.71576659421494
That’s it! You now have the foundation for using Telegraf to collect metrics and write them to your output of choice.
You can also improve this playground or create your own. Please send a PR or open an issue in github.com/rootnroll/library.