<- Back to journal

19 Dec 2024

Building a Cloud Monitoring Application with Flask, Docker, and Azure

Learn how to create a cloud-native monitoring application using Flask, Docker, and Azure App Service. Track system metrics like CPU, memory, and disk usage in real-time.

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

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, canonicalURL: https://coddcore.com/blog/cloud-monitoring-flask-docker-azure )

if name == "main": app.run(host="0.0.0.0", port=8080)