#!/bin/sh
# Why «اقترح درجة» on attempt 28 has not answered. The question is whether anything is actually working on it.
E=/var/www/private/thinkera.academy/enterprise
G=/var/www/private/thinkera.academy/LLM-Gate

echo "=== what the platform recorded for this attempt ==="
cd "$E"
docker compose exec -T db psql -U moodle -d moodle -t -A -F'|' -c "
  SELECT slot, status, model, latencyms, tokensin, tokensout,
         to_char(to_timestamp(timecreated),'HH24:MI:SS') AS started,
         to_char(to_timestamp(timemodified),'HH24:MI:SS') AS touched,
         left(coalesce(error,''), 60) AS error
    FROM mdl_local_thinkera_aisugg WHERE attemptid = 28 ORDER BY slot;"

echo
echo "=== is a model loaded and working right now? ==="
cd "$G"
docker compose exec -T llm ollama ps

echo
echo "=== what the gate has seen (last requests) ==="
docker compose logs gate --tail 8 2>&1 | grep -v "signal" | sed 's/[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}/<ip>/g'

echo
echo "=== is Ollama busy? (its own log) ==="
docker compose logs llm --tail 6 2>&1 | tail -6

echo
echo "=== load and memory ==="
uptime
free -g | head -2
