How aadilsalimm/logspy works
1. Overall shape
- LogSpy is a desktop app, not a server-only web app. The native window is provided by pywebview, while the backend is a Flask application with Socket.IO for live updates.
- The repository is split into two main product areas: live anomaly monitoring (log_spy/) and interactive troubleshooting (troubleshooter/).
2. Top-level runtime
- app.py is the entry point and likely wires together the Flask server, Socket.IO event bridge, and the desktop window.
- The UI is rendered from Jinja templates in templates/ and enhanced by page-specific JavaScript/CSS in static/.
3. Anomaly detection pipeline boundary
- log_spy/main.py acts as the controller/orchestrator for the log-monitoring engine.
- It coordinates subprocesses and queues rather than doing all work in one thread, which is the main architectural boundary for the monitoring path.
4. Log ingestion and pre-processing
- log_spy/log_shipper.py continuously tails journalctl output from the local Linux journal.
- log_spy/log_filter.py removes noisy or low-value system messages before they reach the classifier, reducing model load and false positives.
5. Local LLM classification
- log_spy/log_classifier.py is the anomaly decision point.
- It calls a local Ollama-hosted fine-tuned Phi-3.5-mini model to classify buffered log batches as normal or anomalous and to extract a reason/component summary.
6. Persistence layer
- log_spy/db_ops.py provides SQLite-backed storage for anomaly history.
- This is the durable state of the monitoring subsystem: detected events are written here for later viewing and CRUD operations.
7. Real-time UI update path
- When the controller receives a classification result, it is pushed to the frontend through Socket.IO events.
- This creates a live monitoring loop: journal logs → filter → batch → classify → persist → push to UI.
8. Troubleshooter subsystem
- The troubleshooter/ package is a separate analysis pipeline focused on user-described issues rather than continuous monitoring.
- troubleshooter/troubleShooter.py is the main orchestrator, and log_fetcher.py handles targeted journal queries.
9. Cloud LLM-assisted diagnosis
- Troubleshooting uses a 3-stage flow: intent identification, log retrieval, and root-cause analysis.
- The prompts in intent_sys_prompt.txt and rc_sys_prompt.txt guide Groq-hosted models, so this subsystem depends on cloud API keys in troubleshooter/.env.
10. Frontend split
- There are two distinct dashboards: templates/log_spy.html and templates/troubleshooter.html.
- Their JS/CSS assets are separated under static/log_spy/ and static/troubleshooter/, which mirrors the backend split and helps draw the UI as two entry points into the same app shell.
11. Key external dependencies that affect architecture
- journalctl and systemd are mandatory for log access.
- Ollama provides the local inference runtime for anomaly classification.
- Groq provides remote inference for the troubleshooting workflow.
- SQLite is the only persistent datastore visible in the repository.
12. Primary architectural diagram boundaries
- A useful diagram should show: local journal source on the left, a multiprocessing monitoring pipeline in the center, SQLite plus Socket.IO as shared backend services, and two frontend panels on the right.
- The troubleshooting path should be drawn as a separate request-driven workflow that starts from user input and ends in cloud-LLM analysis, distinct from the continuous monitoring loop.
Main entry points: app.py App entry · log_classifier.py Log classifier · troubleShooter.py Troubleshooter · main.py Monitor orchestrator
Components 18
Desktop runtime
App shell, Flask/Socket.IO backend, and webview entry point.
- App entry · Starts the Flask app, Socket.IO bridge, and native window.
app.py
Live monitoring
Continuous anomaly detection pipeline for journal logs.
- Monitor orchestrator · Coordinates the live log-monitoring subprocesses and queues.
log_spy/main.py - Log shipper · Streams journalctl output from the local system journal.
log_spy/log_shipper.py - Log filter · Drops noisy or low-value messages before classification.
log_spy/log_filter.py - Log classifier · Classifies buffered log batches as normal or anomalous using local inference.
log_spy/log_classifier.py
Troubleshooting
Request-driven diagnosis workflow for user-reported issues.
- Troubleshooter · Coordinates the issue-analysis flow from user input to diagnosis.
troubleshooter/troubleShooter.py - Log fetcher · Retrieves targeted journal entries for a specific troubleshooting case.
troubleshooter/log_fetcher.py - Prompt specs · System prompts that shape intent detection and root-cause analysis.
Frontend
Two dashboard entry points and their static assets.
- Log Spy UI · Template for the live anomaly monitoring dashboard.
templates/log_spy.html - Troubleshooter UI · Template for the interactive troubleshooting dashboard.
templates/troubleshooter.html - Spy script · Client-side behavior for live monitoring updates.
static/log_spy/script.js - Spy styles · Styling for the monitoring dashboard.
static/log_spy/style.css - Troubleshoot script · Client-side behavior for the troubleshooting workflow.
static/troubleshooter/script.js - Troubleshoot styles · Styling for the troubleshooting dashboard.
static/troubleshooter/style.css
Persistence
SQLite-backed history for detected anomalies.
- Anomaly store · Stores anomaly history for later viewing and CRUD operations.
log_spy/db_ops.py
Other components
- System journal · systemd journal access required for live monitoring and targeted retrieval.
- Local model · Hosts the Phi-3.5-mini model used for anomaly classification.
- Groq API · Remote inference backend used for troubleshooting analysis.
Connections 24
- App entry → Monitor orchestrator: starts · Bootstraps the live monitoring pipeline.
- App entry → Troubleshooter: exposes · Makes the troubleshooting workflow available in the same app shell.
- App entry → Log Spy UI: serves · Renders the monitoring dashboard.
- App entry → Troubleshooter UI: serves · Renders the troubleshooting dashboard.
- Log Spy UI → Spy script: uses · Page behavior is driven by its client script.
- Log Spy UI → Spy styles: styles · Monitoring UI styling.
- Troubleshooter UI → Troubleshoot script: uses · Page behavior is driven by its client script.
- Troubleshooter UI → Troubleshoot styles: styles · Troubleshooting UI styling.
- System journal → Log shipper: streams · Live journal output feeds the monitoring pipeline.
- Monitor orchestrator → Log shipper: spawns · Runs the tailing worker as part of the monitoring loop.
- Monitor orchestrator → Log filter: routes · Sends batches through the noise filter.
- Monitor orchestrator → Log classifier: batches · Hands buffered logs to the classifier.
- Log filter → Log classifier: passes · Filtered logs become classification input.
- Log classifier → Local model: queries · Uses local inference for anomaly decisions.
- Log classifier → Anomaly store: persists · Writes anomaly results to SQLite history.
- Log classifier → App entry: emits · Sends live results back to the desktop/backend shell.
- Anomaly store → App entry: serves history · Provides stored anomaly records for UI actions.
- Troubleshooter → Log fetcher: requests · Fetches relevant logs as part of diagnosis.
- Log fetcher → System journal: queries · Pulls targeted entries from the system journal.
- Troubleshooter → Prompt specs: guides · Uses prompt templates for intent and root-cause reasoning.
- Troubleshooter → Groq API: queries · Sends analysis requests to the cloud model backend.
- Troubleshoot script → Troubleshooter: submits · User inputs trigger troubleshooting runs.
- Spy script → App entry: receives events · Consumes live monitoring updates from the backend.
- Troubleshoot script → App entry: receives results · Displays troubleshooting outcomes in the UI.