homeexamplessmart-city-monitoring

Smart City Monitoring - Real-time Sensor Dashboard

Published Nov 7, 2025
4 minutes read

This project demonstrates a complete real-time monitoring system for smart city infrastructure. Four Python sensor services generate simulated metrics that are collected by Prometheus and visualized in Grafana dashboards. The system showcases modern observability patterns with containerized microservices, metrics collection, and real-time visualization.

Smart City Monitoring System
Real-time monitoring dashboard with sensor data visualization

Project goals

Architecture overview

Metrics model

Each sensor exposes Prometheus metrics via HTTP endpoints:

# Traffic: city_traffic_vehicles{location="Main_Street", sensor_id="sensor_1"}
# Temperature: city_temperature_celsius{district="A", sensor_id="A-TEMP-001", lat="47.5", lon="19.0"}
# Air Quality: city_air_quality_pm25{district="C"} city_air_quality_co2{district="C"}
# Lights: city_lights_on{district="A"} city_lights_brightness_percent{district="A"}
Grafana Dashboard
Real-time visualization of all sensor metrics in Grafana

Prometheus configuration

Prometheus scrapes all sensor endpoints every 15 seconds:

global:
  scrape_interval: 15s
 
scrape_configs:
  - job_name: traffic-sensors
    static_configs:
      - targets: ['traffic-sensor:8001']
  - job_name: temperature-sensors
    static_configs:
      - targets: ['temperature-sensor:8002']
  - job_name: airquality-sensors
    static_configs:
      - targets: ['airquality-sensor:8003']
  - job_name: lights-sensors
    static_configs:
      - targets: ['lights-sensor:8004']

Data flow lifecycle

  1. Python sensor scripts generate random metrics using prometheus_client
  2. Each sensor exposes HTTP endpoint on dedicated port (8001-8004)
  3. Prometheus scrapes metrics from all sensor endpoints every 15 seconds
  4. Metrics stored in Prometheus time-series database
  5. Grafana queries Prometheus via auto-provisioned datasource
  6. Dashboards visualize real-time data with configurable panels
  7. Sensors update metrics at different intervals (10s, 15s, 20s, 30s)

Grafana setup

Operational concerns

Security and reliability

Performance notes

Trade-offs and decisions

Prometheus Targets
Prometheus scraping all sensor endpoints with health status

Running the project

Troubleshooting

Notes

This project demonstrates how modern observability tools enable real-time monitoring of distributed systems. The separation of concerns—sensors generate metrics, Prometheus collects them, Grafana visualizes them—shows the power of the metrics collection pattern. The time-based behavior in the lights sensor shows how real-world systems adapt to environmental conditions.

The architecture scales horizontally: add more sensor containers, update Prometheus config, and Grafana automatically visualizes the new metrics. This pattern extends to production systems monitoring microservices, infrastructure, and business metrics.

The repository showcases production-ready monitoring patterns in a compact form—perfect for understanding Prometheus, Grafana, Docker Compose, and metrics-based observability.