diff --git a/VISUALIZATION_SETUP.md b/VISUALIZATION_SETUP.md new file mode 100644 index 0000000..df4485e --- /dev/null +++ b/VISUALIZATION_SETUP.md @@ -0,0 +1,305 @@ +# 📊 Configuración de Herramientas de Visualización + +## ✅ Estado de Configuración + +Todas las herramientas de visualización están conectadas a PostgreSQL y ClickHouse: + +- ✅ **Grafana** - Datasources configurados via provisioning YAML +- ✅ **Metabase** - Configuración automática via API (sin UI) +- ✅ **Rill** - Sources configurados en rill.yaml + +--- + +## 🔑 Credenciales de Acceso + +### Grafana +- **URL**: http://localhost:3500 +- **Usuario**: `admin` +- **Contraseña**: `admin123` +- **Datasources configurados**: + - PostgreSQL (postgres-main:5432) + - ClickHouse (clickhouse:8123) + - Prometheus + - Loki + - Tempo + +### Metabase +- **URL**: http://localhost:3200 +- **Usuario**: `admin@example.com` +- **Contraseña**: `Admin123!@#` +- **Datasources configurados**: + - PostgreSQL Main (postgres-main:5432) + - ClickHouse Analytics (clickhouse:8123) + - Sample Database (H2 - demo) + +### Rill +- **URL**: http://localhost:9009 +- **Autenticación**: No requiere +- **Sources configurados**: + - `postgres_main` (postgres-main:5432) + - `clickhouse_main` (clickhouse:9000) + +--- + +## 🚀 Configuración Automática de Metabase + +El script `configure_metabase.py` configura automáticamente Metabase: + +### Primera vez (setup inicial): +```bash +cd /home/lucas/dagu/scripts +./configure_metabase.py +``` + +Este script: +1. ✅ Detecta si Metabase necesita setup inicial +2. ✅ Crea usuario admin automáticamente +3. ✅ Configura datasources de PostgreSQL y ClickHouse +4. ✅ Todo sin interacción manual + +### Si reseteas Metabase: +```bash +# Eliminar datos de Metabase +docker-compose -f docker-compose-analytics.yml down metabase metabase-db +docker volume rm automatic_process_metabase-data + +# Reiniciar y configurar automáticamente +docker-compose -f docker-compose-analytics.yml up -d metabase-db metabase +sleep 50 # Esperar a que inicie +./configure_metabase.py +``` + +--- + +## 🔧 Archivos de Configuración + +### Grafana +**Ubicación**: `/home/lucas/DataProyects/suite_logs/config/grafana/provisioning/datasources/datasources.yml` + +Datasources PostgreSQL y ClickHouse añadidos automáticamente al desplegar Grafana. + +### Rill +**Ubicación**: `/home/lucas/AutomaticProyects/automatic_process/rill-data/rill.yaml` + +```yaml +sources: + - name: postgres_main + type: sql + connector: postgres + settings: + host: postgres-main + port: 5432 + database: postgres + user: postgres + password: postgres + ssl_mode: disable + raw_sql: true + + - name: clickhouse_main + type: sql + connector: clickhouse + settings: + host: clickhouse + port: 9000 + database: default + user: default + password: clickhouse + ssl: false +``` + +--- + +## ✅ Verificación de Conectividad + +### Script de Verificación +```bash +/home/lucas/dagu/scripts/test_db_connections.sh +``` + +Verifica: +- ✓ PostgreSQL (localhost:5434) +- ✓ ClickHouse (localhost:8123) +- ✓ Grafana (localhost:3500) +- ✓ Metabase (localhost:3200) +- ✓ Rill (localhost:9009) + +### Verificación Manual + +#### Grafana +1. Login en http://localhost:3500 +2. Ir a **Connections** > **Data sources** +3. Verificar datasources "PostgreSQL" y "ClickHouse" +4. Hacer clic en cada uno y presionar **Test** (debe mostrar ✓) + +#### Metabase +1. Login en http://localhost:3200 +2. Ir a **Admin Settings** > **Databases** +3. Verificar "PostgreSQL Main" y "ClickHouse Analytics" +4. Estado debe mostrar "Connected" + +#### Rill +1. Abrir http://localhost:9009 +2. Ver pestaña **Sources** +3. Verificar `postgres_main` y `clickhouse_main` +4. Ejecutar query de prueba: `SELECT 1` + +--- + +## 📊 Bases de Datos Disponibles + +### PostgreSQL +- **Host interno**: `postgres-main:5432` +- **Host externo**: `localhost:5434` +- **Usuario**: `postgres` +- **Contraseña**: `postgres` +- **Base de datos**: `postgres` +- **Estado**: Vacía (sin tablas) + +### ClickHouse +- **Host interno**: `clickhouse:9000` (native), `clickhouse:8123` (HTTP) +- **Host externo**: `localhost:9000`, `localhost:8123` +- **Usuario**: `default` +- **Contraseña**: `clickhouse` +- **Base de datos**: `default` +- **Estado**: Vacía (sin tablas) + +--- + +## 🎯 Próximos Pasos + +### 1. Crear Tablas de Ejemplo (Opcional) + +#### PostgreSQL +```sql +-- Conectar vía psql +PGPASSWORD=postgres psql -h localhost -p 5434 -U postgres -d postgres + +-- Crear tabla de eventos +CREATE TABLE events ( + id SERIAL PRIMARY KEY, + timestamp TIMESTAMP DEFAULT NOW(), + event_type VARCHAR(100), + user_id INTEGER, + data JSONB +); + +-- Insertar datos de prueba +INSERT INTO events (event_type, user_id, data) +VALUES + ('login', 1, '{"ip": "192.168.1.1"}'), + ('purchase', 1, '{"product": "laptop", "amount": 1200}'), + ('logout', 1, '{"duration": 3600}'); +``` + +#### ClickHouse +```sql +-- Conectar vía clickhouse-client +clickhouse-client --host localhost --port 9000 --user default --password clickhouse + +-- Crear tabla de métricas +CREATE TABLE metrics ( + timestamp DateTime, + metric_name String, + metric_value Float64, + tags Map(String, String) +) ENGINE = MergeTree() +ORDER BY timestamp; + +-- Insertar datos de prueba +INSERT INTO metrics VALUES + (now(), 'cpu_usage', 45.2, {'host': 'server1'}), + (now(), 'memory_usage', 72.8, {'host': 'server1'}), + (now(), 'disk_usage', 58.3, {'host': 'server1'}); +``` + +### 2. Crear Dashboards de Ejemplo + +#### En Grafana +1. New Dashboard → Add visualization +2. Seleccionar datasource "PostgreSQL" +3. Query: `SELECT * FROM events ORDER BY timestamp DESC LIMIT 10` +4. Visualizar como tabla o gráfico + +#### En Metabase +1. New → Question +2. Seleccionar "PostgreSQL Main" +3. Simple Question → Pick Table → events +4. Guardar y añadir a dashboard + +#### En Rill +1. Crear modelo en `rill-data/rill.yaml`: +```yaml +models: + - name: recent_events + sql: | + SELECT * FROM events + ORDER BY timestamp DESC + LIMIT 100 + source: postgres_main +``` +2. Restart Rill: `docker-compose -f docker-compose-analytics.yml restart rill` + +### 3. Configurar Pipelines con Dagu + +Ver `TRANSFORMATIONS.md` para ejemplos de DAGs que: +- Extraigan datos de APIs +- Transformen datos +- Carguen a PostgreSQL/ClickHouse +- Generen visualizaciones automáticas + +--- + +## 🔧 Troubleshooting + +### Metabase no se configura +```bash +# Verificar logs +docker logs metabase + +# Resetear y reconfigurar +docker-compose -f docker-compose-analytics.yml down metabase metabase-db +docker volume rm automatic_process_metabase-data +docker-compose -f docker-compose-analytics.yml up -d metabase-db metabase +sleep 50 +/home/lucas/dagu/scripts/configure_metabase.py +``` + +### Grafana no ve las bases de datos +```bash +# Verificar que Grafana está en ambas redes +docker inspect grafana | grep -A 10 Networks + +# Debe mostrar: suite-logs_monitoring y automatic_process_default + +# Probar DNS desde Grafana +docker exec grafana nslookup postgres-main +docker exec grafana nslookup clickhouse +``` + +### Rill no carga sources +```bash +# Verificar configuración +cat /home/lucas/AutomaticProyects/automatic_process/rill-data/rill.yaml + +# Revisar logs +docker logs rill + +# Reiniciar +docker-compose -f docker-compose-analytics.yml restart rill +``` + +--- + +## 📚 Referencias + +- **Grafana Datasources**: http://localhost:3500/connections/datasources +- **Metabase Admin**: http://localhost:3200/admin/databases +- **Rill Dashboard**: http://localhost:9009 +- **DBGate** (DB Manager): http://localhost:3300 +- **Marquez** (Lineage): http://localhost:3001 +- **Homer** (Dashboard Hub): http://localhost:8080 + +--- + +**Última actualización**: 2026-03-23 +**Configuración**: Automática via scripts diff --git a/rill-data/rill.yaml b/rill-data/rill.yaml index 469f266..f5b8b2e 100755 --- a/rill-data/rill.yaml +++ b/rill-data/rill.yaml @@ -1,2 +1,25 @@ -sources: [] +sources: + - name: postgres_main + type: sql + connector: postgres + settings: + host: postgres-main + port: 5432 + database: postgres + user: postgres + password: postgres + ssl_mode: disable + raw_sql: true + + - name: clickhouse_main + type: sql + connector: clickhouse + settings: + host: clickhouse + port: 9000 + database: default + user: default + password: clickhouse + ssl: false + models: []