#!/bin/bash # # Simple M3DB connectivity test # Usage: ./test-metrics.sh # set -e LB_IP="${1:-}" if [ -z "$LB_IP" ]; then echo "Usage: $0 " echo "Example: $0 192.168.1.100" exit 1 fi BASE_URL="http://${LB_IP}:7201" echo "=== M3DB Connectivity Test ===" echo "Target: ${BASE_URL}" echo "" # Health check echo "1. Coordinator Health" if curl -sf "${BASE_URL}/health" > /dev/null 2>&1; then echo " ✓ Healthy" else echo " ✗ Unhealthy or unreachable" exit 1 fi # Placement echo "" echo "2. Placement (cluster topology)" PLACEMENT=$(curl -sf "${BASE_URL}/api/v1/services/m3db/placement" 2>/dev/null || echo '{}') INSTANCE_COUNT=$(echo "$PLACEMENT" | python3 -c "import sys,json; d=json.load(sys.stdin).get('placement',{}).get('instances',{}); print(len(d))" 2>/dev/null || echo "0") if [ "$INSTANCE_COUNT" -gt 0 ]; then echo " ✓ $INSTANCE_COUNT instances in placement" echo "$PLACEMENT" | python3 -c "import sys,json; d=json.load(sys.stdin).get('placement',{}).get('instances',{}); [print(f' - {k}') for k in d.keys()]" 2>/dev/null || true else echo " ✗ No placement configured (run init job)" fi # Namespaces echo "" echo "3. Namespaces (retention policies)" NAMESPACES=$(curl -sf "${BASE_URL}/api/v1/services/m3db/namespace" 2>/dev/null || echo '{}') NS_COUNT=$(echo "$NAMESPACES" | python3 -c "import sys,json; d=json.load(sys.stdin).get('registry',{}).get('namespaces',{}); print(len(d))" 2>/dev/null || echo "0") if [ "$NS_COUNT" -gt 0 ]; then echo " ✓ $NS_COUNT namespaces configured" echo "$NAMESPACES" | python3 -c "import sys,json; d=json.load(sys.stdin).get('registry',{}).get('namespaces',{}); [print(f' - {k}') for k in d.keys()]" 2>/dev/null || true else echo " ✗ No namespaces configured (run init job)" fi # Query test echo "" echo "4. Query Test (PromQL)" QUERY_RESULT=$(curl -sf "${BASE_URL}/api/v1/query?query=up" 2>/dev/null || echo '{"status":"error"}') STATUS=$(echo "$QUERY_RESULT" | python3 -c "import sys,json; print(json.load(sys.stdin).get('status','error'))" 2>/dev/null || echo "error") if [ "$STATUS" = "success" ]; then RESULT_COUNT=$(echo "$QUERY_RESULT" | python3 -c "import sys,json; print(len(json.load(sys.stdin).get('data',{}).get('result',[])))" 2>/dev/null || echo "0") echo " ✓ Query returned: $RESULT_COUNT series" else echo " ✗ Query failed" fi # Write test (requires protobuf + snappy, so just note it) echo "" echo "5. Write Test" echo " Note: Prometheus remote_write requires protobuf + snappy encoding." echo " Use test-metrics.py for full write/read verification." echo " Install: pip install python-snappy requests" echo "" echo "=== Test Complete ==="