File size: 7,005 Bytes
6993919
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#!/bin/bash
# rmi-status β€” Rug Munch Intelligence System Status & Profit Checker
# Auto-loads on terminal start via .bashrc
# Fast (<2s): parallel checks, cached data, Supabase-backed earnings
# Usage: rmi-status [--watch]

API="${RMI_API_URL:-http://localhost:8000}"
RED='\033[0;31m'; GREEN='\033[0;32m'; YELLOW='\033[1;33m'; CYAN='\033[0;36m'; BOLD='\033[1m'; NC='\033[0m'
ok()    { printf "  ${GREEN}βœ“${NC} %s\n" "$1"; }
warn()  { printf "  ${YELLOW}⚠${NC} %s\n" "$1"; }
fail()  { printf "  ${RED}βœ—${NC} %s\n" "$1"; }
header(){ printf "\n${BOLD}${CYAN}━━━ %s ━━━${NC}\n" "$1"; }
money() { printf "${GREEN}\$%'.2f${NC}" "$1"; }

# ── HEADER ──
clear
printf "${BOLD}${CYAN}"
printf "╔══════════════════════════════════════════════════════╗\n"
printf "β•‘   RUG MUNCH INTELLIGENCE β€” System Status            β•‘\n"
printf "β•‘   %-50s β•‘\n" "$(date '+%Y-%m-%d %H:%M:%S')"
printf "β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•${NC}\n"

# ── EARNINGS (from backend dashboard + Supabase fallback) ──
header "EARNINGS"

DASH=$(curl -s --max-time 3 "${API}/api/v1/x402/dashboard" 2>/dev/null)
if [ -n "$DASH" ]; then
  TOTAL=$(echo "$DASH" | python3 -c "import json,sys; d=json.load(sys.stdin); e=d.get('earnings',{}); print(e.get('total_earnings_usdc',0))" 2>/dev/null)
  TODAY=$(echo "$DASH" | python3 -c "import json,sys; d=json.load(sys.stdin); e=d.get('earnings',{}); print(e.get('today_earnings_usdc',0))" 2>/dev/null)
  PAYERS=$(echo "$DASH" | python3 -c "import json,sys; d=json.load(sys.stdin); e=d.get('earnings',{}); print(e.get('unique_payers',0))" 2>/dev/null)
  SB_TOTAL=$(echo "$DASH" | python3 -c "import json,sys; d=json.load(sys.stdin); print(d.get('supabase',{}).get('total_usdc',0))" 2>/dev/null)
  SB_COUNT=$(echo "$DASH" | python3 -c "import json,sys; d=json.load(sys.stdin); print(d.get('supabase',{}).get('persisted_count',0))" 2>/dev/null)
  BY_CHAIN=$(echo "$DASH" | python3 -c "import json,sys; d=json.load(sys.stdin); e=d.get('earnings',{}).get('earnings_by_chain',{}); print(' | '.join(f'{k}: \${v:,.0f}' for k,v in sorted(e.items(), key=lambda x:-x[1])[:4]))" 2>/dev/null)
  TRIALS=$(echo "$DASH" | python3 -c "import json,sys; d=json.load(sys.stdin); t=d.get('trials',{}); print(f\"{t.get('trials_today',0)} today / {t.get('trials_all_time',0)} all\")" 2>/dev/null)
  REDIS_OK=$(echo "$DASH" | python3 -c "import json,sys; print('yes' if json.load(sys.stdin).get('meta',{}).get('redis_available') else 'no')" 2>/dev/null)

  printf "  %-22s %s\n" "Revenue (All-Time):"   "$(money "${TOTAL:-0}")"
  printf "  %-22s %s\n" "Revenue (Today):"      "$(money "${TODAY:-0}")"
  printf "  %-22s %s\n" "Unique Payers:"        "${PAYERS:-0}"
  printf "  %-22s %s\n" "By Chain:"             "${BY_CHAIN:-?}"
  printf "  %-22s %s\n" "Supabase Stored:"      "\$${SB_TOTAL:-0} (${SB_COUNT:-0} records)"
  printf "  %-22s %s\n" "Trials:"               "${TRIALS:-?}"
  printf "  %-22s %s\n" "Redis:"                "${REDIS_OK}"
else
  warn "Backend dashboard unreachable"
fi

# ── SYSTEM HEALTH (parallel docker checks) ──
header "SYSTEM HEALTH"

# Check backend
BE=$(curl -s -o /dev/null -w "%{http_code}" --max-time 2 "${API}/health" 2>/dev/null)
[ "$BE" = "200" ] && ok "Backend API" || fail "Backend API (HTTP $BE)"

# Docker containers β€” fast inline checks
for c in rmi-backend rmi-redis rmi-worker rmi-n8n rmi-orchestrator rmi-cloudflare; do
  STATUS=$(docker inspect --format='{{.State.Status}}' "$c" 2>/dev/null)
  case "$STATUS" in
    running) ok "$c" ;;
    "")      warn "$c β€” not found" ;;
    *)       fail "$c β€” $STATUS" ;;
  esac
done

# ── GATEWAY WORKERS (fast, parallel) ──
header "GATEWAY WORKERS"

# Check Solana gateway
SOL_H=$(curl -s --max-time 3 "https://sol.rugmunch.io/health" 2>/dev/null)
if [ -n "$SOL_H" ]; then
  SOL_RMI=$(echo "$SOL_H" | python3 -c "import json,sys; d=json.load(sys.stdin); t=d.get('tools',{}); print(t.get('rmi_paid',0)+t.get('mcp',0))" 2>/dev/null)
  ok "Solana Gateway β€” ${SOL_RMI:-?} tools"
else
  fail "Solana Gateway"
fi

# Check Base gateway
BASE_H=$(curl -s --max-time 3 "https://base.rugmunch.io/health" 2>/dev/null)
if [ -n "$BASE_H" ]; then
  BASE_T=$(echo "$BASE_H" | python3 -c "import json,sys; d=json.load(sys.stdin); t=d.get('tools',{}); print(t.get('rmi_paid',0)+t.get('mcp',0))" 2>/dev/null)
  ok "Base Gateway β€” ${BASE_T:-?} tools"
else
  fail "Base Gateway"
fi

# MCP Router
MCP=$(curl -s -o /dev/null -w "%{http_code}" --max-time 2 "https://mcp-router.rugmunch.io/tools" 2>/dev/null)
[ "$MCP" = "200" ] && ok "MCP Router" || warn "MCP Router (HTTP $MCP)"

# ── RESOURCES ──
header "RESOURCES"

# Disk
DISK=$(df -h / | tail -1 | awk '{printf "%s used (%s/%s)", $5, $3, $2}')
printf "  ${GREEN}●${NC} Disk:  %s\n" "$DISK"

# Memory
MEM=$(free -h | awk '/^Mem:/ {printf "%s free / %s total", $4, $2}')
printf "  ${GREEN}●${NC} Memory: %s\n" "$MEM"

# CPU (quick snapshot)
CPU=$(top -bn1 | grep "Cpu(s)" | awk '{print $2}' | cut -d'%' -f1 2>/dev/null)
printf "  ${GREEN}●${NC} CPU:    %s%% used\n" "${CPU:-?}"

# ── KEY URLS ──
header "ENDPOINTS"
printf "  Solana:  ${CYAN}https://sol.rugmunch.io${NC}\n"
printf "  Base:    ${CYAN}https://base.rugmunch.io${NC}\n"
printf "  MCP Docs:${CYAN}https://sol.rugmunch.io/mcp-x402-docs${NC}\n"

# ── WALLET FACTORY ──
header "WALLET FACTORY (25+ chains)"
WALLET_API=$(curl -s --max-time 2 "http://localhost:8000/api/v1/wallets/stats" 2>/dev/null)
if [ -n "$WALLET_API" ]; then
  CHAINS=$(echo "$WALLET_API" | python3 -c "import json,sys; d=json.load(sys.stdin); print(d.get('chains_supported','?'))" 2>/dev/null)
  GEN=$(echo "$WALLET_API" | python3 -c "import json,sys; d=json.load(sys.stdin); print(d.get('generation_count','?'))" 2>/dev/null)
  ok "Wallet Factory Active β€” ${CHAINS:-?} chains, ${GEN:-0} generated"
else
  warn "Wallet Factory β€” backend not responding"
fi

# Vault status
VAULT="/root/.rmi/wallets/vault.json"
if [ -f "$VAULT" ]; then
  VAULT_COUNT=$(python3 -c "import json; d=json.load(open('$VAULT')); print(d.get('_meta',{}).get('total_wallets',0))" 2>/dev/null)
  printf "  ${GREEN}●${NC} Vault:   %s wallets stored\\n" "${VAULT_COUNT:-?}"
else
  printf "  ${YELLOW}●${NC} Vault:   empty (generate wallets at /api/v1/wallets/generate)\\n"
fi

# Payment wallets
printf "  ${GREEN}●${NC} EVM:     ${CYAN}0x1E3AC...905C9${NC}\n"
printf "  ${GREEN}●${NC} Solana:  ${CYAN}Gix4P9...MpFzv${NC}\n"
printf "  ${GREEN}●${NC} TRON:    ${CYAN}TYFBXi...eyZu8${NC}\n"
printf "  ${GREEN}●${NC} Bitcoin: ${CYAN}1DkQAf...aM3Md${NC}\n"
printf "  Backend: ${CYAN}${API}${NC}\n"
printf "  Website: ${CYAN}https://rugmunch.io${NC}\n"

echo ""
printf "${BOLD}${CYAN}Run 'rmi-status' anytime. Add --watch for 30s refresh.${NC}\n"
echo ""