This guide uses Docker to run Telegraf.
For Docker installation, see Docker.
Create a directory to store your configuration and compose files.
mkdir -p /opt/telegraf
cd /opt/telegraf
Define a container for Telegraf.
services:
telegraf:
image: telegraf:latest
hostname: "${HOSTNAME}"
volumes:
- ./telegraf.conf:/etc/telegraf/telegraf.conf:ro
- /var/run/docker.sock:/var/run/docker.sock:ro
- /sys:/sys:ro
- /var/run/utmp:/var/run/utmp:ro
- /:/hostfs:ro
environment:
- HOST_ETC=/hostfs/etc
- HOST_PROC=/hostfs/proc
- HOST_SYS=/hostfs/sys
- HOST_VAR=/hostfs/var
- HOST_RUN=/hostfs/run
- HOST_MOUNT_PREFIX=/hostfs
networks:
- monitoring
networks:
monitoring:
driver: bridge
Create telegraf.conf with your output settings:
[global_tags]
hostname = "${HOSTNAME}"
[agent]
interval = "10s"
round_interval = true
metric_batch_size = 1000
metric_buffer_limit = 10000
collection_jitter = "0s"
flush_interval = "10s"
flush_jitter = "0s"
[[outputs.influxdb_v2]]
urls = ["http://influxdb:8086"]
token = "${INFLUXDB_TOKEN}"
organization = "${INFLUXDB_ORG}"
bucket = "${INFLUXDB_BUCKET}"
[[inputs.cpu]]
percpu = true
totalcpu = true
collect_cpu_time = false
report_active = false
[[inputs.mem]]
[[inputs.disk]]
[[inputs.net]]
[[inputs.docker]]
Start the container in the background.
docker compose up -d
telegraf is the official Docker image on Docker HubAny questions?
Feel free to contact us. Find all contact information on our contact page.