Skip to content

Commit 3362a61

Browse files
rainerstudiosclaude
andcommitted
Add monitoring and auto-rotation features
- Disable 30-minute auto-relog to prevent Steam rate limiting - Add automatic proxy rotation script with health checks - Add Discord bot health monitoring (every 5 minutes) - Add Discord cache performance monitoring (daily reports) - Add manual cache statistics script - Add proxy health check utility - Update game data files 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 933881f commit 3362a61

8 files changed

Lines changed: 2249 additions & 6 deletions

File tree

auto-rotate-proxies.sh

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
#!/bin/bash
2+
3+
# Auto Proxy Rotation Script
4+
# Automatically tests proxies and updates config if primary proxies fail
5+
# Run this via cron every hour or when bots disconnect
6+
7+
PROXIES=(
8+
"31.59.20.176:6754"
9+
"45.38.107.97:6014"
10+
"198.23.239.134:6540"
11+
"107.172.163.27:6543"
12+
"64.137.96.74:6641"
13+
"216.10.27.159:6837"
14+
"142.111.67.146:5611"
15+
"142.147.128.93:6593"
16+
)
17+
18+
PROXY_USER="pjukyfij"
19+
PROXY_PASS="3q9caatdky72"
20+
CONFIG_FILE="/var/www/csfloat-api/config.js"
21+
WORKING_PROXIES=()
22+
TIMESTAMP=$(date '+%Y-%m-%d %H:%M:%S')
23+
24+
echo "[$TIMESTAMP] === Auto Proxy Rotation Check ==="
25+
26+
# Test each proxy
27+
for proxy in "${PROXIES[@]}"; do
28+
echo -n "Testing $proxy... "
29+
30+
# Test proxy with 5 second timeout
31+
RESULT=$(curl --connect-timeout 5 --max-time 5 \
32+
--proxy "http://$PROXY_USER:$PROXY_PASS@$proxy/" \
33+
https://ipv4.webshare.io/ 2>&1)
34+
35+
if echo "$RESULT" | grep -qE "^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$"; then
36+
echo "✅ OK"
37+
WORKING_PROXIES+=("$proxy")
38+
else
39+
echo "❌ FAILED"
40+
fi
41+
done
42+
43+
echo ""
44+
echo "Working proxies: ${#WORKING_PROXIES[@]}/${#PROXIES[@]}"
45+
46+
# Ensure we have at least 3 working proxies
47+
if [ ${#WORKING_PROXIES[@]} -lt 3 ]; then
48+
echo "⚠️ ERROR: Only ${#WORKING_PROXIES[@]} working proxies found (need minimum 3)"
49+
echo "Service may experience issues. Manual intervention required."
50+
exit 1
51+
fi
52+
53+
# Read current proxies from config - simpler extraction
54+
CURRENT_PROXIES=$(grep "http://$PROXY_USER:$PROXY_PASS@" "$CONFIG_FILE" | grep -oE "[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:[0-9]+" | head -3)
55+
CURRENT_PROXY_1=$(echo "$CURRENT_PROXIES" | sed -n '1p')
56+
CURRENT_PROXY_2=$(echo "$CURRENT_PROXIES" | sed -n '2p')
57+
CURRENT_PROXY_3=$(echo "$CURRENT_PROXIES" | sed -n '3p')
58+
59+
echo ""
60+
echo "Current config proxies (first 3):"
61+
echo " Bot 0: $CURRENT_PROXY_1"
62+
echo " Bot 1: $CURRENT_PROXY_2"
63+
echo " Bot 2: $CURRENT_PROXY_3"
64+
65+
# Check if current proxies are still working
66+
NEEDS_UPDATE=false
67+
68+
if ! [[ " ${WORKING_PROXIES[@]} " =~ " ${CURRENT_PROXY_1} " ]]; then
69+
echo "⚠️ Bot 0 proxy ($CURRENT_PROXY_1) is DOWN - needs rotation"
70+
NEEDS_UPDATE=true
71+
fi
72+
73+
if ! [[ " ${WORKING_PROXIES[@]} " =~ " ${CURRENT_PROXY_2} " ]]; then
74+
echo "⚠️ Bot 1 proxy ($CURRENT_PROXY_2) is DOWN - needs rotation"
75+
NEEDS_UPDATE=true
76+
fi
77+
78+
if ! [[ " ${WORKING_PROXIES[@]} " =~ " ${CURRENT_PROXY_3} " ]]; then
79+
echo "⚠️ Bot 2 proxy ($CURRENT_PROXY_3) is DOWN - needs rotation"
80+
NEEDS_UPDATE=true
81+
fi
82+
83+
if [ "$NEEDS_UPDATE" = false ]; then
84+
echo "✅ All current proxies are working - no rotation needed"
85+
exit 0
86+
fi
87+
88+
# Backup current config
89+
cp "$CONFIG_FILE" "${CONFIG_FILE}.backup.$(date +%s)"
90+
echo ""
91+
echo "📝 Updating proxy configuration..."
92+
93+
# Build new proxy array
94+
PROXY_LINES=""
95+
for i in "${!WORKING_PROXIES[@]}"; do
96+
proxy="${WORKING_PROXIES[$i]}"
97+
98+
# Add comment based on position
99+
if [ $i -eq 0 ]; then
100+
comment="Bot 0 (xgamingserver3)"
101+
elif [ $i -eq 1 ]; then
102+
comment="Bot 1 (xgamingserver1)"
103+
elif [ $i -eq 2 ]; then
104+
comment="Bot 2 (johnsonk01)"
105+
else
106+
comment="Backup proxy $((i+1))"
107+
fi
108+
109+
PROXY_LINES+=" 'http://$PROXY_USER:$PROXY_PASS@$proxy/', // $comment"$'\n'
110+
done
111+
112+
# Use awk to replace the proxies section
113+
awk -v proxies="$PROXY_LINES" '
114+
/^ .proxies.: \[/ {
115+
print
116+
print proxies
117+
# Skip until closing bracket
118+
while (getline > 0) {
119+
if (/^ \],/) {
120+
print
121+
break
122+
}
123+
}
124+
next
125+
}
126+
{ print }
127+
' "$CONFIG_FILE" > "${CONFIG_FILE}.tmp" && mv "${CONFIG_FILE}.tmp" "$CONFIG_FILE"
128+
129+
echo "✅ Config updated with working proxies"
130+
echo ""
131+
echo "🔄 Restarting CSFloat API service..."
132+
133+
# Restart the pm2 service (correct name: cs2-float-api)
134+
pm2 restart cs2-float-api
135+
136+
echo "✅ Service restarted"
137+
echo ""
138+
echo "[$TIMESTAMP] Proxy rotation completed successfully"
139+
140+
# Wait a few seconds and check bot status
141+
sleep 5
142+
echo ""
143+
echo "Bot status after rotation:"
144+
curl -s http://localhost:3002/stats | grep -o '"bots_online":[0-9]*' || echo "Could not fetch status"

check-cache-stats.sh

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/bin/bash
2+
3+
# Cache Statistics Monitor
4+
# Run this to see how well your cache is performing
5+
6+
echo "=== CSFloat Cache Statistics ==="
7+
echo ""
8+
9+
# Total cached items
10+
TOTAL=$(sudo -u postgres psql -d cs2floatapi -t -c "SELECT COUNT(*) FROM items;")
11+
echo "Total Cached Items: $TOTAL"
12+
13+
# Items cached in last hour
14+
RECENT=$(sudo -u postgres psql -d cs2floatapi -t -c "SELECT COUNT(*) FROM items WHERE updated > NOW() - INTERVAL '1 hour';")
15+
echo "Cached (Last Hour): $RECENT"
16+
17+
# Items cached in last 24h
18+
DAY=$(sudo -u postgres psql -d cs2floatapi -t -c "SELECT COUNT(*) FROM items WHERE updated > NOW() - INTERVAL '24 hours';")
19+
echo "Cached (Last 24h): $DAY"
20+
21+
# Most popular weapons
22+
echo ""
23+
echo "Top 5 Most Cached Weapons:"
24+
sudo -u postgres psql -d cs2floatapi -t -c "
25+
SELECT weapon_type, COUNT(*) as count
26+
FROM (
27+
SELECT defindex,
28+
CASE defindex
29+
WHEN 7 THEN 'AK-47'
30+
WHEN 9 THEN 'AWP'
31+
WHEN 16 THEN 'M4A4'
32+
WHEN 60 THEN 'M4A1-S'
33+
WHEN 40 THEN 'USP-S'
34+
ELSE 'Other'
35+
END as weapon_type
36+
FROM items
37+
) AS weapons
38+
GROUP BY weapon_type
39+
ORDER BY count DESC
40+
LIMIT 5;
41+
" | sed 's/^/ /'
42+
43+
echo ""
44+
echo "Cache Health: $(if [ $TOTAL -gt 100 ]; then echo '✅ Excellent'; elif [ $TOTAL -gt 10 ]; then echo '✅ Good'; else echo '⚠️ Building...'; fi)"

0 commit comments

Comments
 (0)