Back to Blog
IoT Dashboard

Grafana + InfluxDB IoT Monitoring: Complete Production Setup Guide

Grafana and InfluxDB are the industry standard for IoT monitoring dashboards. This guide covers the complete stack from MQTT ingestion through Telegraf to production-ready Grafana panels with alerting, team access control, and Docker deployment.

October 1, 2024
14 min read
GrafanaInfluxDBIoT MonitoringTelegraf

Grafana + InfluxDB IoT Monitoring: Complete Production Setup Guide

For industrial IoT monitoring, Grafana + InfluxDB is the reference stack. InfluxDB stores time-series telemetry with automatic retention and fast aggregations. Grafana visualizes it with 50+ panel types, threshold alerting, and multi-team access control — all without writing a single line of frontend code.

This guide takes you from a blank server to a production monitoring stack with MQTT ingestion, Flux queries, alerting, and secure team access.

Architecture

IoT Devices → MQTT Broker (Mosquitto / AWS IoT)
                    ↓ Telegraf (MQTT input plugin)
              InfluxDB 2.x (time-series storage)
                    ↓ Flux queries
              Grafana (dashboards + alerting)
                    ↓
              PagerDuty / Slack / Email (alerts)

Step 1: Docker Compose Stack

docker-compose.yml

version: '3.8'

services: mosquitto: image: eclipse-mosquitto:2 ports: - "1883:1883" - "8883:8883" volumes: - ./mosquitto/config:/mosquitto/config - ./mosquitto/data:/mosquitto/data

influxdb: image: influxdb:2.7 ports: - "8086:8086" volumes: - influxdb_data:/var/lib/influxdb2 environment: DOCKER_INFLUXDB_INIT_MODE: setup DOCKER_INFLUXDB_INIT_USERNAME: admin DOCKER_INFLUXDB_INIT_PASSWORD: ${INFLUX_PASSWORD} DOCKER_INFLUXDB_INIT_ORG: codecaracal DOCKER_INFLUXDB_INIT_BUCKET: iot_telemetry DOCKER_INFLUXDB_INIT_RETENTION: 30d

telegraf: image: telegraf:1.31 volumes: - ./telegraf/telegraf.conf:/etc/telegraf/telegraf.conf:ro environment: INFLUX_TOKEN: ${INFLUX_TOKEN} depends_on: - influxdb - mosquitto

grafana: image: grafana/grafana:10.4.0 ports: - "3000:3000" volumes: - grafana_data:/var/lib/grafana - ./grafana/provisioning:/etc/grafana/provisioning environment: GF_SECURITY_ADMIN_PASSWORD: ${GRAFANA_PASSWORD} GF_AUTH_ANONYMOUS_ENABLED: false GF_SMTP_ENABLED: true GF_SMTP_HOST: smtp.sendgrid.net:587 GF_SMTP_USER: apikey GF_SMTP_PASSWORD: ${SENDGRID_KEY} depends_on: - influxdb

volumes: influxdb_data: grafana_data:

Step 2: Telegraf MQTT Input

telegraf/telegraf.conf

[agent] interval = "10s" flush_interval = "10s"

[[inputs.mqtt_consumer]] servers = ["tcp://mosquitto:1883"] topics = ["devices/+/telemetry"] qos = 1 data_format = "json"

# Extract device ID from topic (devices/{deviceId}/telemetry) [[inputs.mqtt_consumer.topic_parsing]] topic = "devices/+/telemetry" tags = "_/device_id/_" fields = ""

# Tag each measurement with the device ID [inputs.mqtt_consumer.tags] measurement = "device_telemetry"

[[outputs.influxdb_v2]] urls = ["http://influxdb:8086"] token = "${INFLUX_TOKEN}" organization = "codecaracal" bucket = "iot_telemetry"

Telegraf reads MQTT messages, parses JSON payloads, extracts the device_id from the topic, and writes tagged measurements to InfluxDB. No code required.

Step 3: Flux Queries for Grafana

Flux is InfluxDB's query language. Key queries for IoT dashboards:

Current value (for stat panels / gauges):

from(bucket: "iot_telemetry")
  |> range(start: -1h)
  |> filter(fn: (r) => r._measurement == "device_telemetry")
  |> filter(fn: (r) => r._field == "temperature")
  |> filter(fn: (r) => r.device_id == v.device_id)  // Dashboard variable
  |> last()

Time-series for a chart:

from(bucket: "iot_telemetry")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r._measurement == "device_telemetry")
  |> filter(fn: (r) => r._field == "temperature" or r._field == "humidity")
  |> filter(fn: (r) => r.device_id =~ /${device_id:regex}/)
  |> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)
  |> pivot(rowKey: ["_time"], columnKey: ["_field"], valueColumn: "_value")

Fleet overview (all devices, latest value):

from(bucket: "iot_telemetry")
  |> range(start: -5m)
  |> filter(fn: (r) => r._measurement == "device_telemetry")
  |> filter(fn: (r) => r._field == "temperature")
  |> group(columns: ["device_id"])
  |> last()
  |> group()
  |> sort(columns: ["device_id"])

Step 4: Grafana Dashboard Variables

Create a device_id variable to make dashboards dynamic:

  • 1. Dashboard → Settings → Variables → Add variable
  • 2. Type: Query, Query type: InfluxDB
  • 3. Query:
  • import "influxdata/influxdb/schema"
    schema.tagValues(bucket: "iot_telemetry", tag: "device_id")
    
  • 4. Multi-value: enabled (select all or specific devices)
  • This creates a dropdown at the top of the dashboard — select one device or all, and every panel updates automatically.

    Step 5: Alerting Rules

    Grafana's unified alerting fires on Flux query results:

    grafana/provisioning/alerting/rules.yaml

    apiVersion: 1 groups: - orgId: 1 name: IoT Alerts interval: 1m rules: - uid: temperature-high title: Temperature Above Threshold condition: C data: - refId: A datasourceUid: influxdb model: query: | from(bucket: "iot_telemetry") |> range(start: -5m) |> filter(fn: (r) => r._field == "temperature") |> last() - refId: B datasourceUid: "-100" model: type: reduce reducer: last - refId: C datasourceUid: "-100" model: type: threshold conditions: - evaluator: { type: "gt", params: [80] } for: 2m labels: severity: critical annotations: summary: "{{ $labels.device_id }} temperature {{ $values.B.Value }}°C"

    Step 6: Panel Types for IoT

    | Measurement | Grafana Panel | Config | |-------------|---------------|--------| | Live temperature | Time series | Line, 1h window | | Current value | Stat | Single color threshold | | Battery level | Gauge | 0–100%, red below 20% | | Device online/offline | State timeline | green/red | | Fleet overview | Table | All devices, last value | | Geolocation | Geomap | Lat/lon tags from devices |

    Role-Based Access Control

    grafana/provisioning/access-control/roles.yaml

    apiVersion: 1 roles: - name: IoT Operator global: true permissions: - action: dashboards:read scope: "dashboards:*" - action: alert.instances:read scope: "global:*"

    Clients get Viewer access — they can see dashboards and receive alerts but cannot edit. Your team gets Editor. Only platform admins get Admin.

    The Grafana + InfluxDB stack handles 10,000+ data points per second on modest hardware ($200/month AWS) and scales further with InfluxDB clustering. [Contact Code Caracal](/contact) to set this up for your IoT fleet.

    Written by CodeCaracal Engineering

    We write from production experience — every technique in our articles has been deployed to real clients. No academic theory.

    More Articles

    Business · 12 min read

    IoT Device Compliance: FCC, CE, and Product Certification Guide for Hardware Startups

    Business · 11 min read

    What to Look for When Hiring an IoT Development Partner: 8 Critical Criteria

    Business · 11 min read

    IoT MVP to Production: Realistic Timeline and Budget for Hardware Startups

    Business · 11 min read

    IoT Development Agency vs Building In-House: A Decision Framework for Founders

    IoT Dashboard · 13 min read

    Next.js IoT Analytics Dashboard: From Sensor Data to Production App

    Business · 11 min read

    How Much Does It Cost to Build an IoT Product in 2024? A Realistic Breakdown

    IoT Dashboard · 11 min read

    IoT Dashboard UX: Design Principles for Industrial Monitoring Interfaces

    IoT Dashboard · 12 min read

    Node.js WebSocket Server: The Real-Time Backend for IoT Dashboards

    Cloud & DevOps · 12 min read

    Containerizing IoT Backend Services with Docker: From Dev to Production

    IoT Dashboard · 12 min read

    Building Real-Time IoT Dashboards with React and Recharts

    Cloud & DevOps · 13 min read

    CI/CD for Embedded Firmware: Automated Build, Test, and OTA Release Pipeline

    Mobile Development · 12 min read

    Flutter Offline-First IoT Apps: Hive + Sync Architecture That Works in the Field

    Cloud & DevOps · 14 min read

    Terraform for IoT Infrastructure: Provisioning AWS IoT Core, Lambda, and InfluxDB as Code

    Mobile Development · 10 min read

    Flutter IoT Alerts: Firebase Push Notifications for Device Events

    Cloud & DevOps · 12 min read

    Deploying IoT Backends on AWS: ECS Fargate vs Lambda vs EC2 Decision Guide

    Mobile Development · 11 min read

    Flutter + MQTT: Building Production IoT Mobile Apps That Scale

    Mobile Development · 13 min read

    Flutter BLE: Building a Bluetooth IoT Controller App from Scratch

    Cloud & DevOps · 13 min read

    AWS IoT Core vs Azure IoT Hub vs Google Cloud IoT: 2024 Honest Comparison

    IoT Engineering · 13 min read

    Kafka vs RabbitMQ for IoT: Choosing the Right Message Queue for High-Volume Telemetry

    IoT Engineering · 14 min read

    IoT System Testing: Unit, Integration, Hardware-in-the-Loop, and End-to-End

    IoT Engineering · 14 min read

    Predictive Maintenance with IoT Sensor Data: From Threshold to Machine Learning

    Embedded Systems · 14 min read

    IoT Bootloader Design: Secure Boot, A/B Partitions, and Reliable OTA Recovery

    IoT Engineering · 14 min read

    Multi-Tenant IoT Platform Architecture: Isolation, Scaling, and Data Partitioning

    Embedded Systems · 14 min read

    Memory Management in Embedded Firmware: Avoiding Heap Fragmentation and Stack Overflows

    IoT Engineering · 13 min read

    IoT Cost Optimization: How We Cut AWS IoT Bills by 60% Without Sacrificing Reliability

    IoT Engineering · 12 min read

    Edge Computing in IoT: When to Process On-Device vs In the Cloud

    IoT Engineering · 13 min read

    Digital Twins for IoT: Building a Virtual Mirror of Your Physical Devices

    Embedded Systems · 14 min read

    ESP32 Deep Sleep Mastery: Cutting Power Consumption from 240mA to 10µA

    IoT Engineering · 10 min read

    MQTT QoS 0, 1, and 2 Explained: Choosing the Right Level for IoT

    IoT Engineering · 14 min read

    IoT Monitoring and Observability: Metrics, Logs, and Distributed Tracing

    Embedded Systems · 14 min read

    Debugging Embedded Firmware: JTAG, GDB, Logic Analyzers, and Serial Tracing

    IoT Engineering · 12 min read

    WebSocket vs MQTT vs Server-Sent Events: Real-Time IoT Protocol Deep Dive

    Embedded Systems · 13 min read

    STM32 HAL vs Low-Level Drivers: When the Abstraction Costs You Too Much

    IoT Engineering · 13 min read

    IoT Data Pipeline: From Raw Sensor Reading to Live Dashboard in Under 100ms

    IoT Engineering · 13 min read

    Zero-Touch IoT Device Provisioning: Scaling from 10 to 100,000 Devices

    Embedded Systems · 13 min read

    UART vs SPI vs I2C: Choosing the Right Protocol for Sensor Integration

    IoT Engineering · 12 min read

    Real-Time IoT Alerting: From Simple Thresholds to ML Anomaly Detection

    Embedded Systems · 12 min read

    ESP32 Partition Table: Designing Flash Layout for Production Firmware

    IoT Engineering · 12 min read

    IoT Architecture Patterns: Hub-and-Spoke, Mesh, and Edge-Cloud Hybrid

    Embedded Systems · 13 min read

    IoT Battery Life Optimization: Engineering Devices That Last Years on a Single Charge

    IoT Engineering · 13 min read

    Time-Series Databases for IoT: InfluxDB vs TimescaleDB vs AWS Timestream

    Security · 14 min read

    Zero-Trust Security for Embedded IoT: Why Your Devices Are Probably Vulnerable

    Embedded Systems · 14 min read

    FreeRTOS on ESP32: Task Scheduling, Queues, and Resource Management for IoT

    IoT Engineering · 12 min read

    Building a Production IoT Gateway with Raspberry Pi and Node.js

    Embedded Systems · 13 min read

    ESP32 vs STM32: Choosing the Right Microcontroller for Your IoT Project

    Mobile Development · 10 min read

    Flutter + WebSocket: Building Real-Time IoT Dashboards That Don't Stutter

    IoT Engineering · 13 min read

    IoT Fleet Management at Scale: AWS IoT Core Device Registry and Provisioning

    IoT Engineering · 11 min read

    MQTT vs HTTP for IoT: Which Protocol Wins in Production?

    IoT Engineering · 12 min read

    ESP32 → MQTT → AWS IoT Core: The Production-Grade Architecture Guide

    Let's Build Together

    Got an IoT challenge?
    We've shipped it.

    Whether you need a fleet to track, a factory to monitor, or a farm to automate — our team has done it before and we'd love to build it with you. Typical response time: under 24 hours.

    No upfront commitment99.9% uptime SLANDA on requestFixed-price options