Add Debian Doktor monitoring tool
This commit is contained in:
126
native_crumbcore_v1/debian-doktor.sh
Executable file
126
native_crumbcore_v1/debian-doktor.sh
Executable file
@@ -0,0 +1,126 @@
|
||||
#!/bin/bash
|
||||
# 🏥 Debian Doktor - Crumbforest Live Monitor
|
||||
#
|
||||
# Usage: ./debian-doktor.sh
|
||||
#
|
||||
# A simple TUI to monitor Crumbforest services and logs.
|
||||
|
||||
# Colors
|
||||
GREEN='\033[0;32m'
|
||||
RED='\033[0;31m'
|
||||
YELLOW='\033[1;33m'
|
||||
BLUE='\033[0;34m'
|
||||
BOLD='\033[1m'
|
||||
NC='\033[0m'
|
||||
|
||||
# Configuration
|
||||
LOG_APP="/var/log/crumbforest/crumbforest.log" # Fallback if not using journal
|
||||
LOG_NGINX_ACCESS="/var/log/nginx/crumbforest.access.log"
|
||||
LOG_NGINX_ERROR="/var/log/nginx/crumbforest.error.log"
|
||||
|
||||
# --- Functions ---
|
||||
|
||||
check_service() {
|
||||
if systemctl is-active --quiet "$1"; then
|
||||
echo -e " $1: \t${GREEN}● ONLINE${NC}"
|
||||
else
|
||||
echo -e " $1: \t${RED}● OFFLINE${NC}"
|
||||
fi
|
||||
}
|
||||
|
||||
check_port() {
|
||||
# $1 = Name, $2 = Port
|
||||
if lsof -i :$2 >/dev/null 2>&1 || ss -lptn "sport = :$2" | grep -q $2; then
|
||||
echo -e " $1 ($2): \t${GREEN}● LISTENING${NC}"
|
||||
else
|
||||
echo -e " $1 ($2): \t${RED}● CLOSED${NC}"
|
||||
fi
|
||||
}
|
||||
|
||||
check_health() {
|
||||
# $1 = Name, $2 = URL
|
||||
CODE=$(curl -s -o /dev/null -w "%{http_code}" "$2")
|
||||
if [ "$CODE" == "200" ] || [ "$CODE" == "301" ] || [ "$CODE" == "302" ]; then
|
||||
echo -e " $1 HTTP: \t${GREEN}● OK ($CODE)${NC}"
|
||||
else
|
||||
echo -e " $1 HTTP: \t${RED}● ERR ($CODE)${NC}"
|
||||
fi
|
||||
}
|
||||
|
||||
show_dashboard() {
|
||||
clear
|
||||
echo -e "${BOLD}${BLUE}========================================${NC}"
|
||||
echo -e "${BOLD}${BLUE} 🏥 Debian Doktor - Live Monitor ${NC}"
|
||||
echo -e "${BOLD}${BLUE}========================================${NC}"
|
||||
echo ""
|
||||
echo -e "${BOLD}System Status:${NC}"
|
||||
uptime | awk '{print " Load: " $8 " " $9 " " $10}'
|
||||
free -h | grep "Mem" | awk '{print " Mem: " $3 " / " $2}'
|
||||
df -h / | tail -n 1 | awk '{print " Disk: " $3 " / " $2 " (" $5 ")"}'
|
||||
echo ""
|
||||
echo -e "${BOLD}Services:${NC}"
|
||||
check_service "crumbforest"
|
||||
check_service "crumbforest-indexing"
|
||||
check_service "nginx"
|
||||
check_service "crumbmission-ttyd"
|
||||
echo ""
|
||||
echo -e "${BOLD}Ports & Connectivity:${NC}"
|
||||
check_health "App Health" "http://localhost:8000/health"
|
||||
check_health "Qdrant" "http://localhost:6333/collections"
|
||||
echo ""
|
||||
echo -e "${BOLD}Commands:${NC}"
|
||||
echo -e " ${YELLOW}[1]${NC} Tail App Log (Journal)"
|
||||
echo -e " ${YELLOW}[2]${NC} Tail Nginx Access Log"
|
||||
echo -e " ${YELLOW}[3]${NC} Tail Nginx Error Log"
|
||||
echo -e " ${YELLOW}[4]${NC} System Log (Syslog)"
|
||||
echo -e " ${YELLOW}[5]${NC} Restart Crumbforest App"
|
||||
echo -e " ${YELLOW}[6]${NC} Restart Nginx"
|
||||
echo -e " ${YELLOW}[q]${NC} Quit"
|
||||
echo ""
|
||||
}
|
||||
|
||||
tail_log() {
|
||||
clear
|
||||
echo -e "${BLUE}Tailing Log ($1)... Press Ctrl+C to return.${NC}"
|
||||
echo ""
|
||||
# Trap Ctrl+C to return to menu instead of exit
|
||||
trap 'return' INT
|
||||
if [ "$1" == "journal" ]; then
|
||||
journalctl -u crumbforest -f -n 50
|
||||
elif [ "$1" == "syslog" ]; then
|
||||
tail -f -n 50 /var/log/syslog
|
||||
else
|
||||
tail -f -n 50 "$1"
|
||||
fi
|
||||
trap - INT
|
||||
}
|
||||
|
||||
restart_service() {
|
||||
echo -e "${YELLOW}Restarting $1...${NC}"
|
||||
sudo systemctl restart "$1"
|
||||
read -p "Press Enter to continue..."
|
||||
}
|
||||
|
||||
# --- Main Loop ---
|
||||
|
||||
while true; do
|
||||
show_dashboard
|
||||
read -p "Select option: " -n 1 -r OPTION
|
||||
echo ""
|
||||
|
||||
case $OPTION in
|
||||
1) tail_log "journal" ;;
|
||||
2) tail_log "$LOG_NGINX_ACCESS" ;;
|
||||
3) tail_log "$LOG_NGINX_ERROR" ;;
|
||||
4) tail_log "syslog" ;;
|
||||
5) restart_service "crumbforest" ;;
|
||||
6) restart_service "nginx" ;;
|
||||
q|Q)
|
||||
echo "Bye! 🦉"
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
# Just refresh
|
||||
;;
|
||||
esac
|
||||
done
|
||||
Reference in New Issue
Block a user