2026-03-31 15:49:59 +00:00
#!/bin/bash
#
# Simple M3DB connectivity test
2026-04-01 05:19:14 +00:00
# Usage: ./test-metrics.sh <BASE_URL> [USERNAME] [PASSWORD]
#
# Examples:
# ./test-metrics.sh https://m3db.vultrlabs.dev example example
# ./test-metrics.sh http://192.168.1.100:7201
2026-03-31 15:49:59 +00:00
#
set -e
2026-04-01 02:38:47 +00:00
BASE_URL = " ${ 1 :- } "
2026-04-01 05:19:14 +00:00
USERNAME = " ${ 2 :- } "
PASSWORD = " ${ 3 :- } "
2026-04-01 02:38:47 +00:00
if [ -z " $BASE_URL " ] ; then
2026-04-01 05:19:14 +00:00
echo " Usage: $0 <BASE_URL> [USERNAME] [PASSWORD] "
echo " Example: $0 https://m3db.vultrlabs.dev example example "
2026-04-01 02:38:47 +00:00
echo " $0 http://192.168.1.100:7201 "
2026-03-31 15:49:59 +00:00
exit 1
fi
2026-04-01 02:38:47 +00:00
# Remove trailing slash if present
BASE_URL = " ${ BASE_URL %/ } "
2026-03-31 15:49:59 +00:00
2026-04-01 05:19:14 +00:00
# Build auth flag if credentials provided
AUTH_FLAG = ""
if [ -n " $USERNAME " ] && [ -n " $PASSWORD " ] ; then
AUTH_FLAG = " -u ${ USERNAME } : ${ PASSWORD } "
fi
2026-03-31 15:49:59 +00:00
echo "=== M3DB Connectivity Test ==="
echo " Target: ${ BASE_URL } "
2026-04-01 05:19:14 +00:00
if [ -n " $AUTH_FLAG " ] ; then
echo " Auth: ${ USERNAME } :*** "
fi
2026-03-31 15:49:59 +00:00
echo ""
# Health check
echo "1. Coordinator Health"
2026-04-01 05:19:14 +00:00
if curl -sf $AUTH_FLAG " ${ BASE_URL } /health " > /dev/null 2>& 1; then
2026-03-31 15:49:59 +00:00
echo " ✓ Healthy"
else
echo " ✗ Unhealthy or unreachable"
exit 1
fi
# Placement
echo ""
echo "2. Placement (cluster topology)"
2026-04-01 05:19:14 +00:00
PLACEMENT = $( curl -sf $AUTH_FLAG " ${ BASE_URL } /api/v1/services/m3db/placement " 2>/dev/null || echo '{}' )
2026-03-31 15:49:59 +00:00
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)"
2026-04-01 05:19:14 +00:00
NAMESPACES = $( curl -sf $AUTH_FLAG " ${ BASE_URL } /api/v1/services/m3db/namespace " 2>/dev/null || echo '{}' )
2026-03-31 15:49:59 +00:00
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)"
2026-04-01 05:19:14 +00:00
QUERY_RESULT = $( curl -sf $AUTH_FLAG " ${ BASE_URL } /api/v1/query?query=up " 2>/dev/null || echo '{"status":"error"}' )
2026-03-31 15:49:59 +00:00
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 ==="