Added xray exporter
All checks were successful
Update Kubernetes Services Wiki / Generate and Update K8s Wiki (push) Successful in 11s
Check with kubeconform / lint (push) Successful in 16s
Auto-update README / Generate README and Create MR (push) Successful in 8s

This commit is contained in:
Ultradesu
2025-11-18 14:39:05 +02:00
parent 776109d795
commit 887a9a2306

View File

@@ -172,31 +172,43 @@ data:
mv /tmp/v2ray-exporter /usr/local/bin/v2ray-exporter mv /tmp/v2ray-exporter /usr/local/bin/v2ray-exporter
chmod +x /usr/local/bin/v2ray-exporter chmod +x /usr/local/bin/v2ray-exporter
# Wait for xray API port file from pasarguard-node container # Wait for initial API port file
echo "Waiting for xray API port file..." echo "Waiting for initial xray API port file..."
while [ ! -f /shared/xray-api-port ]; do
echo "Waiting for API port file..."
sleep 2
done
# Main loop - restart exporter if it crashes or port changes
while true; do while true; do
if [ -f /shared/xray-api-port ]; then if [ -f /shared/xray-api-port ]; then
API_PORT=$(cat /shared/xray-api-port) API_PORT=$(cat /shared/xray-api-port)
if [ -n "$API_PORT" ]; then if [ -n "$API_PORT" ]; then
echo "Got xray API port from shared volume: $API_PORT" echo "Starting v2ray-exporter with endpoint 127.0.0.1:$API_PORT"
/usr/local/bin/v2ray-exporter --v2ray-endpoint "127.0.0.1:$API_PORT" --listen ":9550" &
EXPORTER_PID=$!
# Verify the port is working # Wait for exporter to exit or port file to change
if curl -s -o /dev/null -w "%{http_code}" --max-time 2 "127.0.0.1:$API_PORT" 2>&1 | grep -q "Received HTTP/0.9"; then while kill -0 $EXPORTER_PID 2>/dev/null; do
echo "Verified API port: $API_PORT" if [ -f /shared/xray-api-port ]; then
break NEW_PORT=$(cat /shared/xray-api-port)
else if [ "$NEW_PORT" != "$API_PORT" ]; then
echo "Port verification failed, waiting..." echo "API port changed from $API_PORT to $NEW_PORT, restarting exporter"
fi kill $EXPORTER_PID 2>/dev/null
wait $EXPORTER_PID 2>/dev/null
break
fi
fi
sleep 5
done
echo "Exporter stopped, restarting..."
wait $EXPORTER_PID 2>/dev/null
fi fi
fi fi
echo "Waiting for valid xray API port... retrying in 5 seconds" sleep 2
sleep 5
done done
# Start exporter
echo "Starting v2ray-exporter with endpoint 127.0.0.1:$API_PORT"
exec /usr/local/bin/v2ray-exporter --v2ray-endpoint "127.0.0.1:$API_PORT" --listen ":9550"
pasarguard-start.sh: | pasarguard-start.sh: |
#!/bin/sh #!/bin/sh
# Read API_KEY from shared volume created by init container # Read API_KEY from shared volume created by init container
@@ -213,21 +225,25 @@ data:
./main & ./main &
MAIN_PID=$! MAIN_PID=$!
# Wait a bit for xray to start # Start continuous port monitoring in background
sleep 10 {
sleep 10 # Wait for xray to start initially
LAST_PORT=""
while true; do
API_PORT=$(netstat -tlpn | grep xray | grep 127.0.0.1 | awk '{print $4}' | cut -d: -f2 | head -1)
if [ -n "$API_PORT" ] && [ "$API_PORT" != "$LAST_PORT" ]; then
echo "Found xray API port: $API_PORT"
echo -n "$API_PORT" > /shared/xray-api-port
LAST_PORT="$API_PORT"
fi
sleep 5 # Check every 5 seconds
done
} &
PORT_MONITOR_PID=$!
# Find xray API port and save to shared volume # Wait for main process to finish
echo "Looking for xray API port..."
for i in {1..60}; do
API_PORT=$(netstat -tlpn | grep xray | grep 127.0.0.1 | awk '{print $4}' | cut -d: -f2 | head -1)
if [ -n "$API_PORT" ]; then
echo "Found xray API port: $API_PORT"
echo -n "$API_PORT" > /shared/xray-api-port
break
fi
echo "Waiting for xray API port... ($i/60)"
sleep 1
done
# Continue running main process
wait $MAIN_PID wait $MAIN_PID
# Clean up port monitor
kill $PORT_MONITOR_PID 2>/dev/null