← back to Designer Wallcoverings
DW-Agents/dw-agents/agent-log-monitor/README.md
113 lines
# Log Monitor Agent
## Purpose
Automated log analysis and error detection system that continuously monitors all DW-Agents server logs, identifies issues, and automatically creates tasks for resolution.
## Core Responsibilities
- Continuous monitoring of all PM2 process logs
- Error pattern detection and classification
- Automatic issue identification (crashes, errors, warnings)
- Task creation and assignment to appropriate agents
- Alert escalation for critical issues
- Log analytics and trending
- Self-healing recommendations
## Technical Details
- **Port**: 7239
- **Main File**: log-monitor-agent.ts
- **Interface**: Real-time log dashboard with filtering
- **Scan Interval**: Every 30 seconds
- **Auto-Recovery**: PM2 managed with auto-restart on crash
## Monitored Logs
- All PM2 agent logs in `/root/DW-Agents/logs/`
- System logs for critical issues
- Application error logs
- PM2 process status
## Key Features
- **Real-time Log Tailing**: Watch all logs in real-time
- **Error Detection**: Automatic identification of errors, crashes, warnings
- **Pattern Recognition**: Learns common error patterns
- **Intelligent Task Assignment**: Routes issues to appropriate agents
- **Severity Classification**: Critical, High, Medium, Low
- **Alert Escalation**: Sends critical issues to needs-attention agent
- **Log Search**: Full-text search across all logs
- **Analytics Dashboard**: Error trends and statistics
## Error Detection Patterns
- Application crashes (PM2 restarts)
- Unhandled exceptions
- Database connection errors
- API failures (4xx, 5xx)
- Memory leaks (high memory usage)
- Port conflicts
- Authentication failures
- Network timeouts
- Missing dependencies
## Automatic Actions
When issues are detected:
1. **Classify severity** (Critical, High, Medium, Low)
2. **Create task** in task-orchestrator
3. **Assign to appropriate agent**:
- Server crashes → server-uptime agent
- Shopify errors → shopify-store agent
- Customer issues → zendesk-chat or needs-attention
- Payment/accounting → accounting agent
4. **Alert** if critical via needs-attention agent
5. **Log** the action taken
6. **Track** resolution time
## Web Dashboard (Port 7239)
- **Live Log Feed**: Real-time log streaming
- **Error Summary**: Count of errors by agent
- **Task Queue**: Auto-created tasks pending resolution
- **Analytics**: Error trends over time
- **Search**: Find specific log entries
- **Filters**: By agent, severity, time range
## Integration Points
- **task-orchestrator**: Creates and assigns tasks
- **needs-attention**: Escalates critical issues
- **server-uptime**: Coordinates on server health
- **All agents**: Monitors their log output
## Alert Thresholds
- **Critical**: Immediate alert + task creation
- Agent crash/restart
- Database connection loss
- Payment processing failure
- **High**: Task creation within 5 minutes
- Multiple API failures
- High error rate (>10/min)
- Memory usage >80%
- **Medium**: Task creation within 1 hour
- Sporadic API errors
- Slow response times
- Warnings
- **Low**: Logged for review
- Info messages
- Debug output
## Memory Learning
The agent learns:
- Common error patterns and solutions
- False positive patterns to ignore
- Resolution effectiveness
- Agent-specific error signatures
- Peak error times
## PM2 Configuration
- Auto-restart on crash
- Max memory: 300MB
- Log monitoring interval: 30s
- Error aggregation: 5 minutes
## API Endpoints
- `GET /api/logs` - Recent log entries
- `GET /api/errors` - Error summary
- `GET /api/tasks` - Auto-created tasks
- `POST /api/search` - Search logs
- `GET /api/analytics` - Error trends