-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmonitor.sh
More file actions
executable file
·86 lines (74 loc) · 3.91 KB
/
Copy pathmonitor.sh
File metadata and controls
executable file
·86 lines (74 loc) · 3.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/env bash
# monitor.sh - Real-time cluster bootstrap and stabilization monitor loop
logo="\033[93;44mERP\033[97;45m/1\033[0m"
set -euo pipefail
# Ensure kubectl is configured
if ! kubectl cluster-info &>/dev/null; then
echo "❌ Kubernetes cluster is unreachable!"
exit 1
fi
ARGOCD_NS="argocd"
ERP_NAMESPACES=("erp-infra" "erp-security" "erp-telemetry" "erp-ai" "erp-services" "erp-apps")
APP_NAME="erp-uno"
# Setup trap to restore cursor and exit clean on Ctrl+C
trap 'tput cnorm; echo -e "\n👋 Monitoring stopped."; exit 0' INT TERM
# Hide cursor during loop
tput civis
while true; do
clear
current_time=$(date +"%Y-%m-%d %H:%M:%S")
current_context=$(kubectl config current-context)
echo -e "╔═══════════════════════════════════════════════════════════════════════════════╗"
echo -e "║ $logo: Cluster Monitor | Time: $current_time | Context: $current_context ║"
echo -e "╚═══════════════════════════════════════════════════════════════════════════════╝"
# 1. Show ArgoCD Application Sync and Health Status
echo -e "\n[1] ArgoCD Application Status [APP: $APP_NAME]"
echo "--------------------------------------------------------------------------------"
if ARGOCD_NAMESPACE=$ARGOCD_NS argocd app get "$APP_NAME" &>/dev/null; then
ARGOCD_NAMESPACE=$ARGOCD_NS argocd app get "$APP_NAME" | grep -E "^(Name:|Sync Status:|Health Status:|Condition:)" || true
else
echo "⚠️ Application '$APP_NAME' not found or ArgoCD not running yet."
fi
# 2. Show ArgoCD component pods
echo -e "\n[2] ArgoCD System Pods"
echo "--------------------------------------------------------------------------------"
kubectl get pods -n "$ARGOCD_NS" -o custom-columns="NAME:.metadata.name,READY:.status.containerStatuses[0].ready,STATUS:.status.phase,RESTARTS:.status.containerStatuses[0].restartCount" --no-headers 2>/dev/null || echo "No pods in $ARGOCD_NS namespace."
# 3. Show ERP namespace pods
echo -e "\n[3] ERP/1 Application Pods"
echo "--------------------------------------------------------------------------------"
printf "%-18s %-45s %-7s %-8s %s\n" "NAMESPACE" "POD NAME" "READY" "STATUS" "RESTARTS"
printf "%-18s %-45s %-7s %-8s %s\n" "---------" "--------" "-----" "------" "--------"
for ns in "${ERP_NAMESPACES[@]}"; do
kubectl get pods -n "$ns" -o jsonpath='{range .items[*]}{.metadata.namespace}{"\t"}{.metadata.name}{"\t"}{.status.containerStatuses[0].ready}{"\t"}{.status.phase}{"\t"}{.status.containerStatuses[0].restartCount}{"\n"}{end}' 2>/dev/null | while read -r p_ns p_name p_ready p_status p_restarts; do
if [ -n "$p_name" ]; then
# Format the ready status from true/false to 1/1 or 0/1
ready_str="0/1"
if [ "$p_ready" = "true" ]; then
ready_str="1/1"
fi
# Truncate pod name if it's too long
printf "%-18s %-45.45s %-7s %-8s %s\n" "$p_ns" "$p_name" "$ready_str" "$p_status" "$p_restarts"
fi
done
done
# 4. Show recent warning/error events
echo -e "\n[4] Recent Kubernetes Events (ERP/1 & ArgoCD)"
echo "--------------------------------------------------------------------------------"
kubectl get events -A --sort-by='.metadata.creationTimestamp' 2>/dev/null \
| grep -E "erp-|argocd|default" \
| tail -n 8 \
| awk '{
ns = $1
type = $3
obj = $5
msg = ""
for(i=6; i<=NF; i++) {
msg = msg (i==6 ? "" : " ") $i
}
line = sprintf("%-13.13s %-7.7s %-32.32s %-50.50s", ns, type, obj, msg)
print line
}' || echo "No recent events."
echo
echo "💡 Tip: Press Ctrl+C to exit monitoring loop"
sleep 10
done