#!/bin/bash # ============================================================================================== # ================================ NPM Access Stats ============================================ # ============================================================================================== # # PURPOSE # ───────────────────────────────────────────────────────────────────────────── # Aggregates Nginx Proxy Manager's per-host access logs into DB_DIR/npm_access.json — requests, # bytes sent, status breakdown and last hit per proxy host. The Proxies tab reads it. # # NPM writes one access log per host and counts nothing. The logs here are 475 MB across 41 files, # so this cannot happen inside a page load; each pass reads only what arrived since the last one. # # ============================================================================================== # OPERATIONAL MODEL # ============================================================================================== # # A wrapper. The work is in npm_access_stats.php, next to the NPM client and conf helpers it uses. # Same split as api_cache_writer, ai_repair_sweep and cert_history. # # Totals are "since tracking began", not since the host existed: lines that rotate out between two # passes are not counted. Running daily keeps that to whatever NPM rotates in a day. # # ============================================================================================== # RUNTIME MODES # ============================================================================================== # # npm_access_stats.sh one pass # npm_access_stats.sh --dry-run parse and report, write nothing # npm_access_stats.sh --status print the store # npm_access_stats.sh --reset forget offsets and totals, start again from the current logs # # ============================================================================================== # CONFIGURATION # ============================================================================================== # # NPM_LOG_DIR override the log directory; otherwise derived from the container's mounts # DB_DIR npm_access.json is written here # # ============================================================================================== SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" php "$SCRIPT_DIR/npm_access_stats.php" "$@"