A web-based client application built with NiceGUI designed to receive and display stack traces and associated trace information pushed from a remote source. It's intended to be part of a larger distributed debugging or monitoring system.
The client listens for data on a specific endpoint, registers itself with a companion server component, and displays the received information in real-time via a web UI.
- Web UI: Simple and clean interface for viewing the latest received stack and trace data.
- Real-time Updates: Automatically polls for new data and refreshes the display without requiring manual page reloads.
- HTTP Endpoint: Receives data via a simple
POSTrequest to the/pushendpoint. - Flexible Configuration: Can be configured using environment variables (for automated setups) or through a dedicated
/bindpage in the web UI. - Server Binding: Registers its own accessible URL with a companion server component via the server's
/attachendpoint.
- Python 3.8+
- pip (Python package installer)
- A companion "DDBG Server" component (this client needs a server URL to bind to). This server component is not included in this codebase but is required for the binding process.
-
Clone the repository or download the script:
# If using Git git clone <your-repo-url> cd <your-repo-directory> # Or just save the Python script (e.g., as ddbg_client.py)
-
Create and activate a virtual environment (Recommended):
python -m venv venv # On Windows .\venv\Scripts\activate # On macOS/Linux source venv/bin/activate
-
Create a
requirements.txtfile with the following content:nicegui pydantic requests validators
-
Install dependencies:
pip install -r requirements.txt
The client needs two crucial URLs to function:
LOCALURL: The base URL where this client application is accessible from the network (specifically, accessible by the server it binds to). Example:http://192.168.1.10:8080SERVERURL: The base URL of the companion "DDBG Server" component, including any specific path required for binding. Example:http://192.168.1.20:8000/ddbg
You can configure these in two ways:
-
Method 1: Environment Variables (Recommended) Set the
LOCALandSERVERenvironment variables before running the script. The application will automatically read these, validate them, and attempt to bind with the server on startup.# Example on Linux/macOS export LOCAL="http://<your_client_ip_or_hostname>:8080" export SERVER="http://<your_server_ip_or_hostname>:<port>/<path>" python ddbg # Example on Windows (Command Prompt) set LOCAL="http://<your_client_ip_or_hostname>:8080" set SERVER="http://<your_server_ip_or_hostname>:<port>/<path>" python ddbg # Example on Windows (PowerShell) $env:LOCAL="http://<your_client_ip_or_hostname>:8080" $env:SERVER="http://<your_server_ip_or_hostname>:<port>/<path>" python ddbg
(Note: Replace
<...>placeholders with actual values. The client runs on port 8080 by default if not specified otherwise in code/environment for NiceGUI) -
Method 2: Web UI (
/bindpage) If you run the script without setting the environment variables, accessing the application in your browser will automatically redirect you to the/bindpage.- Enter "This App's Base URL" (your
LOCALURL). - Enter "Remote Server Base URL" (your
SERVERURL). - Click "Save and Bind".
- If the binding is successful (the client receives a
"true"response from the server's/attachendpoint), you will be navigated to the main display page (/). A dialog will show the binding attempt result.
- Enter "This App's Base URL" (your
- Ensure configuration is done via environment variables OR be prepared to use the
/bindpage. - Navigate to the directory containing the script and your activated virtual environment.
- Run the script:
python ddbg
- The application will start, and NiceGUI will print the URL where the UI is accessible (usually
http://<your-ip>:8080or similar). Check the console output.
- Open the URL provided in the console output in your web browser.
- If not configured via environment variables, you'll be directed to
/bindfirst. Complete the configuration. - Once configured and bound, the main page (
/) will initially show "Waiting...". - When an external process sends data to this client's
/pushendpoint, the display will update automatically to show the latest "Stack" and "Trace" information.
This is the endpoint the external monitored process should send data to.
- Method:
POST - Path:
/push - Request Body: JSON object matching the following structure:
{ "timestamp": 1678886400, // Integer: Unix timestamp of when the data was generated "data": "Main stack trace...", // String: The primary data (e.g., stack trace) "trace": "Additional trace..." // String: Any supplementary trace info } - Success Response: The
timestampvalue from the request payload (as an integer). - Error Response: An error message string (e.g.,
"Err: Malformed payload").
- Startup: The client starts, checks for
LOCALandSERVERURLs (env vars first, then requires UI input via/bind). - Binding: The client sends its
LOCALURL to theSERVER's/attachendpoint to register itself. - Listening: The client's
/pushendpoint listens for incomingPOSTrequests containing stack/trace data. - Data Reception: When data is received at
/push, the client updates its internal state (global variablesstack,trace,stack_time). - UI Polling: The web UI periodically checks (via
poll_stackfunction) if thestack_timehas changed. - UI Refresh: If
stack_timeindicates new data, the UI component (show_stack) is refreshed to display the lateststackandtrace.