Skip to content

Real-Time System Dashboard in Python using WebSocket

Updated: at 01:00 AM

Table of content

Introduction

This page provides a comprehensive overview of the Dashboard system, its architecture, and how different components interact to deliver real-time system monitoring. It serves as an entry point to understand the system’s purpose, design decisions, and technical implementation.

Purpose and Scope

The Dashboard provides real-time monitoring of system resources through a web interface. It consists of two primary data components:

The system is designed to efficiently handle multiple simultaneous users while minimizing computational overhead by using a single worker thread to gather metrics and push updates to all connected clients.

System Architecture

High-level Architecture

The dashboard architecture addresses the computational expense of system information collection by implementing a WebSocket-based approach. Rather than having each user request data on-demand, a single worker thread collects metrics and pushes updates to all connected clients.

img_1.png Key components include:

Implementation Details

Data Collection

The dashboard separates data collection into two classes:

ClassPurposeUpdate FrequencyData Collected
StaticDataCollects static system informationOnce, on initial connectionHostname, IP address, OS details
DynamicDataCollects changing system metricsRegular intervals (every second)CPU usage, Memory usage, Disk usage

This separation allows the system to optimize resource usage by only collecting static information once.

Worker Thread Implementation

The worker thread is a critical component of the system that:

  1. Runs as a singleton instance
  2. Collects system metrics at regular intervals
  3. Pushes updates to all connected clients via WebSockets

This design ensures that resource-intensive system metrics collection happens only once, regardless of how many clients are connected.

Logging

The dashboard implements comprehensive logging for troubleshooting and monitoring:

The logging configuration can be found in the logging.conf file.

Sources: README.md34-41

Technical Stack

The dashboard leverages several technologies:

ComponentTechnologyPurpose
FrontendHTML5, JavaScriptClient-side user interface
BackendFlask, Flask-SocketIOWeb server and WebSocket support
ProxyNginxReverse proxy for the Flask server
DeploymentVagrant, PuppetEnvironment setup and configuration
MonitoringPython system librariesSystem metrics collection

These technologies work together to create a responsive, real-time system monitoring dashboard.

Runtime Architecture

img_1.png

The runtime architecture illustrates how system resource data flows through various components to reach the client browser. The key insight is that all data collection happens in a single worker thread, which then distributes updates to all connected clients via WebSockets.

Source Code

You can find full source code GitHub Dashboard. Feel free to fork and contribute to the project. The code is organized into modules for easy navigation and understanding.

If you enjoy the content, please consider supporting work