Per-domain Nginx log analytics with hybrid static reports and live insights.
Find a file
2025-07-19 18:01:26 -05:00
scripts Add chart loading management 2025-07-19 18:01:26 -05:00
static Add chart loading management 2025-07-19 18:01:26 -05:00
templates Add chart loading management 2025-07-19 18:01:26 -05:00
tests fix: destroy charts when switching tabs 2025-07-19 17:03:48 -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 docs: refresh README and agent guide 2025-07-19 04:31:13 -05:00
reports.yml refactor: improve report field names 2025-07-19 04:17:38 -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 Add lock files and cron setup 2025-07-19 03:35:18 -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. 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 of the dashboard.

./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.