MoniShield: from a static log report to a self-hosted monitoring and security dashboard
- Role
- Lead developer: backend, frontend and deploy
- Period
- Oct 2026 – present
- Company
- Ombudsman RI
- Stack
- Python · FastAPI · DuckDB · PostgreSQL · Svelte 5 · Apache Kafka · Docker
Problem
The client team read the cluster's daily logs through one dashboard.html file. Every build re-parsed all logs (about 40 minutes for a year of data), every day was loaded into the browser at once, and lists were cut short to keep the file small, so some KPIs were wrong (pod connection errors showed 200 instead of 1,200). The file also held account emails and client IPs with no access control.
Approach
A self-hosted application that reads each log folder once into DuckDB and serves per-page reports through FastAPI to a Svelte 5 UI with sign-in and roles. The old parsing rules were kept and proven equivalent by tests. Attack detection uses 176 OWASP CRS v4 rules with CAPEC categories. Logs can come from a folder, S3, a browser upload or Rancher through Kafka. The code follows a clean architecture that a test enforces.
Result
On a simulated year of data (365 folders, 48 million nginx requests) the database is only 4.75 GB and all 21 queries of a page finish in 20.5 ms. After profiling, ingest became 18× faster (59 MB folder: 207 → 11.6 s). CRS caught 24 percent-encoded probes for sensitive files that slipped past the old rules, while filtering out scanner tools the old rules counted as attacks.

Context
The applications in the client's Kubernetes cluster (ingress-nginx, CoreDNS, Spring services and the frontend) export their logs every day into one folder per date. The team read them through a single dashboard.html file produced by a Python script. What it showed was useful: service health, attack indications, business activity and where users came from. The way it was built would not last:
| Problem | Evidence in the old system |
|---|---|
| Every build re-parsed every log | 11 folders = 14 s; a year of ~131 million lines ≈ 40 minutes per build |
| Every day loaded into the browser at once | 2.3 MB for 11 folders, tens of MB for a year |
| Lists cut short, KPIs computed from the cut lists | "Pod connection errors" showed 200 instead of 1,200 |
| No access control | The file held account emails and client IPs and could be copied anywhere |
Architecture
Log folder ─┐
S3 / R2 ─┤ ┌─ DuckDB (raw logs + aggregate tables)
Upload ─┼─► ingest + derive ──┤
Rancher ─► Kafka ─► inbox ─┘ └─ PostgreSQL (accounts, sessions, audit)
│
FastAPI (JWT, roles, Swagger) ─► Svelte 5 + MapLibre
│
Telegram · Discord · email (alerts & daily report)
The Python code has four layers: domain → application → infrastructure → interfaces. The domain and application layers import no third-party package at all (no FastAPI, SQLAlchemy, DuckDB or boto3), and tests/test_architecture.py enforces it, so an import that breaks the rule fails CI.
Technical decisions
- DuckDB for analytics, PostgreSQL for accounts. Logs are append-only and read through aggregations, a good fit for an embedded columnar database. Accounts, sessions and the audit log stay in PostgreSQL through SQLAlchemy.
- Ingest once, read many times. Only new folders or changed files are read; with nothing new, an ingest takes 0.4 s. Pages only read aggregate tables (light CQRS).
- Equivalent to the old system. The old parsing rules were moved over as they were, and each folder's numbers were checked against the old system's reference figures by tests before the new rules were switched on.
- OWASP CRS instead of home-made regexes. 176 of the 203 relevant CRS v4.30.0 rules are processed once into JSON in the repo (nothing is downloaded at runtime) and matched the way ModSecurity does:
t:transformations in order, an anomaly score, a threshold of 5, then grouped by CAPEC category. - IP privacy. IP locations and owners are looked up offline from GeoLite2, DB-IP and iptoasn databases downloaded to the server, so user IP addresses never leave it.
- Kafka reuses the folder format. The consumer writes Kafka messages into S3-style folders, so the same ingest pipeline applies, and a "LIVE" map can show requests as they arrive.
Performance
Measured by copying the largest folder (359 thousand log lines) to 365 consecutive dates:
| Measure | Target | Result |
|---|---|---|
| Database size for 365 folders | ≤ 10 GB | 4.75 GB |
| All queries of one page | ≤ 200 ms | 20.5 ms (21 queries) |
| Trends tab over 365 folders | ≤ 500 ms | 5.4 ms |
| Ingest with no changes | ≤ 5 s | 0.4 s |
When asked whether the backend should be rewritten in Go, I profiled first. Reading and parsing the logs took only 1% of the time; 80% went into inserting aggregate rows one by one with executemany, and 16% into an account analysis with quadratic complexity. The fix: bulk inserts through one JSON-lines file read by DuckDB (~0.01 ms per row) and a bisection-based account analysis. A 59 MB folder went from 207 to 11.6 s, a 237 MB folder from "not finished in 29 minutes" to 27 s, with identical rows in all 47 tables.
Attack detection
Compared with the old rules on the 5 folders that have ingress-nginx logs:
| Requests flagged | |
|---|---|
| Old rules | 315 |
| OWASP CRS | 110 |
| Flagged by both | 86 |
| CRS only | 24 |
Most "old rules only" requests are common tool User-Agents (Go-http-client, curl) and CMS paths without a payload, which CRS does not treat as attacks. The 24 requests only CRS caught are probes for sensitive files with percent-encoded names, such as /%61%77%73-%63%6f%6e%66%69%67.%6a%73%6f%6e (= /aws-config.json). CRS applies urlDecode before matching; the old rules did not. The limit is stated on the Security page: only the parts of a request that the log records are inspected, so this is not a WAF replacement.
Operations

- Security: JWT sessions, two roles (admin and user), password reset by email code, email changes verified through the old and the new address, and the visitor's real IP behind Cloudflare trusted only from Cloudflare's ranges.
- Notifications: Telegram, Discord and email for per-service error spikes (against the 7-day average) and a daily report.
- Daily backup: both DuckDB databases and the account tables, with a SHA-256 manifest, kept for 7 days, optionally copied to object storage.
- CI/CD: GitHub Actions checks commit messages (Conventional Commits), runs 338 pytest tests, builds the web UI and runs a browser smoke test on every page in both languages. A merge into the
prdbranch deploys to the server automatically. - No client data in the code: service names, hosts and business endpoints come from
.env. Tests, examples and docs useexample.comand synthetic IPs, which made it possible to open the repository to the public.
Still in progress
ingress-nginx logs from Rancher through Kafka are waiting for the clusterloggings permission on the cluster; those are the logs the map and attack detection need for the Kafka source. Next is configurable log formats, so MoniShield can read services beyond today's.