# SQL Monitoring Dashboard

This component provides a comprehensive single-page dashboard for monitoring SQL query performance, loop detection, and system health in the Managing application.

## Features

### Overview Cards
- **Total Tracked Queries**: Shows the total number of queries tracked by the monitoring system
- **Active Queries**: Displays currently monitored queries
- **Total Alerts**: Shows the number of alerts generated by the system
- **Monitoring Status**: Indicates whether SQL monitoring is active or inactive

### System Health Section
- **Monitoring Status**: Overall health of the SQL monitoring system
- **Feature Status**: Individual status of monitoring features (logging, Sentry, loop detection, etc.)
- **Compact Layout**: All health indicators displayed in a responsive grid

### Recent Alerts Section
- **SQL Monitoring Alerts**: Real-time alerts for SQL performance issues
- **Severity Levels**: Critical, Warning, and Info alerts with color-coded badges
- **Repository and Method**: Shows which repository and method triggered the alert
- **Timestamp**: When the alert was generated

### Query Statistics Section
- **Query Statistics**: Detailed statistics about query execution patterns
- **Loop Detection Stats**: Information about detected query loops
- **Context Stats**: Additional context information about the monitoring system

### Information Panel
- **Usage Instructions**: Explains how the dashboard works
- **Auto-refresh Info**: Details about automatic data updates
- **Clear Data Instructions**: How to reset monitoring statistics

## API Integration

The component integrates with the following SQL monitoring endpoints:

- `GET /api/sqlmonitoring/statistics` - Get query statistics
- `GET /api/sqlmonitoring/alerts` - Get monitoring alerts
- `GET /api/sqlmonitoring/health` - Get monitoring health status
- `POST /api/sqlmonitoring/clear` - Clear tracking data
- `GET /api/sqlmonitoring/details/{repositoryName}/{methodName}` - Get query details

## Auto-refresh

- **Statistics**: Refreshes every 30 seconds
- **Alerts**: Refreshes every 15 seconds
- **Health**: Refreshes every minute

## Admin Authorization

All SQL monitoring endpoints require admin authorization. Only users with admin privileges can access this dashboard.

## Mobile-Friendly Design

The dashboard is designed to be fully responsive and mobile-friendly:

- **Responsive Grid**: Overview cards adapt from 1 column on mobile to 4 columns on desktop
- **Compact Layout**: Health status indicators are arranged in a responsive grid
- **Horizontal Scrolling**: Tables have horizontal scroll on smaller screens
- **Touch-Friendly**: All interactive elements are appropriately sized for touch devices
- **Readable Text**: Font sizes and spacing optimized for mobile viewing

## Usage

1. Navigate to Settings → SQL Monitoring
2. View all monitoring information on a single page
3. Use the "Clear Tracking Data" button to reset monitoring statistics
4. Monitor alerts and statistics in real-time
5. Check system health status at a glance

## Configuration

The SQL monitoring system can be configured via `appsettings.json`:

```json
{
  "SqlMonitoring": {
    "Enabled": true,
    "LoggingEnabled": true,
    "SentryEnabled": true,
    "LoopDetectionEnabled": true,
    "PerformanceMonitoringEnabled": true,
    "LoopDetectionWindowSeconds": 60,
    "MaxQueryExecutionsPerWindow": 100,
    "MaxMethodExecutionsPerWindow": 50,
    "LongRunningQueryThresholdMs": 1000,
    "SentryAlertThreshold": 5,
    "SlowQueryThresholdMs": 2000,
    "LogSlowQueriesOnly": false,
    "LogErrorsOnly": false
  }
}
```
