Installing and setting up telegraf to monitor docker as a service on Linux
Telegraf is a data collection and aggregation agent that needs to be installed on target server.
Let's say you would like to gather metric data for example cpu usage or memory
usage for Server A, install Telegraf on server A. All these day will be sent to
a central influxdb datastorem, lets call our influxdb ServerDatastore.
Grafana and influxdb can live on the same or separate server.
In this setup, we are going to setup telegraf to monitor docker application and send all the metric of interest to ServerDataStore.
Installing
telegraf on target server
curl
ttps://dl.influxdata.com/telegraf/releases/telegraf_1.13.2-1_amd64.deb
--output telegraf.deb
Placing telegraf executable
in a specific folder.
After
extracting our telegraf.deb, you can move the binary to /usr/local/bin folder
and configuration file to /user/local/etc/telegraf/telegraf.conf
Next
we need to specify what metrics we would like telegraf to send over. Example below shows the key configuration
for DEV environment that we are interested in.
The
first is target database and server dns. Here we setup our hostname "urls
= "http://ServerDataStore:8086"
and database is called "dev_docker_telegraf".
# Configuration for sending metrics to InfluxDB
[[outputs.influxdb]]
## The full HTTP or UDP URL for your InfluxDB instance.
##
## Multiple URLs can be specified for a single cluster, only ONE of the
## urls will be written to each interval.
# urls = ["unix:///var/run/influxdb.sock"]
# urls = ["udp://127.0.0.1:8089"]
## The target database for metrics; will be created as needed.
## For UDP url endpoint database needs to be configured on server side.
database = "dev_docker_telegraf
Docker
metrics is configured by uncommenting the following sections. It should look
something below :-
# # Read metrics about docker containers
[[inputs.docker]]
# ## Docker Endpoint
# ## To use TCP, set endpoint = "tcp://[ip]:[port]"
# ## To use environment variables (ie, docker-machine), set endpoint = "ENV"
endpoint = "unix:///var/run/docker.sock"
#
# ## Set to true to collect Swarm metrics(desired_replicas, running_replicas)
gather_services = false
Example
of setup for dev environment are shown below :-
Please make sure you have the configuration updated,
saved and place in a specific folder before starting the service.
Running
telegraf as an agent
We
will setup telegraf to run as an agent. First, we need to create a
configuration file call "telegraf.service".
Creating
the configuration
Create
a file called 'telegraf.service' under '/etc/systemd/system'. It should contain
the following :-
[Unit]
Description=telegraf.servicee
[Service]
ExecStart=/usr/local/bin/telegraf
--config /usr/local/etc/telegraf/telegraf.conf
[Install]
WantedBy=multi-user.target:
Running the service
sudo systemctl start
telegraf.service
Checking on service
status
sudo systemctl status
telegraf.service
Stop the service
This
might come in handy if you would like to shutdown a service for testing
purposes.
sudo systemctl stop
telegraf.service
Comments