FlotillasGPS - Sistema completo de monitoreo de flotillas GPS

Sistema completo para monitoreo y gestion de flotas de vehiculos con:
- Backend FastAPI con PostgreSQL/TimescaleDB
- Frontend React con TypeScript y TailwindCSS
- App movil React Native con Expo
- Soporte para dispositivos GPS, Meshtastic y celulares
- Video streaming en vivo con MediaMTX
- Geocercas, alertas, viajes y reportes
- Autenticacion JWT y WebSockets en tiempo real

Documentacion completa y guias de usuario incluidas.
This commit is contained in:
FlotillasGPS Developer
2026-01-21 08:18:00 +00:00
commit 51d78bacf4
248 changed files with 50171 additions and 0 deletions

214
deploy/scripts/status.sh Normal file
View File

@@ -0,0 +1,214 @@
#!/bin/bash
# ============================================
# Sistema de Flotillas - Estado del Sistema
# ============================================
# Muestra informacion completa del estado
# ============================================
# Colores
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
NC='\033[0m'
INSTALL_DIR="${INSTALL_DIR:-/opt/flotillas}"
# Cargar variables
if [[ -f "$INSTALL_DIR/.env" ]]; then
export $(grep -v '^#' "$INSTALL_DIR/.env" | xargs)
fi
clear
echo ""
echo -e "${CYAN}╔══════════════════════════════════════════════════════════════╗${NC}"
echo -e "${CYAN}║ SISTEMA DE FLOTILLAS - ESTADO DEL SISTEMA ║${NC}"
echo -e "${CYAN}╚══════════════════════════════════════════════════════════════╝${NC}"
echo ""
# ---------------------------------------------
# Informacion del servidor
# ---------------------------------------------
echo -e "${BLUE}┌─ Servidor ─────────────────────────────────────────────────┐${NC}"
echo -e "│ Hostname: $(hostname)"
echo -e "│ IP: $(hostname -I | awk '{print $1}')"
echo -e "│ Sistema: $(lsb_release -ds 2>/dev/null || cat /etc/os-release | grep PRETTY_NAME | cut -d'"' -f2)"
echo -e "│ Kernel: $(uname -r)"
echo -e "│ Uptime: $(uptime -p)"
echo -e "${BLUE}└─────────────────────────────────────────────────────────────┘${NC}"
echo ""
# ---------------------------------------------
# Recursos del sistema
# ---------------------------------------------
echo -e "${BLUE}┌─ Recursos ─────────────────────────────────────────────────┐${NC}"
# CPU
CPU_USAGE=$(top -bn1 | grep "Cpu(s)" | awk '{print $2}' | cut -d'%' -f1)
echo -e "│ CPU: ${CPU_USAGE}% usado"
# Memoria
MEM_TOTAL=$(free -h | awk '/^Mem:/{print $2}')
MEM_USED=$(free -h | awk '/^Mem:/{print $3}')
MEM_PERCENT=$(free | awk '/^Mem:/{printf "%.1f", $3/$2*100}')
echo -e "│ Memoria: ${MEM_USED} / ${MEM_TOTAL} (${MEM_PERCENT}%)"
# Disco
DISK_USAGE=$(df -h / | awk 'NR==2{print $3 " / " $2 " (" $5 ")"}')
echo -e "│ Disco: ${DISK_USAGE}"
echo -e "${BLUE}└─────────────────────────────────────────────────────────────┘${NC}"
echo ""
# ---------------------------------------------
# Servicios
# ---------------------------------------------
echo -e "${BLUE}┌─ Servicios ────────────────────────────────────────────────┐${NC}"
check_service() {
local service="$1"
local name="$2"
local port="$3"
if systemctl is-active --quiet "$service" 2>/dev/null; then
local status="${GREEN}ACTIVO${NC}"
if [[ -n "$port" ]]; then
status="$status (puerto $port)"
fi
else
local status="${RED}INACTIVO${NC}"
fi
printf "│ %-14s %s\n" "$name:" "$status"
}
check_service "flotillas-api" "API Backend" "${API_PORT:-8000}"
check_service "flotillas-web" "Frontend" "${FRONTEND_PORT:-3000}"
check_service "postgresql" "PostgreSQL" "5432"
check_service "redis-server" "Redis" "6379"
check_service "traccar" "Traccar GPS" "${TRACCAR_PORT:-5055}"
check_service "mediamtx" "MediaMTX" "8554"
check_service "mosquitto" "MQTT" "1883"
check_service "cloudflared" "Cloudflare" "-"
echo -e "${BLUE}└─────────────────────────────────────────────────────────────┘${NC}"
echo ""
# ---------------------------------------------
# Base de datos
# ---------------------------------------------
echo -e "${BLUE}┌─ Base de Datos ────────────────────────────────────────────┐${NC}"
if systemctl is-active --quiet postgresql; then
# Tamanio de BD
DB_SIZE=$(PGPASSWORD="${POSTGRES_PASSWORD}" psql -h localhost -U "${POSTGRES_USER:-flotillas}" -d "${POSTGRES_DB:-flotillas}" -t -c "SELECT pg_size_pretty(pg_database_size(current_database()));" 2>/dev/null | xargs)
echo -e "│ Tamanio BD: ${DB_SIZE:-N/A}"
# Conexiones activas
CONNECTIONS=$(PGPASSWORD="${POSTGRES_PASSWORD}" psql -h localhost -U "${POSTGRES_USER:-flotillas}" -d "${POSTGRES_DB:-flotillas}" -t -c "SELECT count(*) FROM pg_stat_activity WHERE datname = current_database();" 2>/dev/null | xargs)
echo -e "│ Conexiones: ${CONNECTIONS:-N/A} activas"
# Posiciones (si existe la tabla)
POSITIONS=$(PGPASSWORD="${POSTGRES_PASSWORD}" psql -h localhost -U "${POSTGRES_USER:-flotillas}" -d "${POSTGRES_DB:-flotillas}" -t -c "SELECT COUNT(*) FROM positions;" 2>/dev/null | xargs)
if [[ -n "$POSITIONS" ]]; then
echo -e "│ Posiciones: ${POSITIONS} registros"
fi
else
echo -e "${RED}PostgreSQL no esta activo${NC}"
fi
echo -e "${BLUE}└─────────────────────────────────────────────────────────────┘${NC}"
echo ""
# ---------------------------------------------
# Redis
# ---------------------------------------------
echo -e "${BLUE}┌─ Redis Cache ──────────────────────────────────────────────┐${NC}"
if systemctl is-active --quiet redis-server; then
REDIS_AUTH=""
[[ -n "${REDIS_PASSWORD}" ]] && REDIS_AUTH="-a ${REDIS_PASSWORD}"
REDIS_KEYS=$(redis-cli $REDIS_AUTH DBSIZE 2>/dev/null | awk '{print $2}')
REDIS_MEM=$(redis-cli $REDIS_AUTH INFO memory 2>/dev/null | grep used_memory_human | cut -d: -f2 | tr -d '\r')
echo -e "│ Keys: ${REDIS_KEYS:-N/A}"
echo -e "│ Memoria: ${REDIS_MEM:-N/A}"
else
echo -e "${RED}Redis no esta activo${NC}"
fi
echo -e "${BLUE}└─────────────────────────────────────────────────────────────┘${NC}"
echo ""
# ---------------------------------------------
# Unidades GPS activas
# ---------------------------------------------
echo -e "${BLUE}┌─ GPS / Unidades ───────────────────────────────────────────┐${NC}"
if systemctl is-active --quiet postgresql; then
# Total de unidades
TOTAL_UNITS=$(PGPASSWORD="${POSTGRES_PASSWORD}" psql -h localhost -U "${POSTGRES_USER:-flotillas}" -d "${POSTGRES_DB:-flotillas}" -t -c "SELECT COUNT(*) FROM units;" 2>/dev/null | xargs)
# Unidades activas (con posicion en ultimos 5 min)
ACTIVE_UNITS=$(PGPASSWORD="${POSTGRES_PASSWORD}" psql -h localhost -U "${POSTGRES_USER:-flotillas}" -d "${POSTGRES_DB:-flotillas}" -t -c "SELECT COUNT(DISTINCT unit_id) FROM positions WHERE device_time > NOW() - INTERVAL '5 minutes';" 2>/dev/null | xargs)
echo -e "│ Total: ${TOTAL_UNITS:-0} unidades"
echo -e "│ Activas: ${ACTIVE_UNITS:-0} (ultimo 5 min)"
else
echo -e "${YELLOW}No se puede obtener info de unidades${NC}"
fi
echo -e "${BLUE}└─────────────────────────────────────────────────────────────┘${NC}"
echo ""
# ---------------------------------------------
# Streaming
# ---------------------------------------------
echo -e "${BLUE}┌─ Video Streaming ──────────────────────────────────────────┐${NC}"
if systemctl is-active --quiet mediamtx; then
# Obtener streams activos de MediaMTX API
STREAMS=$(curl -s http://localhost:9997/v3/paths/list 2>/dev/null | jq '.items | length' 2>/dev/null)
echo -e "│ Streams: ${STREAMS:-0} activos"
# Endpoints
echo -e "│ RTSP: rtsp://localhost:8554"
echo -e "│ WebRTC: http://localhost:8889"
echo -e "│ HLS: http://localhost:8888"
else
echo -e "${RED}MediaMTX no esta activo${NC}"
fi
echo -e "${BLUE}└─────────────────────────────────────────────────────────────┘${NC}"
echo ""
# ---------------------------------------------
# Ultimos errores
# ---------------------------------------------
echo -e "${BLUE}┌─ Ultimos Errores (API) ────────────────────────────────────┐${NC}"
ERRORS=$(journalctl -u flotillas-api --since "1 hour ago" -p err --no-pager -q 2>/dev/null | tail -3)
if [[ -z "$ERRORS" ]]; then
echo -e "${GREEN}Sin errores en la ultima hora${NC}"
else
echo "$ERRORS" | while read line; do
echo "$line" | cut -c1-65
done
fi
echo -e "${BLUE}└─────────────────────────────────────────────────────────────┘${NC}"
echo ""
# ---------------------------------------------
# Comandos utiles
# ---------------------------------------------
echo -e "${YELLOW}Comandos utiles:${NC}"
echo " ./health-check.sh - Verificar salud del sistema"
echo " ./logs.sh api -f - Ver logs de API en tiempo real"
echo " ./backup.sh - Crear backup"
echo " ./update.sh - Actualizar sistema"
echo ""