Skip to content

Instantly share code, notes, and snippets.

@veerendra2
Forked from shantanoo-desai/README.md
Created February 20, 2023 20:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save veerendra2/b58cf0526c35636a037ba79e910375d5 to your computer and use it in GitHub Desktop.
Save veerendra2/b58cf0526c35636a037ba79e910375d5 to your computer and use it in GitHub Desktop.
tiguitto (Telegraf, InfluxDBv1.x, Grafana, Mosquitto) stack with Traefik v2.3 reverse proxy using docker

tiguitto Stack with Traefik v2.3 as reverse-proxy

  • Tested on Raspberry-Pi 4 Model B 2GB RAM
  • Docker Version: 19.03.8
  • Docker-Compose version: 1.25.5

Directory structure:

 .
 |-- traefik
    |-- traefik.yml
 |-- telegraf
    |-- telegraf.tiguitto.toml
 docker-compose.yml

Available Endpoints

  • Traefik Dashboard: http://<IP_PI>:8080
  • Grafana Dashboard: http://<IP_PI>/grafana
  • Mosquitto Broker: http://<IP_PI>:1883

Metrics

Traefik Metrics

via the traefik.yml file and available in InfluxDB under the traefik database

IoT Metrics

publish to MQTT Broker in InfluxDB Line Protocol to the following topics:

  • IOT/+/acc
  • IOT/+/mag
  • IOT/+/gyro
  • IOT/+/temp

Roadmap

  • Integrate Traefik v2.3 as Reverse-Proxy to tiguitto stack which already provides the TIG Stack + Mosquitto MQTT Broker with different levels of Security. Contributions Welcome!
version: "3"
services:
proxy:
image: traefik:v2.3
container_name: "traefik"
volumes:
- ./traefik/traefik.yml:/etc/traefik/traefik.yml
- /var/run/docker.sock:/var/run/docker.sock:ro
ports:
- "80:80"
- "8080:8080"
- "1883:1883"
networks:
- iotstack # create using `docker network create iotstack`
grafana:
image: grafana/grafana
container_name: "grafana"
volumes:
- grafana_data:/var/lib/grafana
networks:
- iotstack
environment:
- GF_SERVER_PROTOCOL=http
# we serve the grafana dashboards as: http://<My_IP_ADDRESS>/grafana
- GF_SERVER_ROOT_URL=http://127.0.0.1:3000/grafana
# This Environment Variable provides the complete frontend as sub path when using path prefix
- GF_SERVER_SERVE_FROM_SUB_PATH=true
labels:
# enable Grafana for Reverse Proxy
- "traefik.enable=true"
- "traefik.docker.network=iotstack"
# Serve Grafana as a Path Prefix i.e. http://<IP>/grafana
- "traefik.http.routers.grafana-router.rule=PathPrefix(`/grafana`)"
# via the HTTP (port 80) entrypoint
- "traefik.http.routers.grafana-router.entryPoints=web"
# add a middleware to strip the prefix `/grafana` once the URL is hit
- "traefik.http.routers.grafana-router.middlewares=grafana-mw"
- "traefik.http.middlewares.grafana-mw.stripprefix.prefixes=/grafana"
- "traefik.http.routers.grafana-router.service=grafana"
- "traefik.http.services.grafana.loadbalancer.server.port=3000"
influxdb:
image: influxdb
container_name: "influxdb"
volumes:
- influxdb_data:/var/lib/influxdb
networks:
- iotstack
labels:
# Currently InfluxDB's HTTP Endpoint is unable via POSTMAN
# Need to check this! (disable for now)
- "traefik.enable=true"
- "traefik.docker.network=iotstack"
- "traefik.http.routers.influxdb-router.rule=PathPrefix(`/influxdb`)"
- "traefik.http.routers.influxdb-router.entrypoints=web"
# Not sure if Middleware is needed
- "traefik.http.routers.influxdb-router.middlewares=influxdb-mw"
- "traefik.http.middlewares.influxdb-mw.stripprefix.prefixes=/influxdb"
- "traefik.http.routers.influxdb-router.service=influxdb"
- "traefik.http.services.influxdb.loadbalancer.server.port=8086"
mosquitto:
image: eclipse-mosquitto
container_name: "mosquitto"
networks:
- iotstack
restart: always
volumes:
- mosquitto_data:/mosquitto/
labels:
- "traefik.enable=true"
- "traefik.docker.network=iotstack"
# Entrypoint via MQTT port (1883)
- "traefik.tcp.routers.mqtt-router.entrypoints=mqtt"
# See Docs: https://doc.traefik.io/traefik/routing/routers/#rule_1
- "traefik.tcp.routers.mqtt-router.rule=HostSNI(`*`)"
- "traefik.tcp.routers.mqtt-router.service=mosquitto"
- "traefik.tcp.services.mosquitto.loadbalancer.server.port=1883"
telegraf:
image: telegraf
container_name: "telegraf"
links:
- influxdb
volumes:
- ./telegraf/telegraf.tiguitto.toml:/etc/telegraf/telegraf.conf:ro
networks:
- iotstack
labels:
- "traefik.enable=false"
networks:
iotstack:
external: true
volumes:
grafana_data:
influxdb_data:
mosquitto_data:
[agent]
interval = "20s"
round_interval = true
metric_batch_size = 1000
metric_buffer_limit = 10000
collection_jitter = "0s"
flush_interval = "10s"
flush_jitter = "0s"
precision = ""
debug = true
quiet = false
hostname = ""
omit_hostname = true
#############################################################
# OUTPUT PLUGINS #
#############################################################
[[outputs.influxdb]]
urls = [ "http://influxdb:8086" ]
database = "edge"
skip_database_creation = false
timeout = "5s"
###############################################################
# PROCESSOR PLUGINS #
###############################################################
[[processors.regex]]
order = 1
[[processors.regex.tags]]
# use the `topic` tag to extract information from the MQTT Topic
key = "topic"
# Topic: IOT/<SENSOR_ID>/<measurement>
# Extract <SENSOR_ID>
pattern = ".*/(.*)/.*"
# Replace the first occurrence
replacement = "${1}"
# Store it in tag called:
result_key = "sensorID"
[[processors.enum]]
order = 2
[[processors.enum.mapping]]
# create a mapping between extracted sensorID and some meta-data
tag = "sensorID"
dest = "location"
[processors.enum.mapping.value_mappings]
"sensor1" = "kitchen"
"sensor2" = "livingroom"
##################################################################
# INPUT PLUGINS #
##################################################################
[[inputs.mqtt_consumer]]
servers = [ "tcp://mosquitto:1883" ]
# Topics to subscribe to:
topics = [
"IOT/+/acc",
"IOT/+/mag",
"IOT/+/gyro",
"IOT/+/temp"
]
# Telegraf will also store the topic as a tag with name `topic`
# NOTE: necessary for the Processor REGEX to extract <Sensor_ID>
topic_tag = "topic"
# Connection timeout
connection_timeout = "30s"
# Incoming MQTT Payload from Sensor nodes is in InfluxDB Line Protocol strings
data_format = "influx"
global:
checkNewVersion: false
sendAnonymousUsage: false
api:
insecure: true
dashboard: true
debug: true
log:
level: debug
entryPoints:
web:
address: ":80"
mqtt:
address: ":1883"
metrics:
influxDB:
address: influxdb:8086
protocol: http
database: "traefik"
addServicesLabels: true
addEntryPointsLabels: true
pushInterval: 10s
providers:
providersThrottleDuration: 42
docker:
watch: true
endpoint: "unix:///var/run/docker.sock"
swarmMode: false
exposedByDefault: false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment