fix: Fix tracker container names, log parsing, and regeneration

- Tracker used wrong container names (intgpsiphonclient instead of conduit)
- Tracker parsed numClients instead of [STATS] Connected: format
- Tracker script was never regenerated on update (function was inside heredoc)
- Added regen-tracker command and --update-components now calls it
- Dashboard skips recording when tracker is active (no double entries)
This commit is contained in:
SamNet-dev
2026-02-06 09:02:28 -06:00
parent e8b3dd8e9c
commit cd2827b3fe

View File

@@ -1605,17 +1605,22 @@ PEAK_CONN_FILE="$PERSIST_DIR/peak_connections"
LAST_CONN_RECORD=0 LAST_CONN_RECORD=0
CONN_RECORD_INTERVAL=300 # Record every 5 minutes CONN_RECORD_INTERVAL=300 # Record every 5 minutes
# Get container name by index (matches main script naming)
get_container_name() {
local idx=${1:-1}
if [ "$idx" -eq 1 ]; then
echo "conduit"
else
echo "conduit-${idx}"
fi
}
# Get earliest container start time (for reset detection) # Get earliest container start time (for reset detection)
get_container_start() { get_container_start() {
local earliest="" local earliest=""
local count=${CONTAINER_COUNT:-1} local count=${CONTAINER_COUNT:-1}
for i in $(seq 1 $count); do for i in $(seq 1 $count); do
local cname local cname=$(get_container_name $i)
if [ "$count" -eq 1 ]; then
cname="intgpsiphonclient"
else
cname="intgpsiphonclient${i}"
fi
local start=$(docker inspect --format='{{.State.StartedAt}}' "$cname" 2>/dev/null | cut -d'.' -f1) local start=$(docker inspect --format='{{.State.StartedAt}}' "$cname" 2>/dev/null | cut -d'.' -f1)
[ -z "$start" ] && continue [ -z "$start" ] && continue
if [ -z "$earliest" ] || [[ "$start" < "$earliest" ]]; then if [ -z "$earliest" ] || [[ "$start" < "$earliest" ]]; then
@@ -1649,15 +1654,11 @@ count_connections() {
local total_cing=0 local total_cing=0
local count=${CONTAINER_COUNT:-1} local count=${CONTAINER_COUNT:-1}
for i in $(seq 1 $count); do for i in $(seq 1 $count); do
local cname local cname=$(get_container_name $i)
if [ "$count" -eq 1 ]; then # Single docker logs call, parse both fields from same line
cname="intgpsiphonclient" local logdata=$(docker logs --tail 200 "$cname" 2>&1 | grep "\[STATS\]" | tail -1)
else local stats=$(echo "$logdata" | awk '{for(j=1;j<=NF;j++) if($j=="Connected:") print $(j+1)}')
cname="intgpsiphonclient${i}" local cing=$(echo "$logdata" | awk '{for(j=1;j<=NF;j++) if($j=="Connecting:") print $(j+1)}')
fi
# Quick tail of recent logs
local stats=$(docker logs --tail 50 "$cname" 2>&1 | grep -o 'numClients":[0-9]*' | tail -1 | grep -o '[0-9]*')
local cing=$(docker logs --tail 50 "$cname" 2>&1 | grep -o 'connectingClients":[0-9]*' | tail -1 | grep -o '[0-9]*')
total_conn=$((total_conn + ${stats:-0})) total_conn=$((total_conn + ${stats:-0}))
total_cing=$((total_cing + ${cing:-0})) total_cing=$((total_cing + ${cing:-0}))
done done
@@ -3215,8 +3216,11 @@ show_status() {
echo -e "${EL}" echo -e "${EL}"
echo -e "${CYAN}═══ Traffic (current session) ═══${NC}${EL}" echo -e "${CYAN}═══ Traffic (current session) ═══${NC}${EL}"
# Record connection history (every 5 min) # Record connection history (every 5 min) — only if tracker is not running
record_connection_history "$connected" "$connecting" # to avoid double entries and race conditions on the history file
if ! systemctl is-active conduit-tracker.service &>/dev/null 2>&1; then
record_connection_history "$connected" "$connecting"
fi
# Get connection history snapshots # Get connection history snapshots
local snap_6h=$(get_connection_snapshot 6) local snap_6h=$(get_connection_snapshot 6)
local snap_12h=$(get_connection_snapshot 12) local snap_12h=$(get_connection_snapshot 12)
@@ -7197,6 +7201,7 @@ case "${1:-menu}" in
uninstall) uninstall_all ;; uninstall) uninstall_all ;;
version|-v|--version) show_version ;; version|-v|--version) show_version ;;
help|-h|--help) show_help ;; help|-h|--help) show_help ;;
regen-tracker) setup_tracker_service 2>/dev/null ;;
menu|*) show_menu ;; menu|*) show_menu ;;
esac esac
MANAGEMENT MANAGEMENT
@@ -7385,6 +7390,8 @@ main() {
echo -e "${RED}Failed to update management script${NC}" echo -e "${RED}Failed to update management script${NC}"
exit 1 exit 1
fi fi
# Regenerate tracker via the newly installed management script
"$INSTALL_DIR/conduit" regen-tracker 2>/dev/null || true
# Rewrite conduit.service to correct format (fixes stale/old service files) # Rewrite conduit.service to correct format (fixes stale/old service files)
if command -v systemctl &>/dev/null && [ -f /etc/systemd/system/conduit.service ]; then if command -v systemctl &>/dev/null && [ -f /etc/systemd/system/conduit.service ]; then
local need_rewrite=false local need_rewrite=false