|
| 1 | +# Elasticsearch Integration & Grafana Dashboards - Complete Setup |
| 2 | + |
| 3 | +## 🎉 INTEGRATION COMPLETE |
| 4 | + |
| 5 | +Successfully integrated logs into Elasticsearch and created advanced Grafana dashboards! |
| 6 | + |
| 7 | +## 📊 Summary |
| 8 | + |
| 9 | +### Logs Ingested to Elasticsearch |
| 10 | +- **Total Entries**: 118,751 log entries |
| 11 | +- **Source Files**: 272 log files |
| 12 | +- **Date Range**: Last 7 days |
| 13 | +- **Index Name**: `spine-logs` |
| 14 | + |
| 15 | +### Top Log Sources |
| 16 | +1. **992 entries** - capture-spine/logs/api_2025-12-28_211038.log |
| 17 | +2. **990 entries** - capture-spine/logs/api_2025-12-30_144825.log |
| 18 | +3. **907 entries** - capture-spine/logs/api-2026-01-03.log |
| 19 | +4. **905 entries** - capture-spine/logs/api_2025-12-29_155322.log |
| 20 | +5. **882 entries** - capture-spine/logs/frontend-2026-01-04.log |
| 21 | + |
| 22 | +## 🔗 Access URLs |
| 23 | + |
| 24 | +### Grafana - Advanced Dashboards |
| 25 | +- **URL**: http://localhost:3100 |
| 26 | +- **Username**: `admin` |
| 27 | +- **Password**: `admin` |
| 28 | +- **Dashboards Available**: |
| 29 | + - "Spine Ecosystem - Log Dashboard" (basic Loki dashboard) |
| 30 | + - "Spine Ecosystem - Advanced Log Analytics" (NEW - 9 panels with sophisticated visualizations) |
| 31 | + |
| 32 | +### Uptime Kuma - Service Monitoring |
| 33 | +- **URL**: http://localhost:3001 |
| 34 | +- **First Time Setup**: Create admin account on first launch |
| 35 | +- **Status**: Running and healthy |
| 36 | + |
| 37 | +### Kibana - Elasticsearch UI |
| 38 | +- **URL**: http://localhost:5601 |
| 39 | +- **Status**: Available for Elasticsearch log exploration |
| 40 | +- **Index Pattern**: Create `spine-logs*` pattern in Kibana > Stack Management > Index Patterns |
| 41 | + |
| 42 | +### Dozzle - Docker Logs |
| 43 | +- **URL**: http://localhost:9999 |
| 44 | +- **Purpose**: Real-time Docker container log viewing |
| 45 | + |
| 46 | +## 📈 Grafana Dashboard Features |
| 47 | + |
| 48 | +The new "Spine Ecosystem - Advanced Log Analytics" dashboard includes: |
| 49 | + |
| 50 | +### 1. Key Metrics (Top Row) |
| 51 | +- **🔴 Total Errors (24h)**: Shows total error count with color thresholds |
| 52 | +- **⚠️ Total Warnings (24h)**: Warning count across all services |
| 53 | + |
| 54 | +### 2. Time Series Visualizations |
| 55 | +- **📊 Log Volume by Service**: Track log activity per service |
| 56 | +- **🔥 Error Rate by Service**: Stacked bar chart showing errors over time |
| 57 | +- **📉 Log Level Trends**: Compare ERROR, WARNING, INFO trends |
| 58 | + |
| 59 | +### 3. Distribution Charts |
| 60 | +- **📈 Log Level Distribution**: Donut chart showing breakdown by severity |
| 61 | +- **📊 Errors by Service**: Horizontal bar chart of total errors per service |
| 62 | + |
| 63 | +### 4. Analysis Tables |
| 64 | +- **🔝 Top Error Messages**: Table of most frequent errors |
| 65 | + |
| 66 | +### 5. Live Monitoring |
| 67 | +- **🔴 Live Error & Warning Stream**: Real-time log tail showing errors and warnings |
| 68 | + |
| 69 | +## 🛠️ How to Use |
| 70 | + |
| 71 | +### Elasticsearch Log Queries (Kibana) |
| 72 | +1. Open http://localhost:5601 |
| 73 | +2. Go to "Discover" |
| 74 | +3. Create index pattern: `spine-logs*` |
| 75 | +4. Search examples: |
| 76 | + - Find errors: `level:ERROR` |
| 77 | + - Search message content: `message:"connection refused"` |
| 78 | + - Filter by service: `service:capture-spine` |
| 79 | + - Time range: Use time picker in top-right |
| 80 | + |
| 81 | +### Grafana Dashboard Navigation |
| 82 | +1. Open http://localhost:3100 |
| 83 | +2. Login with admin/admin |
| 84 | +3. Go to "Dashboards" (left sidebar, grid icon) |
| 85 | +4. Select "Spine Ecosystem - Advanced Log Analytics" |
| 86 | +5. Use time range selector (top-right) to change window |
| 87 | +6. Click on any graph to drill down |
| 88 | +7. Use "Refresh" dropdown to enable auto-refresh (10s, 30s, 1m, etc.) |
| 89 | + |
| 90 | +### Uptime Kuma Setup |
| 91 | +1. Open http://localhost:3001 |
| 92 | +2. Create admin account (first-time setup wizard) |
| 93 | +3. Add monitors: |
| 94 | + - **HTTP Monitor**: http://localhost:8000/health (spine-dev-api) |
| 95 | + - **HTTP Monitor**: http://localhost:8001/health (spine-api-qa) |
| 96 | + - **HTTP Monitor**: http://localhost:9200 (Elasticsearch) |
| 97 | + - **Docker Container**: Monitor spine containers |
| 98 | + |
| 99 | +## 🔄 Continuous Log Ingestion |
| 100 | + |
| 101 | +To keep Elasticsearch updated with new logs, run periodically: |
| 102 | + |
| 103 | +```powershell |
| 104 | +# Ship logs from last 24 hours |
| 105 | +B:/github/py-sec-edgar/.venv/Scripts/python.exe scripts/send_logs_to_elasticsearch.py --days 1 |
| 106 | +
|
| 107 | +# Ship all capture-spine logs |
| 108 | +B:/github/py-sec-edgar/.venv/Scripts/python.exe scripts/send_logs_to_elasticsearch.py --pattern "capture-spine/logs/**/*.log" |
| 109 | +
|
| 110 | +# Ship everything without date filter |
| 111 | +B:/github/py-sec-edgar/.venv/Scripts/python.exe scripts/send_logs_to_elasticsearch.py --all |
| 112 | +``` |
| 113 | + |
| 114 | +### Automated Ingestion (Optional) |
| 115 | +Create a Windows Task Scheduler job to run the script hourly: |
| 116 | +```powershell |
| 117 | +# Schedule task to run every hour |
| 118 | +$action = New-ScheduledTaskAction -Execute 'B:/github/py-sec-edgar/.venv/Scripts/python.exe' ` |
| 119 | + -Argument 'scripts/send_logs_to_elasticsearch.py --days 1' ` |
| 120 | + -WorkingDirectory 'B:\github\py-sec-edgar' |
| 121 | +
|
| 122 | +$trigger = New-ScheduledTaskTrigger -Once -At (Get-Date) -RepetitionInterval (New-TimeSpan -Hours 1) |
| 123 | +
|
| 124 | +Register-ScheduledTask -TaskName "Spine Log Ingestion" -Action $action -Trigger $trigger -Description "Ingest spine logs to Elasticsearch" |
| 125 | +``` |
| 126 | + |
| 127 | +## 📁 Files Created |
| 128 | + |
| 129 | +### Python Scripts |
| 130 | +- **scripts/send_logs_to_elasticsearch.py**: Log ingestion tool |
| 131 | + - Parses Python log formats |
| 132 | + - Handles bulk indexing |
| 133 | + - Creates index templates |
| 134 | + - Supports date filtering |
| 135 | + |
| 136 | +### Grafana Configurations |
| 137 | +- **monitoring/grafana/provisioning/datasources/elasticsearch.yml**: Elasticsearch data source |
| 138 | + - Auto-configured for Grafana |
| 139 | + - Points to Elasticsearch container |
| 140 | + - Index pattern: `spine-logs*` |
| 141 | + |
| 142 | +- **monitoring/grafana/provisioning/dashboards/spine-advanced-logs.json**: Advanced dashboard |
| 143 | + - 9 sophisticated panels |
| 144 | + - Live refresh capability |
| 145 | + - Color-coded severity levels |
| 146 | + - Interactive drill-down |
| 147 | + |
| 148 | +### Docker Compose Updates |
| 149 | +- **monitoring/docker-compose.monitoring.yml**: |
| 150 | + - Added external network connection to `capture-spine_search-net` |
| 151 | + - Grafana now has access to Elasticsearch container |
| 152 | + |
| 153 | +## 🔍 Query Examples |
| 154 | + |
| 155 | +### Loki Queries (in Grafana) |
| 156 | +```logql |
| 157 | +# All errors |
| 158 | +{job=~".+"} |~ "(?i)(error|exception|fatal)" |
| 159 | +
|
| 160 | +# Errors from specific service |
| 161 | +{job="spine-main"} |~ "ERROR" |
| 162 | +
|
| 163 | +# Warning count over time |
| 164 | +sum by (job) (count_over_time({job=~".+"} |~ "(?i)warning" [5m])) |
| 165 | +
|
| 166 | +# Top error messages |
| 167 | +topk(10, sum by (msg) (count_over_time({job=~".+"} |~ "ERROR" | pattern `<_> - ERROR - <_> - <msg>` [1h]))) |
| 168 | +``` |
| 169 | + |
| 170 | +### Elasticsearch Queries (in Kibana) |
| 171 | +```json |
| 172 | +# Find connection errors |
| 173 | +{ |
| 174 | + "query": { |
| 175 | + "bool": { |
| 176 | + "must": [ |
| 177 | + { "match": { "level": "ERROR" }}, |
| 178 | + { "match": { "message": "connection" }} |
| 179 | + ] |
| 180 | + } |
| 181 | + } |
| 182 | +} |
| 183 | + |
| 184 | +# Errors in last hour from capture-spine |
| 185 | +{ |
| 186 | + "query": { |
| 187 | + "bool": { |
| 188 | + "must": [ |
| 189 | + { "match": { "service": "capture-spine" }}, |
| 190 | + { "match": { "level": "ERROR" }}, |
| 191 | + { "range": { "@timestamp": { "gte": "now-1h" }}} |
| 192 | + ] |
| 193 | + } |
| 194 | + } |
| 195 | +} |
| 196 | +``` |
| 197 | + |
| 198 | +## 🎯 Next Steps |
| 199 | + |
| 200 | +1. **Explore Dashboards**: Open Grafana and explore the pre-built dashboards |
| 201 | +2. **Set Up Alerts**: Configure Grafana alerts for error thresholds |
| 202 | +3. **Add Monitors**: Set up Uptime Kuma monitors for all services |
| 203 | +4. **Create Kibana Visualizations**: Build custom Elasticsearch dashboards |
| 204 | +5. **Schedule Log Ingestion**: Automate periodic log shipping to ES |
| 205 | + |
| 206 | +## 🐛 Troubleshooting |
| 207 | + |
| 208 | +### Grafana Not Loading |
| 209 | +```powershell |
| 210 | +# Check Grafana status |
| 211 | +docker logs spine-grafana --tail 50 |
| 212 | +
|
| 213 | +# Restart Grafana |
| 214 | +docker restart spine-grafana |
| 215 | +
|
| 216 | +# Verify port mapping |
| 217 | +docker port spine-grafana |
| 218 | +``` |
| 219 | + |
| 220 | +### Elasticsearch Connection Issues |
| 221 | +```powershell |
| 222 | +# Check Elasticsearch health |
| 223 | +docker exec spine-elasticsearch curl http://localhost:9200/_cluster/health |
| 224 | +
|
| 225 | +# View Elasticsearch logs |
| 226 | +docker logs spine-elasticsearch --tail 50 |
| 227 | +``` |
| 228 | + |
| 229 | +### Missing Logs in Elasticsearch |
| 230 | +```powershell |
| 231 | +# Check index exists |
| 232 | +docker exec spine-elasticsearch curl http://localhost:9200/_cat/indices?v |
| 233 | +
|
| 234 | +# Verify document count |
| 235 | +docker exec spine-elasticsearch curl http://localhost:9200/spine-logs/_count |
| 236 | +``` |
| 237 | + |
| 238 | +## 📚 Resources |
| 239 | + |
| 240 | +- **Grafana Documentation**: https://grafana.com/docs/grafana/latest/ |
| 241 | +- **Loki Query Language**: https://grafana.com/docs/loki/latest/logql/ |
| 242 | +- **Elasticsearch Query DSL**: https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl.html |
| 243 | +- **Uptime Kuma**: https://github.com/louislam/uptime-kuma |
| 244 | + |
| 245 | +--- |
| 246 | + |
| 247 | +**Status**: ✅ All monitoring services running and integrated |
| 248 | +**Last Updated**: 2026-01-31 |
| 249 | +**Log Entries in ES**: 118,751 entries across 272 files |
0 commit comments