3

Phase 3: Health Monitoring

Comprehensive database health monitoring system with real-time metrics, intelligent alerts, and performance optimization suggestions to keep your database running at peak performance.

Overview

Database Monitoring

Monitor your database health with connection status tracking and performance metrics collection.

  • Connection status monitoring
  • Response time measurement
  • Query performance logging
  • Database size tracking

Performance Analytics

Track database performance with 24-hour query statistics and health metrics storage.

  • Query execution time tracking
  • Slow query detection
  • Failed query monitoring
  • Historical metrics storage

What Database Health Monitoring Provides:

Connection Status

Test and monitor database connectivity

Response Time

Measure database response times

Query Analytics

Track query performance and errors

Metrics Storage

Store historical performance data

Health Dashboard

Available Health Widgets

Health Metrics Widget

Displays key health statistics with color-coded indicators

  • • Connection status and response time
  • • 24-hour query count
  • • Average response time
  • • Slow and failed query counts
  • • Database size information

Performance Chart

24-hour query performance visualization

  • • Hourly average response times
  • • Query count trends
  • • Dual-axis chart display
  • • Interactive Chart.js visualization

Database Health Widget

Comprehensive health overview with real-time data

  • • Multi-connection status display
  • • Performance metrics breakdown
  • • Database-specific metrics (MySQL, PostgreSQL, SQLite)
  • • Active connections count

Dashboard Actions

Refresh Metrics

Manually refresh health summary and performance data

Test All Connections

Test connectivity to all configured database connections

Database Status

HEALTHY

All systems operational

Active Connections

47

of 100 max connections

Query Performance

2.3ms

average response time

CPU Usage

35% - Normal

Memory Usage

62% - Optimal

Monitoring Categories

System Resources

  • CPU utilization
  • Memory usage
  • Disk I/O
  • Network traffic

Connections

  • Active connections
  • Connection pool usage
  • Failed connections
  • Connection duration

Query Performance

  • Query execution time
  • Slow query detection
  • Query frequency
  • Index usage

Storage

  • Disk space usage
  • Table sizes
  • Index sizes
  • Growth trends

Real-time Features

Auto-refresh

Metrics update every 30 seconds automatically

Live Updates

WebSocket-powered real-time data streaming

Mobile Responsive

Monitor from any device, anywhere

Performance Metrics

Collected Metrics

Connection Status

Tests database connectivity and measures response times for all configured connections

Query Performance

Tracks execution times, query types, and identifies slow queries over 1000ms

Database Size

Monitors database size in MB for MySQL, PostgreSQL, and SQLite databases

Active Connections

Counts active database connections for MySQL and PostgreSQL systems

Error Tracking

Logs failed queries and connection errors with detailed error messages

Historical Data

Stores metrics with timestamps for 24-hour trend analysis and reporting

Database-Specific Metrics

MySQL Metrics

  • • Database size calculation from information_schema
  • • Active connections via SHOW STATUS
  • • Table and index size monitoring

PostgreSQL Metrics

  • • Database size via pg_database_size()
  • • Active connections from pg_stat_activity
  • • Connection state monitoring

SQLite Metrics

  • • File size monitoring
  • • Simple connection testing
  • • Performance tracking
Database Operations
15,847
SELECT queries
3,291
INSERT operations
1,456
UPDATE operations
234
DELETE operations

Resource Utilization

Buffer Pool Usage
78%
Query Cache Hit Rate
92%
Index Usage Efficiency
85%

Historical Trends

Performance Over Time

Performance Chart Visualization

Resource Usage Trends

Resource Chart Visualization

Metric Status Tracking

Current Implementation Status

The health monitoring system currently focuses on data collection and visualization. Advanced alerting features are planned for future development.

Metric Status Levels

Metrics are stored with status indicators to help identify potential issues.

Normal Default

Metrics within expected ranges

Warning Attention

Metrics approaching concerning thresholds

Critical Urgent

Metrics indicating potential issues

Configuration Options

Health monitoring is configurable through the CodeForge configuration file.

Slow Query Threshold

Currently set to 1000ms for identifying slow queries

Check Interval

Health checks can be automated with configurable intervals

Connection Timeout

Database connection timeout settings for health tests

SMS

Send SMS notifications

Webhook

Custom webhook URLs

Data Collection & Management

Health Command

The CollectHealthMetricsCommand provides automated health data collection for monitoring dashboards.

php artisan codeforge:collect-health-metrics

Command Features:

  • Multi-connection health testing
  • Performance metrics collection
  • Database size monitoring
  • Query statistics aggregation

Scheduling Integration:

  • Laravel scheduler compatible
  • Configurable collection intervals
  • Automatic data storage
  • Built-in cleanup routines

Available Resources

Health Metrics Resource

Filament resource for viewing stored health metrics with filtering and search capabilities

  • • View all collected metrics
  • • Filter by connection and metric type
  • • Search by metric name
  • • Export functionality

Query Performance Logs

Filament resource for analyzing query performance data with detailed insights

  • • View query execution logs
  • • Identify slow queries
  • • Analyze query patterns
  • • Export performance data

Database Integration

Health monitoring automatically integrates with your existing database infrastructure:

Auto-Discovery

Automatically detects all configured database connections from your Laravel app

Safe Operation

Minimal performance impact with silent failure handling to protect your application

Driver Support

Supports MySQL, PostgreSQL, and SQLite with driver-specific optimizations

Health Scanner

Comprehensive health assessment

Issue Detection

Proactive detection of common database issues before they impact performance:

Performance Issues:

  • • Missing indexes on frequently queried columns
  • • Unused indexes consuming space
  • • Tables without primary keys
  • • Inefficient query patterns

Configuration Issues:

  • • Suboptimal buffer pool settings
  • • Incorrect timeout configurations
  • • Inadequate connection limits
  • • Missing maintenance tasks

Data Access & Analysis

Filament Resources

Access collected health data through built-in Filament administration interfaces.

Database Health Metrics Available

View and filter all collected health metrics

Query Performance Logs Available

Analyze query execution times and patterns

Export Capabilities

Export health data through Filament's built-in export functionality.

CSV Export

Export filtered data to CSV format

Excel Export

Export data with formatting to Excel

Available Data Analysis

Filtering Options

  • • Filter by database connection
  • • Filter by metric type
  • • Filter by time range
  • • Filter by status level

Search Capabilities

  • • Search by metric name
  • • Search by query content
  • • Search by error messages
  • • Global search across data

Sorting & Pagination

  • • Sort by any column
  • • Configurable page sizes
  • • Date-based ordering
  • • Performance-based sorting

Performance Insights

Query Performance Analysis

The health monitoring system provides insights into query performance patterns and identifies optimization opportunities.

Slow Query Detection

Automatically identifies queries taking longer than the configured threshold (1000ms by default)

  • • Query execution time tracking
  • • Query type classification
  • • Pattern analysis for optimization

Performance Trends

24-hour performance data helps identify patterns and performance degradation

  • • Historical performance data
  • • Average response time trends
  • • Query count distribution

Database-Specific Monitoring

Health monitoring adapts to different database systems and provides relevant metrics for each:

MySQL Optimization

  • • Connection count monitoring
  • • Table size analysis
  • • Index usage tracking

PostgreSQL Insights

  • • Active connection analysis
  • • Database size tracking
  • • Query state monitoring

SQLite Monitoring

  • • File size monitoring
  • • Performance tracking
  • • Lightweight metrics

Maintenance Task

Schedule ANALYZE TABLE for 3 tables that haven't been analyzed in over 30 days.

Optimization Categories

Performance

Query optimization and indexing

5 suggestions

Memory

Buffer pool and cache optimization

2 suggestions

Storage

Disk usage and table optimization

3 suggestions

Maintenance

Scheduled maintenance tasks

1 suggestion

Configuration

Health Monitoring Settings

Configure health monitoring through the CodeForge configuration file:

# Health Monitoring Configuration 'health_monitoring' => [ 'enabled' => true, 'check_interval' => 300, // 5 minutes 'slow_query_threshold' => 1000, // milliseconds 'connection_timeout' => 5, // seconds ], # Query Performance Logging 'enable_query_logging' => true, 'query_logging' => [ 'slow_query_threshold' => 1000, 'log_all_queries' => false, 'max_log_entries' => 10000, 'cleanup_older_than_days' => 30, ]

Available Settings:

  • enabled: Enable/disable health monitoring
  • check_interval: Health check frequency (seconds)
  • slow_query_threshold: Slow query detection threshold (ms)
  • connection_timeout: Connection test timeout

Query Logging Options:

  • log_all_queries: Log all queries vs. slow queries only
  • max_log_entries: Maximum query log entries to keep
  • cleanup_older_than_days: Automatic cleanup period
  • skip_patterns: Queries to exclude from logging

Automation Setup

Set up automated health metrics collection using Laravel's scheduler:

# In app/Console/Kernel.php protected function schedule(Schedule $schedule) { $schedule->command('codeforge:collect-health-metrics') ->everyFiveMinutes() ->withoutOverlapping(); }

Recommended Frequency

Run health collection every 5-15 minutes for optimal monitoring without performance impact

Performance Impact

Health monitoring has minimal performance overhead and includes silent failure handling

Start Monitoring Your Database Health

Comprehensive database health monitoring with real-time metrics, performance tracking, and data analysis capabilities.

Next: Migration Manager View Health Dashboard Back to Documentation