Implement Phase 9: Prometheus Metrics (v0.9.0)
All checks were successful
Create Release Package / build-release (push) Successful in 1m8s
All checks were successful
Create Release Package / build-release (push) Successful in 1m8s
- Add Prometheus metrics integration via wp-prometheus hooks - Create Grafana dashboard JSON with 24 panels - Add metrics settings tab with enable/disable toggle - Expose inventory, booking, occupancy, revenue, and guest metrics Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
57
CLAUDE.md
57
CLAUDE.md
@@ -935,3 +935,60 @@ Admin features always work; frontend requires valid license.
|
||||
- CSV export with BOM (`\xEF\xBB\xBF`) ensures Excel compatibility
|
||||
- Guest data aggregation from bookings uses unique key pattern for anonymous guests
|
||||
- Occupancy calculation: (booked nights / total room nights) * 100
|
||||
|
||||
### 2026-02-03 - Version 0.9.0 (Prometheus Metrics)
|
||||
|
||||
**Completed:**
|
||||
|
||||
- Created `src/Integration/Prometheus.php` class (~700 lines)
|
||||
- Integration with wp-prometheus via `wp_prometheus_collect_metrics` hook
|
||||
- Dashboard registration via `wp_prometheus_register_dashboards` hook
|
||||
- Option to enable/disable metrics collection
|
||||
- Inventory metrics: buildings total, rooms by status, services by status
|
||||
- Booking metrics: by status, check-ins/outs today, upcoming 7 days, avg duration
|
||||
- Guest metrics: total, by status, repeat guests, new this month
|
||||
- Occupancy metrics: current rate, monthly rate, occupied rooms, bed capacity
|
||||
- Revenue metrics: this month, YTD, avg booking value, services revenue
|
||||
- Optimized SQL queries using `$wpdb->prepare()` throughout
|
||||
- Created `assets/grafana/wp-bnb-dashboard.json` Grafana dashboard
|
||||
- 24 panels with responsive grid layout
|
||||
- Occupancy gauges with color-coded thresholds (red < 30%, orange < 50%, yellow < 70%, green ≥ 70%)
|
||||
- Pie charts for bookings, rooms, and guests by status
|
||||
- Revenue stat panels (this month, YTD, avg value, services)
|
||||
- Guest stat panels (total, new, repeat, active services)
|
||||
- Today's activity panels (check-ins, check-outs, upcoming)
|
||||
- Prometheus datasource variable for flexibility
|
||||
- Auto-refresh every 5 minutes
|
||||
- Updated `src/Plugin.php`
|
||||
- Added Prometheus class import
|
||||
- Initialized Prometheus integration in `init_components()`
|
||||
- Added "Metrics" tab to settings page (6 tabs total)
|
||||
- Added `render_metrics_settings()` method with WP Prometheus detection
|
||||
- Added `save_metrics_settings()` method
|
||||
- Metrics reference table showing all available metrics
|
||||
- Updated version to 0.9.0
|
||||
|
||||
**Files Created:**
|
||||
|
||||
- `src/Integration/Prometheus.php` - Prometheus metrics integration class
|
||||
- `assets/grafana/wp-bnb-dashboard.json` - Pre-configured Grafana dashboard
|
||||
|
||||
**Files Changed:**
|
||||
|
||||
- `src/Plugin.php` - Prometheus initialization, metrics settings tab
|
||||
- `wp-bnb.php` - Version bump to 0.9.0 (header and constant)
|
||||
- `CHANGELOG.md` - Added v0.9.0 release notes
|
||||
- `PLAN.md` - Marked Phase 9 as complete
|
||||
- `README.md` - Added Prometheus metrics documentation
|
||||
|
||||
**Learnings:**
|
||||
|
||||
- wp-prometheus uses `wp_prometheus_collect_metrics` action with collector object
|
||||
- Collector provides `register_gauge()` for fluctuating values
|
||||
- Labels are passed as array to `register_gauge()`, values to `set()`
|
||||
- Grafana dashboard JSON requires proper panel IDs and grid positions
|
||||
- Occupancy queries need careful date range handling for month boundaries
|
||||
- Revenue queries use `DECIMAL(10,2)` casting for accurate sums
|
||||
- Metrics should be cached or computed efficiently as they're scraped frequently
|
||||
- Dashboard registration requires file path, title, description, icon, and plugin name
|
||||
- Settings tab detection uses `$prometheus_active` to show WP Prometheus status
|
||||
|
||||
Reference in New Issue
Block a user