|
| 1 | +<!--nologo--> |
| 2 | + |
| 3 | +[Telegraf](https://github.com/influxdata/telegraf) is an agent for collecting metrics and writing them into InfluxDB or other possible outputs. |
| 4 | + |
| 5 | +In this playground, you've got Telegraf and InfluxDB already installed and configured. |
| 6 | + |
| 7 | +## Configuration |
| 8 | + |
| 9 | +The configuration file is located at `/etc/telegraf/telegraf.conf`. It enables several [inputs](https://github.com/influxdata/telegraf/blob/master/README.md#input-plugins) such as `cpu` and `mem` that read metrics about the system’s cpu and memory usage. It also specifies InfluxDB as the desired [output](https://github.com/influxdata/telegraf/blob/master/README.md#output-plugins). |
| 10 | + |
| 11 | +You can view and edit the config using `nano` or `vim`: |
| 12 | +```bash |
| 13 | +nano /etc/telegraf/telegraf.conf |
| 14 | +``` |
| 15 | + |
| 16 | +## How to use it |
| 17 | + |
| 18 | +Run a single collection of metrics and print them to stdout: |
| 19 | + |
| 20 | +``` |
| 21 | +telegraf --test |
| 22 | +``` |
| 23 | + |
| 24 | +Collect metrics only from `cpu` and `mem` inputs and print them to stdout: |
| 25 | + |
| 26 | +``` |
| 27 | +telegraf --input-filter cpu:mem --test |
| 28 | +``` |
| 29 | + |
| 30 | +## Start the Telegraf service |
| 31 | + |
| 32 | +```bash |
| 33 | +sudo service telegraf start |
| 34 | +``` |
| 35 | + |
| 36 | +Once Telegraf is up and running, it will start collecting metrics and writing them to the local InfluxDB every 10 seconds. |
| 37 | + |
| 38 | +You can check Telegraf and InfluxDB logs at `/var/log/telegraf/telegraf.log` and `/var/log/influxdb/influxd.log` respectively. |
| 39 | + |
| 40 | +## Explore metrics in InfluxDB |
| 41 | + |
| 42 | +Enter the interactive InfluxDB shell and connect to the `telegraf` [database](https://docs.influxdata.com/influxdb/v1.7/concepts/glossary/#database): |
| 43 | + |
| 44 | +```bash |
| 45 | +influx -database telegraf |
| 46 | +``` |
| 47 | + |
| 48 | +Once in the InfluxDB shell, list all [measurements](https://docs.influxdata.com/influxdb/v1.7/concepts/glossary/#measurement) in the database: |
| 49 | + |
| 50 | +```bash |
| 51 | +> SHOW MEASUREMENTS |
| 52 | +name: measurements |
| 53 | +name |
| 54 | +---- |
| 55 | +cpu |
| 56 | +disk |
| 57 | +diskio |
| 58 | +kernel |
| 59 | +mem |
| 60 | +processes |
| 61 | +swap |
| 62 | +system |
| 63 | +``` |
| 64 | + |
| 65 | +List all [field keys](https://docs.influxdata.com/influxdb/v1.7/concepts/glossary/#field-key) by measurement: |
| 66 | + |
| 67 | +```bash |
| 68 | +> SHOW FIELD KEYS |
| 69 | +name: cpu |
| 70 | +fieldKey fieldType |
| 71 | +-------- --------- |
| 72 | +usage_guest float |
| 73 | +usage_guest_nice float |
| 74 | +usage_idle float |
| 75 | +usage_iowait float |
| 76 | +usage_irq float |
| 77 | +usage_nice float |
| 78 | +usage_softirq float |
| 79 | +usage_steal float |
| 80 | +usage_system float |
| 81 | +usage_user float |
| 82 | +... |
| 83 | +``` |
| 84 | + |
| 85 | +Select a data sample in the [field](https://docs.influxdata.com/influxdb/v1.7/concepts/glossary/#field) `usage_idle` in the measurement `cpu`: |
| 86 | + |
| 87 | +```bash |
| 88 | +> SELECT usage_idle FROM cpu WHERE cpu = 'cpu-total' LIMIT 5 |
| 89 | +name: cpu |
| 90 | +time usage_idle |
| 91 | +---- ---------- |
| 92 | +1555419650000000000 99.74840657497393 |
| 93 | +1555419660000000000 99.83283182882222 |
| 94 | +1555419670000000000 99.81608426684404 |
| 95 | +1555419680000000000 99.81602274627767 |
| 96 | +1555419690000000000 99.71576659421494 |
| 97 | +``` |
| 98 | + |
| 99 | +That’s it! You now have the foundation for using Telegraf to collect metrics and write them to your output of choice. |
| 100 | + |
| 101 | +## What's next? |
| 102 | + |
| 103 | +You can explore the official Telegraf [documentation](https://docs.influxdata.com/telegraf) and check available [input](https://github.com/influxdata/telegraf/blob/master/README.md#input-plugins) and [output](https://github.com/influxdata/telegraf/blob/master/README.md#output-plugins) plugins. |
| 104 | + |
| 105 | +You can also improve this playground or create your own. Please send a PR or open an issue in [github.com/rootnroll/library](https://github.com/rootnroll/library). |
0 commit comments