Files
Varaverk/Plugin/unraid/Tools/npm_access_stats.sh
T
Gmer4Lfe 1041c4bba8 Show what each proxy host is actually doing, and mark the ones behind Authelia
NPM writes an access log per host and counts nothing, so 475 MB of logs held the only answer to
"is anything using this". Aggregated on a schedule and read from a few kB of JSON; the row also
now says whether an auth_request block is in front of the site, which nothing showed before.
2026-08-15 19:20:11 -04:00

44 lines
2.5 KiB
Bash
Executable File

#!/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" "$@"