Step-by-Step Guide to Building a Django‑Based Operations Platform
This article fills the gap of detailed tutorials by chronologically documenting how the author constructed a Django‑powered operations platform, adding monitoring, dashboards, log viewing, task submission, and various management features, each illustrated with screenshots and brief explanations.
Overview
This document records the step‑by‑step construction of a Django‑based operations and monitoring platform. Each feature was added incrementally, allowing developers to see concrete implementation details such as model design, view logic, template usage, and integration with system tools.
Feature Timeline
31 – Real‑time Log Viewing
Implemented a view that streams the tail of a log file to the browser using Django’s StreamingHttpResponse. The server reads new lines from the file and yields them as they appear, enabling live log monitoring without page refresh.
30 – TCP Connection Count Monitoring
Added a metric that counts established TCP connections on the host. The implementation uses psutil.net_connections() to filter status='ESTABLISHED' and stores the count in a Django model for later charting.
29 – Test Data Dashboard
Created a simple dashboard page that displays synthetic test data. The dashboard uses Django’s generic ListView and a Chart.js integration to render line charts.
28 – Email Alert on Threshold Breach
Implemented an email alarm that triggers when the maximum value of the last three measurements exceeds a configurable threshold. The logic queries the recent records, computes max(), and sends an email via Django’s send_mail function.
27 – Monitoring Module (Server‑side API & JSON Handling)
Created a reusable monitoring app that receives JSON payloads from remote agents.
Server‑side API parses the JSON, validates fields, and stores metrics using Django ORM (SQLite by default, non‑MySQL).
Deduplication and ordering are performed with ORM distinct() and order_by() clauses; performance optimizations are deferred.
26 – Task Submission Module
Added a model Task and a corresponding view that accepts POST requests to create new tasks. The view returns a JSON response with the task ID, enabling front‑end polling.
25 – Custom Django Decorator & URL Auditing
Implemented a decorator @audit that logs request metadata (method, path, user) before view execution. Integrated URL audit middleware that records each accessed endpoint into a database table.
24 – Server List with Checkbox Selection
Extended the server list page to include a checkbox column. Selected hosts are collected via a Django form (no JavaScript). The view extracts the IPs of the chosen servers and executes a shell command using subprocess.run. Both GET and POST methods are supported.
23 – Performance Monitoring Toggle
Added a Boolean field enable_perf to the server model and a toggle control on the list page. When enabled, the platform collects CPU and memory usage via psutil and displays the data on the server detail view.
21 – Socket‑Based Monitoring (No Redis/MySQL)
Started a lightweight TCP socket server that listens for metric packets from agents.
Agents connect, send a JSON payload, and close the socket.
Django periodically reads from the socket, stores metrics, and renders time‑series charts with Chart.js.
20 – Web‑SSH (Web Login & Bastion Host)
Built a web‑based SSH client using paramiko for SSH connections and django-channels for WebSocket communication. Users log in via the Django auth system, then launch a bastion session that forwards terminal I/O to the browser.
18 – DNS Lookup (dig) Integration
Added a utility page that executes the system dig command (or a custom script) via subprocess.check_output. The raw output is parsed, formatted into an HTML table, and displayed to the user.
17‑14 – UI Enhancements
Dropdown (choice) fields for related models.
Model ordering using Meta.ordering.
Explicit migration generation after model changes.
Extended URL patterns and template tags for reusable components.
DNS query module with CRUD operations, using a foreign‑key dropdown for domain selection.
12‑10 – Server Management UI
Pages for editing, deleting, and adding server records.
Search functionality implemented with Q objects.
Pagination using Django’s Paginator class.
8‑5 – Dashboard & Template Inheritance
Created a static dashboard that lists devices and servers. Demonstrated Django template inheritance by defining a base layout and extending it for specific pages.
4‑3 – User Management
Added user creation via the Django admin interface.
Implemented login and logout views using django.contrib.auth.
External Technical References
For background on Django deployment and environment setup, the author links to several Chinese blog posts covering:
Django basics and project creation.
uWSGI/Nginx configuration.
Python packaging tools (setuptools, pip, easy_install).
Django Debug Toolbar installation.
These resources provide additional context for readers who need to replicate the development environment.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
ITPUB
Official ITPUB account sharing technical insights, community news, and exciting events.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
