Per-domain Nginx log analytics with hybrid static reports and live insights.
Find a file
2025-08-19 00:40:07 -05:00
.forgejo/workflows ci: ensure repo root on PYTHONPATH when running pytest 2025-08-16 05:29:20 -05:00
scripts reports: fix analysis import error when run as a script\n\n- Prepend project root to sys.path in scripts/generate_reports.py to allow when executed via path\n- Update run-reports.sh to invoke the generator as a module () for robust imports\n- Keeps CLI behavior the same while eliminating 'No module named scripts' 2025-08-19 00:40:07 -05:00
static Phase 1 UX + JS transforms: tabs, windowing, percent/grouping, smoothing, stacked series, metadata pass-through, top_n 2025-08-18 23:01:00 -05:00
templates UX: merge Distribution and Tables into a single Breakdown tab with clear option help\n\n- Replace separate Distribution/Tables tabs with one Breakdown tab\n- Breakdown shows categorical charts and data tables together\n- Add in-page help explaining Percent mode, Grouping, and Exclude '-'\n- Update filtering, containers, and tab logic to target new tab\n- Keep existing report JSON/HTML contracts; no server changes required 2025-08-19 00:28:42 -05:00
tests UX Phase 1 follow-ups: state v2 + reset, window defaults + support, palette support; analysis JSON generation; tests for LIMIT/metadata; README updates 2025-08-18 23:47:23 -05:00
.flake8 lint: re-enable E402; remove sys.path hacks; drop unused pytest imports in tests 2025-08-16 05:24:14 -05:00
.gitignore Update requirements and AGENTS instructions 2025-07-17 00:17:46 -05:00
AGENTS.md docs: refresh README and agent guide 2025-07-19 04:31:13 -05:00
LICENSE Initial commit 2025-07-16 22:42:28 -05:00
README.md UX Phase 1 follow-ups: state v2 + reset, window defaults + support, palette support; analysis JSON generation; tests for LIMIT/metadata; README updates 2025-08-18 23:47:23 -05:00
reports.yml Phase 1 UX + JS transforms: tabs, windowing, percent/grouping, smoothing, stacked series, metadata pass-through, top_n 2025-08-18 23:01:00 -05:00
requirements.txt Add YAML-driven report generation 2025-07-18 01:24:26 -05:00
run-analysis.sh Add lock files and cron setup 2025-07-19 03:35:18 -05:00
run-import.sh Add lock files and cron setup 2025-07-19 03:35:18 -05:00
run-reports.sh reports: fix analysis import error when run as a script\n\n- Prepend project root to sys.path in scripts/generate_reports.py to allow when executed via path\n- Update run-reports.sh to invoke the generator as a module () for robust imports\n- Keeps CLI behavior the same while eliminating 'No module named scripts' 2025-08-19 00:40:07 -05:00
setup.sh Add lock files and cron setup 2025-07-19 03:35:18 -05:00

ngxstat

ngxstat is a lightweight log analytics toolkit for Nginx. It imports access logs into an SQLite database and renders static dashboards so you can explore per-domain metrics without running a heavy backend service.

Requirements

  • Python 3.10+
  • Access to the Nginx log files (default: /var/log/nginx)

The helper scripts create a virtual environment on first run, but you can also set one up manually:

python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt

Importing Logs

Run the importer to ingest new log entries into database/ngxstat.db:

./run-import.sh

Rotated logs are processed in order and only entries newer than the last imported timestamp are added.

Generating Reports

To build the HTML dashboard and JSON data files use run-reports.sh which runs all intervals in one go:

./run-reports.sh

The script calls scripts/generate_reports.py internally to create hourly, daily, weekly and monthly reports, then writes analysis JSON files used by the "Analysis" tab. Per-domain reports are written under output/domains/<domain> alongside the aggregate data. Open output/index.html in a browser to view the dashboard.

If you prefer to run individual commands you can invoke the generator directly:

python scripts/generate_reports.py hourly
python scripts/generate_reports.py daily --all-domains

Analysis Helpers

run-analysis.sh executes additional utilities that examine the database for missing domains, caching opportunities and potential threats. The JSON output is saved under output/analysis and appears in the "Analysis" tab. The run-reports.sh script also generates these JSON files as part of the build.

UX Controls

The dashboard defaults to a 7day window for time series. Your view preferences persist locally in the browser under the ngxstat-state-v2 key. Use the "Reset view" button to clear saved state and restore defaults.

./run-analysis.sh

Serving the Reports

The generated files are static. You can serve them with a simple Nginx block:

server {
    listen 80;
    server_name example.com;
    root /path/to/ngxstat/output;

    location / {
        try_files $uri $uri/ =404;
    }
}

Restrict access if the reports should not be public.

Running Tests

Install the development dependencies and execute the suite with pytest:

pip install -r requirements.txt
pytest -q

All tests must pass before submitting changes.

Acknowledgements

ngxstat uses the following thirdparty resources:

The project is licensed under the GPLv3. Icon assets remain in the public domain via the CC0 license.