#!/bin/bash # Run sysmonstm collector only (for secondary machines) # Usage: ./ctrl/collector.sh [aggregator-ip] [--remote] # # Examples: # ./ctrl/collector.sh 192.168.1.33 # Build locally (default) # ./ctrl/collector.sh 192.168.1.33 --remote # Use registry image cd "$(dirname "$0")/.." AGGREGATOR_IP=${1:-192.168.1.33} MACHINE_ID=$(hostname) USE_REMOTE=false if [ "$2" = "--remote" ]; then USE_REMOTE=true fi # Check if aggregator is reachable echo "Checking connection to aggregator at $AGGREGATOR_IP:50051..." if ! nc -z -w 3 "$AGGREGATOR_IP" 50051 2>/dev/null; then echo "" echo "ERROR: Cannot connect to aggregator at $AGGREGATOR_IP:50051" echo "" echo "Make sure the full stack is running on the main machine first:" echo " cd ~/wdir/sms && ./ctrl/run.sh" echo "" exit 1 fi echo "Aggregator reachable." if [ "$USE_REMOTE" = true ]; then IMAGE="registry.mcrn.ar/sysmonstm/collector:latest" echo "Using remote image: $IMAGE" else IMAGE="sysmonstm-collector:local" echo "Building local image..." docker build -t $IMAGE -f services/collector/Dockerfile . fi echo "Starting collector for $MACHINE_ID -> $AGGREGATOR_IP:50051" docker run --rm --name sysmonstm-collector --network host \ -e AGGREGATOR_URL=${AGGREGATOR_IP}:50051 \ -e MACHINE_ID=${MACHINE_ID} \ $IMAGE