# InfluxDB + Chronograf

> InfluxDB time-series database with Chronograf admin UI.

- Category: Database Stacks
- Difficulty: intermediate
- Components: influxdb, chronograf
- Tags: influxdb, timeseries, metrics, iot
- Source: https://docker.recipes/databases/influxdb-chronograf

## Overview

InfluxDB is a purpose-built time-series database designed specifically for handling high-velocity, timestamped data from IoT sensors, application metrics, and monitoring systems. Originally developed by InfluxData in 2013, it addresses the unique challenges of time-series data through specialized storage engines, query optimization for temporal patterns, and built-in retention policies that automatically manage data lifecycle. Unlike traditional relational databases, InfluxDB excels at ingesting millions of data points per second while providing sub-second query performance for analytics and alerting.

This stack combines InfluxDB 2.7 with Chronograf to create a comprehensive time-series data platform. While InfluxDB 2.x includes a built-in UI, Chronograf provides advanced visualization capabilities, alerting rules, and administrative tools that complement InfluxDB's native interface. The configuration establishes automatic initialization with organization, bucket, and authentication setup, plus inter-service connectivity for data exploration and dashboard creation.

This combination is ideal for DevOps teams implementing observability solutions, IoT developers collecting sensor data, and organizations requiring real-time analytics on timestamped metrics. The stack provides both the high-performance data storage capabilities of InfluxDB and the intuitive visualization tools of Chronograf, making it accessible for both technical operators and business users who need to analyze time-series patterns.

## Features

- High-performance time-series storage engine optimized for timestamped data ingestion and retrieval
- Flux query language with advanced time-series functions for complex temporal analytics
- Built-in data retention policies with automatic downsampling and expiration management
- Chronograf's drag-and-drop dashboard builder with time-series specific visualizations
- Real-time alerting system with customizable thresholds and notification channels
- Multi-tenant organization and bucket structure for data isolation and access control
- Native support for both push and pull data collection patterns
- Advanced time-series functions including aggregations, transformations, and predictive analytics

## Use cases

- IoT sensor networks collecting temperature, humidity, and environmental data from distributed devices
- Application performance monitoring with metrics collection from microservices architectures
- Financial data analysis for real-time trading metrics and market data aggregation
- Industrial equipment monitoring for predictive maintenance and operational efficiency
- Website analytics tracking user behavior patterns and performance metrics over time
- Energy management systems monitoring power consumption and grid performance data
- DevOps infrastructure monitoring collecting system metrics, logs, and performance indicators

## Prerequisites

- Minimum 1GB RAM allocated to Docker (InfluxDB requires 256MB minimum, 1GB+ recommended for production)
- Available ports 8086 (InfluxDB) and 8888 (Chronograf) on the host system
- Basic understanding of time-series data concepts and Flux or InfluxQL query syntax
- Environment variables configured for INFLUX_USER, INFLUX_PASSWORD, INFLUX_ORG, INFLUX_BUCKET, and INFLUX_TOKEN
- Docker Compose version 3.8 or higher with volume and network support
- Understanding of InfluxDB's bucket and organization concepts for proper data modeling

## docker-compose.yml

```yaml
services:
  influxdb:
    image: influxdb:2.7
    container_name: influxdb
    restart: unless-stopped
    environment:
      DOCKER_INFLUXDB_INIT_MODE: setup
      DOCKER_INFLUXDB_INIT_USERNAME: ${INFLUX_USER}
      DOCKER_INFLUXDB_INIT_PASSWORD: ${INFLUX_PASSWORD}
      DOCKER_INFLUXDB_INIT_ORG: ${INFLUX_ORG}
      DOCKER_INFLUXDB_INIT_BUCKET: ${INFLUX_BUCKET}
      DOCKER_INFLUXDB_INIT_ADMIN_TOKEN: ${INFLUX_TOKEN}
    volumes:
      - influxdb_data:/var/lib/influxdb2
      - influxdb_config:/etc/influxdb2
    ports:
      - "8086:8086"
    networks:
      - influx-network

  chronograf:
    image: chronograf:latest
    container_name: chronograf
    restart: unless-stopped
    environment:
      INFLUXDB_URL: http://influxdb:8086
    volumes:
      - chronograf_data:/var/lib/chronograf
    ports:
      - "8888:8888"
    depends_on:
      - influxdb
    networks:
      - influx-network

volumes:
  influxdb_data:
  influxdb_config:
  chronograf_data:

networks:
  influx-network:
    driver: bridge
```

## .env

```bash
INFLUX_USER=admin
INFLUX_PASSWORD=changeme123
INFLUX_ORG=myorg
INFLUX_BUCKET=mybucket
INFLUX_TOKEN=my-super-secret-token
```

## Usage notes

- Docs: https://docs.influxdata.com/influxdb/v2/
- Access InfluxDB UI at http://localhost:8086 | Chronograf at http://localhost:8888
- Use INFLUX_TOKEN for API authentication in your applications
- Query with Flux or InfluxQL - Flux recommended for v2.x
- Retention policies control data lifecycle - configure per bucket
- Backup: influx backup /path/to/backup, restore with influx restore

## Troubleshooting

- Connection refused on port 8086: Ensure InfluxDB container is fully started and DOCKER_INFLUXDB_INIT_MODE environment variables are properly set
- Chronograf shows 'Unable to connect to InfluxDB': Verify the INFLUXDB_URL environment variable points to http://influxdb:8086 and both containers are on the same network
- Authentication failures with INFLUX_TOKEN: Check that the token matches between InfluxDB initialization and client applications, and verify token has proper read/write permissions
- High memory usage during data ingestion: Configure appropriate retention policies and batch write sizes, monitor for inefficient Flux queries causing memory spikes
- Empty dashboards in Chronograf: Ensure data is being written to the correct bucket and organization, verify Chronograf is connected to the right InfluxDB instance
- Time zone issues in data visualization: Configure proper timezone settings in both InfluxDB and Chronograf, ensure client applications send UTC timestamps

