|
--- |
|
title: 'Monitoring & Logging' |
|
description: 'Monitor your MCP servers and analyze system logs with MCPHub' |
|
--- |
|
|
|
|
|
|
|
MCPHub provides comprehensive monitoring and logging capabilities to help you track server performance, debug issues, and maintain system health. |
|
|
|
|
|
|
|
|
|
|
|
The MCPHub dashboard provides real-time monitoring of all registered MCP servers: |
|
|
|
- **Server Health**: Online/offline status with automatic health checks |
|
- **Response Times**: Average, min, max response times per server |
|
- **Request Volume**: Requests per second/minute/hour |
|
- **Error Rates**: Success/failure ratios and error trends |
|
- **Resource Usage**: Memory and CPU utilization (when available) |
|
|
|
|
|
|
|
Configure health checks for your MCP servers: |
|
|
|
```json |
|
{ |
|
"healthCheck": { |
|
"enabled": true, |
|
"interval": 30000, |
|
"timeout": 5000, |
|
"retries": 3, |
|
"endpoints": { |
|
"ping": "/health", |
|
"tools": "/tools/list" |
|
} |
|
} |
|
} |
|
``` |
|
|
|
|
|
|
|
Get monitoring data programmatically: |
|
|
|
```bash |
|
|
|
curl http://localhost:3000/api/monitoring/health |
|
|
|
|
|
curl http://localhost:3000/api/monitoring/metrics?server=my-server&range=1h |
|
|
|
|
|
curl http://localhost:3000/api/monitoring/overview |
|
``` |
|
|
|
|
|
|
|
|
|
|
|
MCPHub supports standard log levels: |
|
|
|
- **ERROR**: Critical errors requiring immediate attention |
|
- **WARN**: Warning conditions that should be monitored |
|
- **INFO**: General operational messages |
|
- **DEBUG**: Detailed debugging information |
|
- **TRACE**: Very detailed trace information |
|
|
|
|
|
|
|
Configure logging in your environment: |
|
|
|
```bash |
|
|
|
LOG_LEVEL=info |
|
|
|
|
|
LOG_FORMAT=json |
|
|
|
|
|
LOG_FILE=/var/log/mcphub/app.log |
|
|
|
|
|
ENABLE_REQUEST_LOGS=true |
|
``` |
|
|
|
|
|
|
|
MCPHub uses structured logging for better analysis: |
|
|
|
```json |
|
{ |
|
"timestamp": "2024-01-20T10:30:00Z", |
|
"level": "info", |
|
"message": "MCP server request completed", |
|
"server": "github-mcp", |
|
"tool": "search_repositories", |
|
"duration": 245, |
|
"status": "success", |
|
"requestId": "req_123456", |
|
"userId": "user_789" |
|
} |
|
``` |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```yaml |
|
|
|
services: |
|
mcphub: |
|
volumes: |
|
- ./logs:/app/logs |
|
environment: |
|
- LOG_FILE=/app/logs/mcphub.log |
|
- LOG_ROTATION=daily |
|
- LOG_MAX_SIZE=100MB |
|
- LOG_MAX_FILES=7 |
|
``` |
|
|
|
|
|
|
|
```json |
|
{ |
|
"logging": { |
|
"database": { |
|
"enabled": true, |
|
"table": "logs", |
|
"retention": "30d", |
|
"indexes": ["timestamp", "level", "server"] |
|
} |
|
} |
|
} |
|
``` |
|
|
|
|
|
|
|
```bash |
|
|
|
SYSLOG_ENABLED=true |
|
SYSLOG_HOST=localhost |
|
SYSLOG_PORT=514 |
|
SYSLOG_FACILITY=local0 |
|
|
|
|
|
ELASTICSEARCH_URL=http://localhost:9200 |
|
ELASTICSEARCH_INDEX=mcphub-logs |
|
``` |
|
|
|
|
|
|
|
Automatic log rotation configuration: |
|
|
|
```json |
|
{ |
|
"logRotation": { |
|
"enabled": true, |
|
"maxSize": "100MB", |
|
"maxFiles": 10, |
|
"compress": true, |
|
"interval": "daily" |
|
} |
|
} |
|
``` |
|
|
|
|
|
|
|
|
|
|
|
MCPHub collects various system metrics: |
|
|
|
```javascript |
|
// Example metrics collected |
|
{ |
|
"timestamp": "2024-01-20T10:30:00Z", |
|
"metrics": { |
|
"requests": { |
|
"total": 1547, |
|
"success": 1523, |
|
"errors": 24, |
|
"rate": 12.5 |
|
}, |
|
"servers": { |
|
"online": 8, |
|
"offline": 2, |
|
"total": 10 |
|
}, |
|
"performance": { |
|
"avgResponseTime": 156, |
|
"p95ResponseTime": 324, |
|
"p99ResponseTime": 567 |
|
}, |
|
"system": { |
|
"memoryUsage": "245MB", |
|
"cpuUsage": "15%", |
|
"uptime": "72h 35m" |
|
} |
|
} |
|
} |
|
``` |
|
|
|
|
|
|
|
Add custom metrics for your use case: |
|
|
|
```javascript |
|
// Custom metric example |
|
const customMetric = { |
|
name: 'tool_usage', |
|
type: 'counter', |
|
tags: { |
|
server: 'github-mcp', |
|
tool: 'search_repositories', |
|
result: 'success', |
|
}, |
|
value: 1, |
|
}; |
|
|
|
// Send to metrics endpoint |
|
await fetch('/api/monitoring/metrics', { |
|
method: 'POST', |
|
headers: { 'Content-Type': 'application/json' }, |
|
body: JSON.stringify(customMetric), |
|
}); |
|
``` |
|
|
|
|
|
|
|
|
|
|
|
Set up alerts for critical conditions: |
|
|
|
```json |
|
{ |
|
"alerts": { |
|
"serverDown": { |
|
"condition": "server.status == 'offline'", |
|
"duration": "5m", |
|
"severity": "critical", |
|
"channels": ["email", "slack"] |
|
}, |
|
"highErrorRate": { |
|
"condition": "errors.rate > 0.1", |
|
"duration": "2m", |
|
"severity": "warning", |
|
"channels": ["slack"] |
|
}, |
|
"slowResponse": { |
|
"condition": "response.p95 > 1000", |
|
"duration": "5m", |
|
"severity": "warning", |
|
"channels": ["email"] |
|
} |
|
} |
|
} |
|
``` |
|
|
|
|
|
|
|
|
|
|
|
```bash |
|
|
|
SMTP_HOST=smtp.gmail.com |
|
SMTP_PORT=587 |
|
SMTP_USER=alerts@yourcompany.com |
|
SMTP_PASS=your-app-password |
|
ALERT_EMAIL_TO=admin@yourcompany.com |
|
``` |
|
|
|
|
|
|
|
```bash |
|
|
|
SLACK_WEBHOOK_URL=https://hooks.slack.com/services/... |
|
SLACK_CHANNEL=#mcphub-alerts |
|
``` |
|
|
|
|
|
|
|
```json |
|
{ |
|
"webhooks": [ |
|
{ |
|
"url": "https://your-service.com/webhooks/mcphub", |
|
"events": ["server.down", "error.rate.high"], |
|
"headers": { |
|
"Authorization": "Bearer your-token" |
|
} |
|
} |
|
] |
|
} |
|
``` |
|
|
|
|
|
|
|
|
|
|
|
Use the logs API to query and analyze logs: |
|
|
|
```bash |
|
|
|
curl "http://localhost:3000/api/logs?level=error&since=1h" |
|
|
|
|
|
curl "http://localhost:3000/api/logs?server=github-mcp&limit=100" |
|
|
|
|
|
curl "http://localhost:3000/api/logs?requestId=req_123456" |
|
|
|
|
|
curl "http://localhost:3000/api/logs?from=2024-01-20T00:00:00Z&to=2024-01-20T23:59:59Z" |
|
``` |
|
|
|
|
|
|
|
Aggregate logs for insights: |
|
|
|
```bash |
|
|
|
curl "http://localhost:3000/api/logs/aggregate?groupBy=server&level=error&since=24h" |
|
|
|
|
|
curl "http://localhost:3000/api/logs/aggregate?groupBy=hour&type=request&since=7d" |
|
``` |
|
|
|
|
|
|
|
|
|
|
|
Monitor MCP server response times: |
|
|
|
```javascript |
|
// Response time metrics |
|
{ |
|
"server": "github-mcp", |
|
"tool": "search_repositories", |
|
"metrics": { |
|
"calls": 156, |
|
"avgTime": 234, |
|
"minTime": 89, |
|
"maxTime": 1205, |
|
"p50": 201, |
|
"p95": 567, |
|
"p99": 892 |
|
} |
|
} |
|
``` |
|
|
|
|
|
|
|
Track error rates and patterns: |
|
|
|
```bash |
|
|
|
curl "http://localhost:3000/api/monitoring/errors?groupBy=server&since=1h" |
|
|
|
|
|
curl "http://localhost:3000/api/monitoring/errors?server=github-mcp&details=true" |
|
``` |
|
|
|
|
|
|
|
|
|
|
|
Export metrics to Prometheus: |
|
|
|
```yaml |
|
|
|
scrape_configs: |
|
- job_name: 'mcphub' |
|
static_configs: |
|
- targets: ['localhost:3000'] |
|
metrics_path: '/api/monitoring/prometheus' |
|
scrape_interval: 30s |
|
``` |
|
|
|
|
|
|
|
Import MCPHub Grafana dashboard: |
|
|
|
```json |
|
{ |
|
"dashboard": { |
|
"title": "MCPHub Monitoring", |
|
"panels": [ |
|
{ |
|
"title": "Server Status", |
|
"type": "stat", |
|
"targets": [ |
|
{ |
|
"expr": "mcphub_servers_online", |
|
"legendFormat": "Online" |
|
} |
|
] |
|
}, |
|
{ |
|
"title": "Request Rate", |
|
"type": "graph", |
|
"targets": [ |
|
{ |
|
"expr": "rate(mcphub_requests_total[5m])", |
|
"legendFormat": "Requests/sec" |
|
} |
|
] |
|
} |
|
] |
|
} |
|
} |
|
``` |
|
|
|
|
|
|
|
Configure Logstash for log processing: |
|
|
|
```ruby |
|
|
|
input { |
|
beats { |
|
port => 5044 |
|
} |
|
} |
|
|
|
filter { |
|
if [fields][service] == "mcphub" { |
|
json { |
|
source => "message" |
|
} |
|
|
|
date { |
|
match => [ "timestamp", "ISO8601" ] |
|
} |
|
} |
|
} |
|
|
|
output { |
|
elasticsearch { |
|
hosts => ["localhost:9200"] |
|
index => "mcphub-logs-%{+YYYY.MM.dd}" |
|
} |
|
} |
|
``` |
|
|
|
|
|
|
|
|
|
|
|
**Missing Metrics** |
|
|
|
```bash |
|
|
|
curl http://localhost:3000/api/monitoring/health |
|
|
|
|
|
grep -r "monitoring" /path/to/config/ |
|
``` |
|
|
|
**Log File Issues** |
|
|
|
```bash |
|
|
|
ls -la /var/log/mcphub/ |
|
|
|
|
|
df -h /var/log/ |
|
|
|
|
|
logrotate -d /etc/logrotate.d/mcphub |
|
``` |
|
|
|
**Performance Issues** |
|
|
|
```bash |
|
|
|
top -p $(pgrep -f mcphub) |
|
|
|
|
|
curl http://localhost:3000/api/monitoring/database |
|
|
|
|
|
curl http://localhost:3000/api/monitoring/slow-queries |
|
``` |
|
|
|
|
|
|
|
Enable debug logging for troubleshooting: |
|
|
|
```bash |
|
|
|
DEBUG=mcphub:* npm start |
|
|
|
|
|
export DEBUG=mcphub:monitoring,mcphub:logging |
|
``` |
|
|
|
|
|
|
|
|
|
|
|
- Use structured logging with consistent formats |
|
- Implement proper log levels and filtering |
|
- Set up log rotation and retention policies |
|
- Monitor log file sizes and disk usage |
|
|
|
|
|
|
|
- Configure appropriate health check intervals |
|
- Set up alerts for critical conditions |
|
- Monitor both system and application metrics |
|
- Use dashboards for visual monitoring |
|
|
|
|
|
|
|
- Index log database tables appropriately |
|
- Use log sampling for high-volume scenarios |
|
- Implement proper caching for metrics |
|
- Regular cleanup of old logs and metrics |
|
|
|
|
|
|
|
- Sanitize sensitive data in logs |
|
- Secure access to monitoring endpoints |
|
- Use authentication for external integrations |
|
- Encrypt log transmission when using external services |
|
|