docker.recipes

Telegraf

intermediate

Plugin-driven server agent for collecting and reporting metrics.

Overview

Telegraf is InfluxData's plugin-driven server agent designed to collect, process, aggregate, and write metrics from diverse sources including system statistics, application metrics, IoT sensors, and third-party APIs. Originally developed as part of the TICK stack (Telegraf, InfluxDB, Chronograf, Kapacitor), Telegraf has become the de facto standard for metrics collection with over 300 input plugins and numerous output destinations, making it one of the most versatile monitoring agents available. This monitoring stack combines Telegraf's comprehensive data collection capabilities with InfluxDB's purpose-built time-series database engine to create a powerful metrics pipeline. Telegraf continuously gathers metrics from configured sources and pushes them directly to InfluxDB using its native line protocol, while InfluxDB stores and indexes the time-stamped data for fast retrieval and analysis. The push-based architecture ensures reliable data delivery even during network interruptions through Telegraf's built-in buffering and retry mechanisms. This combination is ideal for infrastructure teams, DevOps engineers, and system administrators who need comprehensive monitoring without the complexity of agent-server architectures like Prometheus. Organizations running hybrid environments, IoT deployments, or custom applications benefit from Telegraf's extensive plugin ecosystem and InfluxDB's flexible querying capabilities through both InfluxQL and Flux languages, making it particularly valuable for teams requiring both operational monitoring and business analytics from the same data store.

Key Features

  • 300+ input plugins including Docker containers, system metrics, SNMP devices, databases, message queues, and cloud services
  • Native InfluxDB line protocol integration with automatic schema creation and tag/field optimization
  • Built-in data processing with aggregation, transformation, and filtering processors before storage
  • Automatic service discovery for dynamic environments including Docker, Kubernetes, and cloud platforms
  • Multiple output destinations supporting simultaneous writes to InfluxDB, Prometheus, Kafka, and other systems
  • InfluxDB 2.0 organization and bucket-based data isolation with token-based authentication
  • Flux query language support for advanced analytics, predictions, and cross-measurement joins
  • Configurable data retention policies and downsampling for long-term storage optimization

Common Use Cases

  • 1Infrastructure monitoring for servers, containers, and network devices with centralized metrics storage
  • 2IoT sensor data collection and analysis for manufacturing, environmental monitoring, or smart building systems
  • 3Application performance monitoring with custom metrics, database query times, and business KPIs
  • 4DevOps pipeline monitoring including build times, deployment frequencies, and error rates
  • 5Network monitoring through SNMP polling of switches, routers, and other network infrastructure
  • 6Database performance tracking for MySQL, PostgreSQL, MongoDB, and other database systems
  • 7Cloud resource monitoring across AWS, Azure, and GCP with cost and utilization metrics

Prerequisites

  • Minimum 1GB RAM for InfluxDB with additional memory scaling based on cardinality and retention periods
  • Port 8086 available for InfluxDB HTTP API and web interface access
  • Docker socket access (/var/run/docker.sock) mounted for container monitoring capabilities
  • Understanding of time-series concepts including tags, fields, and measurement schemas for optimal data modeling
  • Telegraf configuration knowledge for input/output plugin setup and metric collection intervals
  • Network connectivity from monitored systems to Telegraf agent for remote monitoring scenarios

For development & testing. Review security settings, change default credentials, and test thoroughly before production use. See Terms

docker-compose.yml

docker-compose.yml
1services:
2 influxdb:
3 image: influxdb:2
4 container_name: influxdb
5 restart: unless-stopped
6 environment:
7 DOCKER_INFLUXDB_INIT_MODE: setup
8 DOCKER_INFLUXDB_INIT_USERNAME: admin
9 DOCKER_INFLUXDB_INIT_PASSWORD: ${INFLUXDB_PASSWORD}
10 DOCKER_INFLUXDB_INIT_ORG: myorg
11 DOCKER_INFLUXDB_INIT_BUCKET: telegraf
12 volumes:
13 - influxdb_data:/var/lib/influxdb2
14 ports:
15 - "8086:8086"
16 networks:
17 - telegraf-network
18
19 telegraf:
20 image: telegraf:latest
21 container_name: telegraf
22 restart: unless-stopped
23 volumes:
24 - ./telegraf/telegraf.conf:/etc/telegraf/telegraf.conf:ro
25 - /var/run/docker.sock:/var/run/docker.sock:ro
26 depends_on:
27 - influxdb
28 networks:
29 - telegraf-network
30
31volumes:
32 influxdb_data:
33
34networks:
35 telegraf-network:
36 driver: bridge

.env Template

.env
1INFLUXDB_PASSWORD=changeme123

Usage Notes

  1. 1Docs: https://docs.influxdata.com/telegraf/
  2. 2InfluxDB UI at http://localhost:8086 - admin/INFLUXDB_PASSWORD
  3. 3Create ./telegraf/telegraf.conf or generate: telegraf config > telegraf.conf
  4. 4300+ input plugins: system stats, Docker, SNMP, databases, etc.
  5. 5Output to InfluxDB, Prometheus, Kafka, and many more
  6. 6TICK stack component - pairs with InfluxDB, Chronograf, Kapacitor

Individual Services(2 services)

Copy individual services to mix and match with your existing compose files.

influxdb
influxdb:
  image: influxdb:2
  container_name: influxdb
  restart: unless-stopped
  environment:
    DOCKER_INFLUXDB_INIT_MODE: setup
    DOCKER_INFLUXDB_INIT_USERNAME: admin
    DOCKER_INFLUXDB_INIT_PASSWORD: ${INFLUXDB_PASSWORD}
    DOCKER_INFLUXDB_INIT_ORG: myorg
    DOCKER_INFLUXDB_INIT_BUCKET: telegraf
  volumes:
    - influxdb_data:/var/lib/influxdb2
  ports:
    - "8086:8086"
  networks:
    - telegraf-network
telegraf
telegraf:
  image: telegraf:latest
  container_name: telegraf
  restart: unless-stopped
  volumes:
    - ./telegraf/telegraf.conf:/etc/telegraf/telegraf.conf:ro
    - /var/run/docker.sock:/var/run/docker.sock:ro
  depends_on:
    - influxdb
  networks:
    - telegraf-network

Quick Start

terminal
1# 1. Create the compose file
2cat > docker-compose.yml << 'EOF'
3services:
4 influxdb:
5 image: influxdb:2
6 container_name: influxdb
7 restart: unless-stopped
8 environment:
9 DOCKER_INFLUXDB_INIT_MODE: setup
10 DOCKER_INFLUXDB_INIT_USERNAME: admin
11 DOCKER_INFLUXDB_INIT_PASSWORD: ${INFLUXDB_PASSWORD}
12 DOCKER_INFLUXDB_INIT_ORG: myorg
13 DOCKER_INFLUXDB_INIT_BUCKET: telegraf
14 volumes:
15 - influxdb_data:/var/lib/influxdb2
16 ports:
17 - "8086:8086"
18 networks:
19 - telegraf-network
20
21 telegraf:
22 image: telegraf:latest
23 container_name: telegraf
24 restart: unless-stopped
25 volumes:
26 - ./telegraf/telegraf.conf:/etc/telegraf/telegraf.conf:ro
27 - /var/run/docker.sock:/var/run/docker.sock:ro
28 depends_on:
29 - influxdb
30 networks:
31 - telegraf-network
32
33volumes:
34 influxdb_data:
35
36networks:
37 telegraf-network:
38 driver: bridge
39EOF
40
41# 2. Create the .env file
42cat > .env << 'EOF'
43INFLUXDB_PASSWORD=changeme123
44EOF
45
46# 3. Start the services
47docker compose up -d
48
49# 4. View logs
50docker compose logs -f

One-Liner

Run this command to download and set up the recipe in one step:

terminal
1curl -fsSL https://docker.recipes/api/recipes/telegraf/run | bash

Troubleshooting

  • Error 'database not found' or 401 authentication: Verify InfluxDB initialization completed and bucket 'telegraf' exists with correct token permissions
  • High memory usage in InfluxDB: Check metric cardinality using SHOW CARDINALITY and avoid high-cardinality tags like timestamps or UUIDs
  • Telegraf metrics not appearing: Verify telegraf.conf output configuration matches InfluxDB organization/bucket and check Telegraf logs for connection errors
  • Permission denied accessing Docker socket: Ensure telegraf container user has docker group membership or run with appropriate privileges
  • Clock synchronization errors: Verify system clocks are synchronized between Telegraf agents and InfluxDB as time skew affects data ingestion
  • Plugin-specific errors in logs: Check plugin documentation for required permissions, credentials, or network access to monitored services

Community Notes

Loading...
Loading notes...

Download Recipe Kit

Get all files in a ready-to-deploy package

Includes docker-compose.yml, .env template, README, and license

Components

telegrafinfluxdb

Tags

#telegraf#metrics#influxdb#agent#plugins

Category

Monitoring & Observability
Ad Space