feat: Add persistent storage support for Redis and APCu (v0.4.0)
All checks were successful
Create Release Package / build-release (push) Successful in 56s

- Add StorageFactory class for storage adapter selection with fallback
- Support Redis storage for shared metrics across instances
- Support APCu storage for high-performance single-server deployments
- Add Storage tab in admin settings with configuration UI
- Add connection testing for Redis and APCu adapters
- Support environment variables for Docker/containerized deployments
- Update Collector to use StorageFactory instead of hardcoded InMemory
- Add all translations (English and German)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-02-02 16:15:53 +01:00
parent bad977bef0
commit 898af5e9d2
11 changed files with 1693 additions and 13 deletions

61
PLAN.md
View File

@@ -59,6 +59,7 @@ wp-prometheus/
│ └── release.yml # CI/CD pipeline
├── assets/
│ ├── css/ # Admin/Frontend styles
│ ├── dashboards/ # Grafana dashboard templates
│ └── js/
│ └── admin.js # Admin JavaScript
├── languages/ # Translation files
@@ -67,13 +68,17 @@ wp-prometheus/
├── releases/ # Release packages
├── src/
│ ├── Admin/
│ │ ├── DashboardProvider.php
│ │ └── Settings.php
│ ├── Endpoint/
│ │ └── MetricsEndpoint.php
│ ├── License/
│ │ └── Manager.php
│ ├── Metrics/
│ │ ── Collector.php
│ │ ── Collector.php
│ │ ├── CustomMetricBuilder.php
│ │ ├── RuntimeCollector.php
│ │ └── StorageFactory.php
│ ├── Installer.php
│ ├── Plugin.php
│ └── index.php
@@ -159,13 +164,57 @@ Alternatively, the token can be passed as a query parameter (for testing):
https://example.com/metrics/?token=your-auth-token
```
## Storage Configuration
The plugin supports multiple storage backends for Prometheus metrics:
### Available Adapters
| Adapter | Description | Use Case |
| --------- | ------------------------------- | ------------------------------------- |
| In-Memory | Default, no persistence | Development, single request metrics |
| Redis | Shared storage across instances | Production, load-balanced environments|
| APCu | High-performance local cache | Production, single-server deployments |
### Environment Variables
For Docker or containerized environments, configure storage via environment variables:
```bash
# Storage adapter selection
WP_PROMETHEUS_STORAGE_ADAPTER=redis
# Redis configuration
WP_PROMETHEUS_REDIS_HOST=redis
WP_PROMETHEUS_REDIS_PORT=6379
WP_PROMETHEUS_REDIS_PASSWORD=secret
WP_PROMETHEUS_REDIS_DATABASE=0
WP_PROMETHEUS_REDIS_PREFIX=WORDPRESS_PROMETHEUS_
# APCu configuration
WP_PROMETHEUS_APCU_PREFIX=wp_prom
```
### Docker Compose Example
```yaml
services:
wordpress:
image: wordpress:latest
environment:
WP_PROMETHEUS_STORAGE_ADAPTER: redis
WP_PROMETHEUS_REDIS_HOST: redis
WP_PROMETHEUS_REDIS_PORT: 6379
depends_on:
- redis
redis:
image: redis:alpine
```
## Future Enhancements
### Version 0.3.0
- Custom metric builder in admin
- Metric export/import
- Grafana dashboard templates
*No planned features at this time.*
## Dependencies