62 lines
1.6 KiB
Bash
Executable File
62 lines
1.6 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Load shared libraries
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
source "$SCRIPT_DIR/../lib/init.sh"
|
|
|
|
# Script to help migrate projects to shared monitoring stack
|
|
|
|
set -e
|
|
|
|
PROJECT_NAME="${1:-}"
|
|
NAMESPACE="${2:-default}"
|
|
|
|
if [ -z "$PROJECT_NAME" ]; then
|
|
echo "📊 Monitoring Migration Helper"
|
|
echo ""
|
|
echo "Usage: $0 <project-name> [namespace]"
|
|
echo ""
|
|
echo "This script helps migrate a project to use the shared monitoring stack."
|
|
echo ""
|
|
exit 1
|
|
fi
|
|
|
|
echo "📊 Migrating $PROJECT_NAME to shared monitoring stack..."
|
|
|
|
# Check if ServiceMonitor CRD exists
|
|
if ! kubectl get crd servicemonitors.monitoring.coreos.com &>/dev/null; then
|
|
echo "⚠️ ServiceMonitor CRD not found"
|
|
echo " → Ensure Prometheus operator is installed"
|
|
exit 1
|
|
fi
|
|
|
|
# Create ServiceMonitor template
|
|
cat > "/tmp/${PROJECT_NAME}-servicemonitor.yaml" << EOF
|
|
apiVersion: monitoring.coreos.com/v1
|
|
kind: ServiceMonitor
|
|
metadata:
|
|
name: ${PROJECT_NAME}
|
|
namespace: ${NAMESPACE}
|
|
labels:
|
|
app: ${PROJECT_NAME}
|
|
spec:
|
|
selector:
|
|
matchLabels:
|
|
app: ${PROJECT_NAME}
|
|
endpoints:
|
|
- port: metrics
|
|
path: /metrics
|
|
interval: 30s
|
|
EOF
|
|
|
|
echo "✅ Created ServiceMonitor template: /tmp/${PROJECT_NAME}-servicemonitor.yaml"
|
|
echo ""
|
|
echo "📝 Next steps:"
|
|
echo " 1. Ensure your service exposes metrics on /metrics endpoint"
|
|
echo " 2. Add 'metrics' port to your service"
|
|
echo " 3. Review and apply ServiceMonitor:"
|
|
echo " kubectl apply -f /tmp/${PROJECT_NAME}-servicemonitor.yaml"
|
|
echo ""
|
|
echo "📖 See docs/K8S_MIGRATION_GUIDE.md for detailed instructions"
|
|
|