content.md 5.7 KB

Telegraf

Telegraf is an open source agent written in Go for collecting metrics and data on the system it's running on or from other services. Telegraf writes data it collects to InfluxDB in the correct format.

Telegraf Official Docs

%%LOGO%%

Using this image

Exposed Ports

  • 8125 StatsD
  • 8092 UDP
  • 8094 TCP

Using the default configuration

The default configuration requires a running InfluxDB instance as an output plugin. Ensure that InfluxDB is running on port 8086 before starting the Telegraf container.

Minimal example to start an InfluxDB container:

$ docker run -d --name influxdb -p 8083:8083 -p 8086:8086 influxdb

Starting Telegraf using the default config, which connects to InfluxDB at http://localhost:8086/:

$ docker run --net=container:influxdb %%IMAGE%%

Using a custom config file

First, generate a sample configuration and save it as telegraf.conf on the host:

$ docker run --rm %%IMAGE%% telegraf config > telegraf.conf

Once you've customized telegraf.conf, you can run the Telegraf container with it mounted in the expected location:

$ docker run -v $PWD/telegraf.conf:/etc/telegraf/telegraf.conf:ro %%IMAGE%%

Modify $PWD to the directory where you want to store the configuration file.

Read more about the Telegraf configuration here.

Using the container with input plugins

These examples assume you are using a custom configuration file that takes advantage of Docker's built-in service discovery capability. In order to do so, we'll first create a new network:

$ docker network create influxdb

Next, we'll start our InfluxDB container named influxdb:

$ docker run -d --name=influxdb \
      --net=influxdb \
      influxdb

The telegraf.conf configuration can now resolve the influxdb container by name:

[[outputs.influxdb]]
	urls = ["http://influxdb:8086"]

Finally, we start our Telegraf container and verify functionality:

$ docker run -d --name=telegraf \
      --net=influxdb \
      -v $PWD/telegraf.conf:/etc/telegraf/telegraf.conf:ro \
      %%IMAGE%%
$ docker logs -f telegraf

Aerospike

Start an instance of aerospike:

$ docker run -d --name aerospike \
      --net=influxdb \
      -p 3000-3003:3000-3003 \
      aerospike

Edit your Telegraf config file and set the correct connection parameter for Aerospike:

[[inputs.aerospike]]
	servers = ["aerospike:3000"]

Restart your telegraf container to pick up the changes:

$ docker restart telegraf

Nginx

Create an nginx_status.conf configuration file to expose metric data:

server {
    listen 8090;
    location /nginx_status {
        stub_status;
        access_log off;
    }
}

Start an Nginx container utilizing it:

$ docker run -d --name=nginx \
      --net=influxdb \
      -p 8090:8090 -p 8080:80 \
      -v $PWD/nginx_status.conf:/etc/nginx/conf.d/nginx_status.conf:ro \
      nginx

Verify the status page: http://localhost:8090/nginx_status.

Configure the nginx input plugin in your Telegraf configuration file:

[[inputs.nginx]]
  urls = ["http://nginx:8090/nginx_status"]

Restart your telegraf container to pick up the changes:

$ docker restart telegraf

StatsD

Telegraf has a StatsD plugin, allowing Telegraf to run as a StatsD server that metrics can be sent to. In order for this to work, you must first configure the StatsD plugin in your config file.

Run Telegraf with the UDP port 8125 exposed:

$ docker run -d --name=telegraf \
      --net=influxdb \
      -p 8125:8125/udp \
      -v $PWD/telegraf.conf:/etc/telegraf/telegraf.conf:ro \
      %%IMAGE%%

Send Mock StatsD data:

$ for i in {1..50}; do echo $i;echo "foo:1|c" | nc -u -w0 127.0.0.1 8125; done

Check that the measurement foo is added in the DB.

Supported Plugins Reference

Monitoring the host filesystem

One of the more common use cases for Telegraf is running it in a container to monitor the host filesystem using the inputs that take information from the /proc filesystem. This section only applies to monitoring a Linux host.

To do this, you can mount the host's /proc filesystem inside of the container and set the location of /proc to an alternate location by using the HOST_PROC environment variable to change the location of where /proc is located. As an example:

$ docker run -d --name=telegraf \
      --net=influxdb \
      -e HOST_PROC=/host/proc \
      -v /proc:/host/proc:ro \
      -v $PWD/telegraf.conf:/etc/telegraf/telegraf.conf:ro \
      %%IMAGE%%

Monitoring docker containers

To monitor other docker containers, you can use the docker plugin and mount the docker socket into the container. An example configuration is below:

[[inputs.docker]]
  endpoint = "unix:///var/run/docker.sock"

Then you can start the telegraf container.

$ docker run -d --name=telegraf \
      --net=influxdb \
      -v /var/run/docker.sock:/var/run/docker.sock \
      -v $PWD/telegraf.conf:/etc/telegraf/telegraf.conf:ro \
      %%IMAGE%%

Refer to the docker plugin documentation for more information.