=== Site Health Monitor & Slow Query Monitor === Contributors: liaisontw Tags: performance, site-health, database, slow-query, profiling Requires at least: 6.0 Tested up to: 7.0 Requires PHP: 7.4 Stable tag: 2.0.0 License: GPLv3 or later License URI: https://www.gnu.org/licenses/gpl-3.0.html
An engineering-focused WordPress diagnostic plugin that provides site health metrics and database slow query profiling **by leveraging WordPress’s official query debugging mechanism (`SAVEQUERIES`)**.
---
## == Description ==
**Site Health Monitor & Slow Query Monitor** is an admin-only diagnostic tool built for developers and operators who want **clear visibility into WordPress performance characteristics** without introducing undocumented runtime behavior.
This plugin intentionally **requires `SAVEQUERIES` to be enabled in `wp-config.php`**, and does not attempt to bypass or reimplement WordPress core database instrumentation.
### Why this matters
Rather than intercepting or mutating the database layer, this plugin:
* Respects WordPress’s established debugging contract
* Uses **core-supported query timing data**
* Makes performance trade-offs **explicit and auditable**
* Avoids fragile hooks into internal execution paths
---
## == Requirements ==
To enable slow query monitoring, the following **must** be set in `wp-config.php`:
```php
define( 'SAVEQUERIES', true );
This constant must be defined before WordPress bootstrap, as required by core.
If SAVEQUERIES is not enabled, slow query monitoring will be automatically disabled and the plugin will operate in site health metrics–only mode.
- PHP memory usage
- Aggregate database query time
- REST API response latency
- Active plugin count
- WordPress version
- Uses
$wpdb->queriesas the authoritative source - Automatic slow query detection via time thresholds
- Query normalization and aggregation
- Persistent storage for historical analysis
- Zero interference with query execution
liaison-site-health-monitor/
├── liaison-site-health-monitor.php # Plugin bootstrap
├── includes/
│ ├── class-liaison-site-health-monitor.php # Main file
│ ├── class-liaison-site-health-monitor-metrics.php # Runtime metrics collection
│ ├── class-liaison-site-health-monitor-db.php # Persistence layer
│ ├── class-liaison-site-health-monitor-profiler.php # SAVEQUERIES-based analysis
│ └── class-liaison-site-health-monitor-admin.php # Admin UI controller
├── admin/
│ └── partials/
│ └── liaison-site-health-monitor-admin-display.php # Admin dashboard
└── uninstall.php # Cleanup logic
[WordPress Runtime]
|
|-- SAVEQUERIES enabled
|
v
[$wpdb->queries]
|
|-- [SQL, time, caller]
|
v
[SHM Profiler]
|
|-- Threshold filtering
|-- Normalization & aggregation
|
v
[Custom DB Table]
|
v
[Admin Dashboard]
-
Admin dashboard loads.
-
Metrics collector gathers:
memory_get_usage(true)- REST request timing
- Plugin state and WordPress version
-
Metrics are rendered synchronously in the admin UI.
-
WordPress records query timing into
$wpdb->queries(core behavior). -
On admin page load:
- Plugin inspects recorded queries
- Filters queries exceeding the configured threshold
-
Slow queries are:
- Normalized (values stripped)
- Stored in a plugin-owned table
-
Aggregated results are displayed in the dashboard.
WordPress deliberately gates query timing behind SAVEQUERIES to ensure developers explicitly opt into performance overhead.
This plugin embraces that design decision:
- No attempt to override
$wpdb - No undocumented filters or runtime mutation
- No silent performance impact
Instead, it provides:
- Transparent prerequisites
- Predictable behavior
- Alignment with WordPress core debugging philosophy
This makes the plugin suitable for development, staging, and controlled production diagnostics.
-
Admin-only access
- Dashboard restricted to privileged users.
-
No sensitive data exposure
- Query values are normalized before storage.
-
No runtime mutation
- Does not alter database execution flow.
-
Clear uninstall behavior
- Plugin-owned tables removed on uninstall.
- Uses WordPress-supported debugging mechanisms
- Easy to reason about and audit
- No fragile DB-layer interception
- Clear performance cost model
- Ideal for learning and diagnosis
- Requires
SAVEQUERIESto be enabled - Higher overhead than production-safe profilers
- Not intended for always-on monitoring
- Less suitable for high-traffic production sites
-
Add the following to
wp-config.php:define( 'SAVEQUERIES', true );
-
Upload the plugin to
wp-content/plugins/site-health-monitor. -
Activate via WordPress admin.
-
Navigate to: Tools → Site Health Monitor
-
Review site metrics and slow query data.
- Tested with
SAVEQUERIESenabled and disabled. - Verifies graceful degradation when unavailable.
- Manual validation of query timing accuracy.
- No dependency on non-core WordPress behavior.
- Provides site health metrics and database slow query profiling
- SAVEQUERIES-based slow query analysis
- Introduced query normalization & aggregation
- Added explicit requirement documentation
- Refined admin dashboard
- Clarified architectural trade-offs