# ngxstat Per-domain Nginx log analytics with hybrid static reports and live insights. ## Generating Reports Use the `generate_reports.py` script to build aggregated JSON and HTML files from `database/ngxstat.db`. Create a virtual environment and install dependencies: ```bash python3 -m venv .venv source .venv/bin/activate pip install -r requirements.txt ``` Then run one or more of the interval commands: ```bash python scripts/generate_reports.py hourly python scripts/generate_reports.py daily python scripts/generate_reports.py weekly python scripts/generate_reports.py monthly ``` Reports are written under the `output/` directory. Each command updates the corresponding `.json` file and produces an HTML dashboard using Chart.js. ## Importing Logs Use the `run-import.sh` script to set up the Python environment if needed and import the latest Nginx log entries into `database/ngxstat.db`. ```bash ./run-import.sh ``` This script is suitable for cron jobs as it creates the virtual environment on first run, installs dependencies and reuses the environment on subsequent runs. The importer handles rotated logs in order from oldest to newest so entries are processed exactly once. If you rerun the script, it only ingests records with a timestamp newer than the latest one already stored in the database, preventing duplicates. ## Cron Report Generation Use the `run-reports.sh` script to run all report intervals in one step. The script sets up the Python environment the same way as `run-import.sh`, making it convenient for automation via cron. ```bash ./run-reports.sh ``` Running this script will create or update the hourly, daily, weekly and monthly reports under `output/`. ## Serving Reports with Nginx To expose the generated HTML dashboards and JSON files over HTTP you can use a simple Nginx server block. Point the `root` directive to the repository's `output/` directory and optionally restrict access to your local network. ```nginx server { listen 80; server_name example.com; # Path to the generated reports root /path/to/ngxstat/output; location / { try_files $uri $uri/ =404; } # Allow access only from private networks allow 192.0.0.0/8; allow 10.0.0.0/8; deny all; } ``` With this configuration the generated static files are served directly by Nginx while connections outside of `192.*` and `10.*` are denied.