# SigNoz Dashboards for Bakery IA

This directory contains comprehensive SigNoz dashboard configurations for monitoring the Bakery IA system.

## Available Dashboards

### 1. Infrastructure Monitoring
- **File**: `infrastructure-monitoring.json`
- **Purpose**: Monitor Kubernetes infrastructure, pod health, and resource utilization
- **Key Metrics**: CPU usage, memory usage, network traffic, pod status, container health

### 2. Application Performance
- **File**: `application-performance.json`
- **Purpose**: Monitor microservice performance and API metrics
- **Key Metrics**: Request rate, error rate, latency percentiles, endpoint performance

### 3. Database Performance
- **File**: `database-performance.json`
- **Purpose**: Monitor PostgreSQL and Redis database performance
- **Key Metrics**: Connections, query execution time, cache hit ratio, locks, replication status

### 4. API Performance
- **File**: `api-performance.json`
- **Purpose**: Monitor REST and GraphQL API performance
- **Key Metrics**: Request volume, response times, status codes, endpoint analysis

### 5. Error Tracking
- **File**: `error-tracking.json`
- **Purpose**: Track and analyze system errors
- **Key Metrics**: Error rates, error distribution, recent errors, HTTP errors, database errors

### 6. User Activity
- **File**: `user-activity.json`
- **Purpose**: Monitor user behavior and activity patterns
- **Key Metrics**: Active users, sessions, API calls per user, session duration

### 7. System Health
- **File**: `system-health.json`
- **Purpose**: Overall system health monitoring
- **Key Metrics**: Availability, health scores, resource utilization, service status

### 8. Alert Management
- **File**: `alert-management.json`
- **Purpose**: Monitor and manage system alerts
- **Key Metrics**: Active alerts, alert rates, alert distribution, firing alerts

### 9. Log Analysis
- **File**: `log-analysis.json`
- **Purpose**: Search and analyze system logs
- **Key Metrics**: Log volume, error logs, log distribution, log search

## How to Import Dashboards

### Method 1: Using SigNoz UI

1. **Access SigNoz UI**: Open your SigNoz instance in a web browser
2. **Navigate to Dashboards**: Go to the "Dashboards" section
3. **Import Dashboard**: Click on "Import Dashboard" button
4. **Upload JSON**: Select the JSON file from this directory
5. **Configure**: Adjust any variables or settings as needed
6. **Save**: Save the imported dashboard

**Note**: The dashboards now use the correct SigNoz JSON schema with proper filter arrays.

### Method 2: Using SigNoz API

```bash
# Import a single dashboard
curl -X POST "http://<SIGNOZ_HOST>:3301/api/v1/dashboards/import" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer <API_KEY>" \
  -d @infrastructure-monitoring.json

# Import all dashboards
for file in *.json; do
  curl -X POST "http://<SIGNOZ_HOST>:3301/api/v1/dashboards/import" \
    -H "Content-Type: application/json" \
    -H "Authorization: Bearer <API_KEY>" \
    -d @"$file"
done
```

### Method 3: Using Kubernetes ConfigMap

```yaml
# Create a ConfigMap with all dashboards
kubectl create configmap signoz-dashboards \
  --from-file=infrastructure-monitoring.json \
  --from-file=application-performance.json \
  --from-file=database-performance.json \
  --from-file=api-performance.json \
  --from-file=error-tracking.json \
  --from-file=user-activity.json \
  --from-file=system-health.json \
  --from-file=alert-management.json \
  --from-file=log-analysis.json \
  -n signoz
```

## Dashboard Variables

Most dashboards include variables that allow you to filter and customize the view:

- **Namespace**: Filter by Kubernetes namespace (e.g., `bakery-ia`, `default`)
- **Service**: Filter by specific microservice
- **Severity**: Filter by error/alert severity
- **Environment**: Filter by deployment environment
- **Time Range**: Adjust the time window for analysis

## Metrics Reference

The dashboards use standard OpenTelemetry metrics. If you need to add custom metrics, ensure they are properly instrumented in your services.

## Troubleshooting

### Dashboard Import Errors

If you encounter errors when importing dashboards:

1. **Validate JSON**: Ensure the JSON files are valid
   ```bash
   jq . infrastructure-monitoring.json
   ```

2. **Check Metrics**: Verify that the metrics exist in your SigNoz instance

3. **Adjust Time Range**: Try different time ranges if no data appears

4. **Check Filters**: Ensure filters match your actual service names and tags

### "e.filter is not a function" Error

This error occurs when the dashboard JSON uses an incorrect filter format. The fix has been applied:

**Before (incorrect)**:
```json
"filters": {
  "namespace": "${namespace}"
}
```

**After (correct)**:
```json
"filters": [
  {
    "key": "namespace",
    "operator": "=",
    "value": "${namespace}"
  }
]
```

All dashboards in this directory now use the correct array format for filters.

### Missing Data

If dashboards show no data:

1. **Verify Instrumentation**: Ensure your services are properly instrumented with OpenTelemetry
2. **Check Time Range**: Adjust the time range to include recent data
3. **Validate Metrics**: Confirm the metrics are being collected and stored
4. **Review Filters**: Check that filters match your actual deployment

## Customization

You can customize these dashboards by:

1. **Editing JSON**: Modify the JSON files to add/remove panels or adjust queries
2. **Cloning in UI**: Clone existing dashboards and modify them in the SigNoz UI
3. **Adding Variables**: Add new variables for additional filtering options
4. **Adjusting Layout**: Change the grid layout and panel sizes

## Best Practices

1. **Regular Reviews**: Review dashboards regularly to ensure they meet your monitoring needs
2. **Alert Integration**: Set up alerts based on key metrics shown in these dashboards
3. **Team Access**: Share relevant dashboards with appropriate team members
4. **Documentation**: Document any custom metrics or specific monitoring requirements

## Support

For issues with these dashboards:

1. Check the [SigNoz documentation](https://signoz.io/docs/)
2. Review the [Bakery IA monitoring guide](../SIGNOZ_COMPLETE_CONFIGURATION_GUIDE.md)
3. Consult the OpenTelemetry metrics specification

## License

These dashboard configurations are provided under the same license as the Bakery IA project.