How jahaja/psdash works
Project Type and Purpose
• psdash is a full-stack Python web application (Flask) that provides a real-time system information dashboard for Linux.
• It can run in two modes:
– Web mode: serves HTTP UI (overview, processes, network, disks, logs).
– Agent mode: runs an RPC server (zerorpc) to report metrics to a central web node.
File Structure
Top-level files & directories:
• setup.py, Vagrantfile, tests/ – build, development & CI.
• psdash/ – application package containing:
– __main__.py & run.py – CLI entry points.
– web.py – Flask app initialization & routing.
– node.py, helpers.py, net.py, log.py, run.py – “model” modules gathering metrics (via psutil).
– static/ – CSS, JS assets for the client UI.
– templates/ – Jinja2 views for each page.
• tests/ – unit tests for each module and web endpoints.
Extract Key Architectural Insights from README
• Uses Flask for webserver & routing.
• Uses psutil for gathering system metrics.
• Optional zerorpc for agent-to-web communications in multi-node setups.
• Configuration via environment / Flask config.
• UI built on Bootstrap, auto-refreshing data via AJAX (psdash.js).
Main Components
a. Client (Browser)
– HTML/CSS/JS (psdash.js) served by Flask → renders dashboard, polls REST endpoints.
b. Flask Web Server
– web.py holds route definitions: /, /processes, /network, /logs, etc.
– Controllers invoke model modules (node.py, net.py, log.py) to retrieve data.
c. Model Modules
– psutil-based gatherers: CPU, memory, disk, network, processes, logs.
d. Agent RPC Servers (zerorpc)
– Optional psdash instances in agent mode expose RPC interface.
e. Configuration Store
– Flask config + environment variables (PSDASH_*) controlling auth, nodes, intervals.
f. External Dependencies
– psutil library, zerorpc, Flask, Bootstrap.
Relationships & Data Flows
1) Browser → HTTP(S) GET/POST to Flask routes.
2) Flask controllers → call local model modules OR RPC calls to remote agents.
3) Model modules → fetch raw data from OS via psutil.
4) Flask → return JSON or render Jinja2 templates.
5) Browser JS → periodically poll JSON endpoints to update charts/tables.
Architectural Patterns & Design Principles
• MVC-style separation:
– Models: node.py, net.py, log.py
– Views: Jinja2 templates under templates/
– Controllers: route handlers in web.py
• Plugin-style extensibility: new metrics modules can be dropped in psdash/
• Multi-node clustering: central web node + agent nodes communicating via RPC.
• 12-factor config: all settings via env vars or config file.