A comprehensive monitoring solution for edge devices using Flask, Prometheus, and Grafana. This project simulates metrics from Kubernetes edge devices and provides real-time visualization through a custom dashboard and embedded Grafana panels.
- Real-time Monitoring: Track CPU, RAM, temperature, and network metrics
- Custom Dashboard: Interactive web interface with live charts
- Prometheus Integration: Time-series data collection and storage
- Grafana Visualization: Professional monitoring dashboards
- Alert System: Configurable alerts for high resource usage
- Data Export: CSV export functionality
- Docker Support: Easy deployment with Docker Compose
- Kubernetes Ready: K8s deployment manifests included
┌─────────────────────────────────────────────────────────┐
│ Docker Compose │
│ │
│ ┌──────────────────┐ ┌──────────────────┐ │
│ │ Flask Exporter │───▶│ Prometheus │ │
│ │ Port: 5000 │ │ Port: 9090 │ │
│ │ - Dashboard │ │ - Scrapes / │ │
│ │ - API │ │ metrics │ │
│ │ - Metrics │ │ - Stores data │ │
│ └──────────────────┘ └──────────────────┘ │
│ │ │ │
│ │ ┌────────▼──────────┐ │
│ │ │ Grafana │ │
│ │ │ Port: 3000 │ │
│ │ │ - Visualizes │ │
│ │ │ - Dashboards │ │
│ │ └───────────────────┘ │
│ │ │ │
└───────────┼───────────────────────┼──────────────────────┘
│ │
▼ ▼
Browser Access Browser Access
localhost:5000 localhost:3000
- Backend: Python 3.11, Flask
- Metrics: Prometheus Client
- Monitoring: Prometheus, Grafana
- Frontend: HTML, CSS, JavaScript, Chart.js
- Containerization: Docker, Docker Compose, mini
- Orchestration: Kubernetes
edge_metrics_ojt_final/
├── exporter.py # Flask application (main server)
├── devices.py # Device data generator
├── requirements.txt # Python dependencies
├── Dockerfile # Docker image configuration
├── docker-compose.yml # Multi-container setup
├── prometheus.yml # Prometheus configuration
├── alert_rules.yml # Alert definitions
├── grafana-dashboard.json # Pre-configured Grafana dashboard
├── k8s/ # Kubernetes manifests
│ ├── namespace.yaml # Creates edge-metrics namespace
│ ├── prometheus-config.yaml # Prometheus config and alert rules
│ ├── exporter-deployment.yaml # Flask exporter deployment & service
│ ├── prometheus-deployment.yaml # Prometheus deployment & service
│ └── grafana-deployment.yaml # Grafana deployment & service
├── static/
│ ├── index.html # Dashboard UI
│ ├── dashboard.js # Frontend logic
│ └── style.css # Styling
## Prerequisites
- Docker Desktop installed
- Docker Compose installed
- Python 3.11+ (for local development)
- 8GB RAM recommended
## Quick Start
### 1. Clone the Repository
```bash
cd edge_metrics_ojt_final
docker-compose up -dThis will start:
- Flask Exporter on port 5000
- Prometheus on port 9090
- Grafana on port 3000
Open your browser and navigate to:
- Main Dashboard: http://localhost:5000
- Prometheus: http://localhost:9090
- Grafana: http://localhost:3000
- Go to http://localhost:3000
- Login with default credentials:
- Username:
admin - Password:
admin
- Username:
- Add Prometheus data source:
- Go to Configuration → Data Sources
- Click "Add data source"
- Select "Prometheus"
- URL:
http://prometheus:9090 - Click "Save & Test"
- Import dashboard:
- Go to Dashboards → Import
- Upload
grafana-dashboard.json - Select Prometheus data source
- Click "Import"
GET /- Main dashboard UIGET /api/devices- JSON data of all devicesGET /metrics- Prometheus metrics endpoint
{
"devices": [
{
"id": "edge-device-1",
"type": "sensor",
"cpu": 45.23,
"ram": 62.15,
"temp": 55.8,
"network_sent": 3440000.0,
"network_received": 29800000.0,
"status": "Online",
"anomaly": "Normal"
}
],
"timestamp": 1733315400
}The exporter exposes the following Prometheus metrics:
edge_device_cpu_usage_percent- CPU usage percentageedge_device_ram_usage_percent- RAM usage percentageedge_device_temperature_celsius- Device temperatureedge_device_network_sent_bytes- Network bytes sentedge_device_network_received_bytes- Network bytes receivededge_device_anomaly_flag- Anomaly detection (1=Anomaly, 0=Normal)
All metrics include labels: device_id and type
Configured alerts in Prometheus:
- HighEdgeCPU: Triggers when CPU > 80% for 1 minute
View alerts at: http://localhost:9090/alerts
-
Device Table
- Real-time device metrics
- Status indicators (Online/High Load)
- Anomaly detection
- Filter by status
-
Live Charts
- CPU Usage Over Time
- RAM Usage Over Time
- Temperature Over Time
- Network Sent/Received
-
Controls
- Refresh Data button
- Export to CSV
- Status filter
- Auto-refresh every 4 seconds
-
Embedded Grafana
- Professional monitoring dashboard
- Historical data visualization
# Install dependencies
pip install -r requirements.txt
# Run the exporter
python exporter.py
# Access at http://localhost:5000docker build -t edge-metrics-exporter:latest .# All services
docker-compose logs -f
# Specific service
docker-compose logs -f exporter
docker-compose logs -f prometheus
docker-compose logs -f grafanaDeploy the edge metrics monitoring stack on Kubernetes Desktop or Minikube.
- Docker Desktop with Kubernetes enabled, OR
- Minikube installed and running
- kubectl configured
# 1. Switch to Docker Desktop context
kubectl config use-context docker-desktop
# 2. Build Docker image
docker build -t edge-metrics-exporter:latest .
# 3. Deploy all resources
kubectl apply -f k8s/namespace.yaml
kubectl apply -f k8s/prometheus-config.yaml
kubectl apply -f k8s/exporter-deployment.yaml
kubectl apply -f k8s/prometheus-deployment.yaml
kubectl apply -f k8s/grafana-deployment.yaml
# 4. Verify deployment
kubectl get pods -n edge-metrics
# 5. Access services (run each in separate terminal)
kubectl port-forward -n edge-metrics service/exporter 5000:5000
kubectl port-forward -n edge-metrics service/prometheus 9090:9090
kubectl port-forward -n edge-metrics service/grafana 3000:3000# 1. Start Minikube
minikube start
# 2. Build image in Minikube's Docker environment
eval $(minikube docker-env)
docker build -t edge-metrics-exporter:latest .
# 3. Deploy all resources
kubectl apply -f k8s/
# 4. Verify deployment
kubectl get pods -n edge-metrics
# 5. Access services
kubectl port-forward -n edge-metrics service/exporter 5000:5000
kubectl port-forward -n edge-metrics service/prometheus 9090:9090
kubectl port-forward -n edge-metrics service/grafana 3000:3000
# Or use Minikube dashboard
minikube dashboardThe k8s/ directory contains:
namespace.yaml- Creates edge-metrics namespaceprometheus-config.yaml- ConfigMap with Prometheus config and alert rulesexporter-deployment.yaml- Flask exporter deployment and serviceprometheus-deployment.yaml- Prometheus deployment and servicegrafana-deployment.yaml- Grafana deployment and service
After port-forwarding, access:
- Exporter Dashboard: http://localhost:5000
- Prometheus: http://localhost:9090
- Grafana: http://localhost:3000
- Open Kubernetes Desktop UI
- Select namespace: edge-metrics
- View running pods, deployments, and services
# Delete all resources
kubectl delete namespace edge-metrics
# Or delete individually
kubectl delete -f k8s/If Grafana shows login screen in iframe:
- Check environment variables in
docker-compose.yml - Ensure
GF_AUTH_ANONYMOUS_ENABLED=trueis set - Restart containers:
docker-compose restart grafana
- Check if exporter is running:
docker-compose ps - Verify metrics endpoint: http://localhost:5000/metrics
- Check Prometheus targets: http://localhost:9090/targets
- Ensure target status is "UP"
# Stop all containers
docker-compose down
# Remove volumes
docker-compose down -v
# Rebuild and start
docker-compose up -d --buildEdit prometheus.yml:
global:
scrape_interval: 10s # Change from 5s to 10sEdit alert_rules.yml:
- alert: HighEdgeCPU
expr: edge_device_cpu_usage_percent > 90 # Change threshold
for: 2m # Change durationEdit static/dashboard.js:
setInterval(refreshAll, 5000); // Change from 4000ms to 5000ms# Stop containers
docker-compose stop
# Stop and remove containers
docker-compose down
# Stop and remove everything (including volumes)
docker-compose down -vdevices.py generates random CPU, RAM, temperature, and network metrics. exporter.py exposes: /api/devices → JSON data for the frontend /metrics → Prometheus-format data The frontend fetches new metrics every second. UI updates in real time using JavaScript. Deployed on Render using Gunicorn for production.
https://edge-device-metrics-simulated-2.onrender.com
https://edge-device-metrics-simulated-2.onrender.com/metrics
This project is created for educational purposes (OJT Project).
Created as part of On-the-Job Training (OJT) project for edge device monitoring.
For issues or questions, please check the troubleshooting section or review the logs.





