Files
mev-beta/orig/monitoring/dashboard.sh
Administrator c54c569f30 refactor: move all remaining files to orig/ directory
Completed clean root directory structure:
- Root now contains only: .git, .env, docs/, orig/
- Moved all remaining files and directories to orig/:
  - Config files (.claude, .dockerignore, .drone.yml, etc.)
  - All .env variants (except active .env)
  - Git config (.gitconfig, .github, .gitignore, etc.)
  - Tool configs (.golangci.yml, .revive.toml, etc.)
  - Documentation (*.md files, @prompts)
  - Build files (Dockerfiles, Makefile, go.mod, go.sum)
  - Docker compose files
  - All source directories (scripts, tests, tools, etc.)
  - Runtime directories (logs, monitoring, reports)
  - Dependency files (node_modules, lib, cache)
  - Special files (--delete)

- Removed empty runtime directories (bin/, data/)

V2 structure is now clean:
- docs/planning/ - V2 planning documents
- orig/ - Complete V1 codebase preserved
- .env - Active environment config (not in git)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-10 10:53:05 +01:00

181 lines
6.1 KiB
Bash
Executable File

#!/bin/bash
# Real-time MEV Bot Monitoring Dashboard
# Updates every 5 seconds with live statistics
set -e
# Configuration
REFRESH_INTERVAL=5
LOG_DIR="logs/24h_test"
MAIN_LOG_DIR="logs"
# Colors
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Function to get latest log
get_latest_log() {
# Check 24h test log first
LATEST=$(ls -t ${LOG_DIR}/test_*.log 2>/dev/null | head -1)
if [ -z "${LATEST}" ]; then
# Fall back to main log
LATEST="${MAIN_LOG_DIR}/mev_bot.log"
fi
echo "${LATEST}"
}
# Function to clear screen
clear_screen() {
clear
echo -e "${BLUE}╔════════════════════════════════════════════════════════════╗${NC}"
echo -e "${BLUE}║ MEV Bot Real-Time Monitoring Dashboard ║${NC}"
echo -e "${BLUE}╚════════════════════════════════════════════════════════════╝${NC}"
echo ""
}
# Function to display stats
display_stats() {
LOG_FILE=$(get_latest_log)
if [ ! -f "${LOG_FILE}" ]; then
echo -e "${RED}❌ No log file found${NC}"
return
fi
# Get last 1000 lines for performance
RECENT_LOGS=$(tail -1000 "${LOG_FILE}")
# Calculate stats
BLOCKS=$(echo "${RECENT_LOGS}" | grep -c "Processing.*transactions" || echo "0")
DEX=$(echo "${RECENT_LOGS}" | grep -c "DEX Transaction detected" || echo "0")
OPPS=$(echo "${RECENT_LOGS}" | grep -c "ARBITRAGE OPPORTUNITY" || echo "0")
PROFITABLE=$(echo "${RECENT_LOGS}" | grep "ARBITRAGE OPPORTUNITY" | grep -c "isExecutable:true" || echo "0")
ERRORS=$(echo "${RECENT_LOGS}" | grep -c "\[ERROR\]" || echo "0")
WARNS=$(echo "${RECENT_LOGS}" | grep -c "\[WARN\]" || echo "0")
# Check if bot is running
PID_FILE="${LOG_DIR}/mev-bot.pid"
BOT_STATUS="${RED}❌ Not Running${NC}"
UPTIME="N/A"
if [ -f "${PID_FILE}" ]; then
PID=$(cat "${PID_FILE}")
if ps -p "${PID}" > /dev/null 2>&1; then
BOT_STATUS="${GREEN}✅ Running (PID: ${PID})${NC}"
UPTIME=$(ps -o etime= -p "${PID}" | tr -d ' ')
fi
fi
# Display
echo -e "${BLUE}📊 System Status${NC}"
echo " Status: ${BOT_STATUS}"
echo " Uptime: ${UPTIME}"
echo " Log: ${LOG_FILE}"
echo ""
echo -e "${BLUE}📈 Performance (Last 1000 lines)${NC}"
echo " Blocks Processed: ${BLOCKS}"
echo " DEX Transactions: ${DEX}"
if [ "${BLOCKS}" -gt "0" ]; then
DEX_RATE=$(awk "BEGIN {printf \"%.2f\", (${DEX} / ${BLOCKS}) * 100}")
echo " DEX Rate: ${DEX_RATE}%"
fi
echo ""
echo -e "${BLUE}🎯 Opportunities${NC}"
echo " Total Detected: ${OPPS}"
echo -e " Profitable: ${GREEN}${PROFITABLE}${NC}"
echo " Rejected: $((OPPS - PROFITABLE))"
if [ "${OPPS}" -gt "0" ]; then
SUCCESS_RATE=$(awk "BEGIN {printf \"%.2f\", (${PROFITABLE} / ${OPPS}) * 100}")
echo " Success Rate: ${SUCCESS_RATE}%"
fi
echo ""
# Latest opportunities
echo -e "${BLUE}💰 Recent Opportunities (Last 5)${NC}"
echo "${RECENT_LOGS}" | grep "netProfitETH:" | tail -5 | while read line; do
PROFIT=$(echo "$line" | grep -o 'netProfitETH:[^ ]*' | cut -d: -f2)
EXECUTABLE=$(echo "$line" | grep -o 'isExecutable:[^ ]*' | cut -d: -f2)
if [ "${EXECUTABLE}" = "true" ]; then
echo -e " ${GREEN}${NC} ${PROFIT} ETH"
else
echo -e " ${RED}${NC} ${PROFIT} ETH"
fi
done || echo " No opportunities yet"
echo ""
# Cache metrics
echo -e "${BLUE}💾 Cache Performance${NC}"
CACHE=$(echo "${RECENT_LOGS}" | grep "Reserve cache metrics" | tail -1)
if [ -n "${CACHE}" ]; then
HIT_RATE=$(echo "${CACHE}" | grep -o 'hitRate=[0-9.]*' | cut -d= -f2)
HITS=$(echo "${CACHE}" | grep -o 'hits=[0-9]*' | cut -d= -f2)
MISSES=$(echo "${CACHE}" | grep -o 'misses=[0-9]*' | cut -d= -f2)
ENTRIES=$(echo "${CACHE}" | grep -o 'entries=[0-9]*' | cut -d= -f2)
if [ -n "${HIT_RATE}" ]; then
HIT_RATE_INT=$(echo "${HIT_RATE}" | cut -d. -f1)
if [ "${HIT_RATE_INT}" -ge "75" ]; then
COLOR="${GREEN}"
elif [ "${HIT_RATE_INT}" -ge "60" ]; then
COLOR="${YELLOW}"
else
COLOR="${RED}"
fi
echo -e " Hit Rate: ${COLOR}${HIT_RATE}%${NC}"
fi
echo " Hits: ${HITS}"
echo " Misses: ${MISSES}"
echo " Entries: ${ENTRIES}"
else
echo " Not available (multihop not triggered)"
fi
echo ""
# Errors
echo -e "${BLUE}⚠️ Issues${NC}"
if [ "${ERRORS}" -gt "0" ]; then
echo -e " Errors: ${RED}${ERRORS}${NC}"
else
echo -e " Errors: ${GREEN}0${NC}"
fi
if [ "${WARNS}" -gt "10" ]; then
echo -e " Warnings: ${YELLOW}${WARNS}${NC}"
else
echo " Warnings: ${WARNS}"
fi
# Recent error
if [ "${ERRORS}" -gt "0" ]; then
echo ""
echo " Latest Error:"
echo "${RECENT_LOGS}" | grep "\[ERROR\]" | tail -1 | sed 's/^/ /' | cut -c1-80
fi
echo ""
# Protocol distribution
echo -e "${BLUE}📊 Protocol Distribution (Last 100 opportunities)${NC}"
echo "${RECENT_LOGS}" | grep "protocol:" | tail -100 | \
grep -o 'protocol:[A-Za-z0-9_]*' | \
sort | uniq -c | sort -rn | head -5 | \
awk '{printf " %-20s %d\n", substr($2, 10), $1}' || echo " No data yet"
echo ""
# Footer
echo -e "${BLUE}════════════════════════════════════════════════════════════${NC}"
echo "Last updated: $(date)"
echo "Press Ctrl+C to exit | Refreshing every ${REFRESH_INTERVAL}s"
}
# Main loop
trap "echo ''; echo 'Dashboard stopped'; exit 0" INT TERM
while true; do
clear_screen
display_stats
sleep ${REFRESH_INTERVAL}
done