setting up telegraf as a linux daemon
Installing
telegraf on target server
curl
https://dl.influxdata.com/telegraf/releases/telegraf-1.13.3_linux_amd64.tar.gz
--output telegraf.tar.gz -k
- Placing telegraf executable in a specific folder.
tar
xf telegraf.tar.gz
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
Assuming
we are in your expand tar directory, /telegraf/usr/bin
sudo
cp telegraf /usr/local/bin
Assuming
we are in your expand tar directory, /telegraf/etc/telegraf
sudo
mkdir /usr/local/etc/telegraf
sudo
cp telegraf.conf /usr/local/etc/telegraf
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://WebAppPaymentsInfluxDB.asbbank.co.nz: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.service
[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