This post explains how to build and deploy a cloud-native monitoring application using Flask, Docker, and Azure. The application provides real-time metrics such as CPU usage, memory, and disk utilization. You can view the live demo here: Cloud Monitoring App.
Table of contents
Open Table of contents
Introduction
Monitoring systems ensure the performance and reliability of distributed applications. This project leverages Flask for the backend, Docker for containerization, and Azure App Service for scalable hosting. The application tracks:
- CPU Usage: Real-time percentage utilization.
- Memory Usage: Total, used, and available memory.
- Disk Usage: Storage capacity and usage details.
Tech Stack
Tool/Technology | Purpose |
---|---|
Flask | Backend framework for creating the application |
Docker | Containerization of the application for portability |
Azure App Service | Hosting the containerized application |
Python psutil | Fetching real-time system metrics |
HTML/CSS | Frontend interface for displaying metrics |
Code Implementation
Here’s the core Flask code for the monitoring application:
app.py
from flask import Flask, render_template
import psutil
app = Flask(__name__)
@app.route("/")
def index():
cpu_usage = psutil.cpu_percent(interval=1)
memory_info = psutil.virtual_memory()
disk_info = psutil.disk_usage("/")
return render_template(
"index.html",
cpu_usage=cpu_usage,
memory_info=memory_info,
disk_info=disk_info,
)
if __name__ == "__main__":
app.run(host="0.0.0.0", port=8080)