Skip to content

Commit 005d582

Browse files
committed
feat(health): add plugin health monitoring system with alerts and tests
Implement comprehensive plugin health monitoring including metrics collection, status determination, and alerting. Add middleware for request tracking, service provider integration, and console commands for health checks. Include unit and feature tests for all components. Add configuration options for thresholds and alert channels. Implement caching for performance and add detailed health reports. Support JSON output and watch mode in console command. Fix various code style issues and add Laravel Pint for consistent formatting. Update composer dependencies and ensure proper error handling throughout the system.
1 parent 86837fa commit 005d582

19 files changed

+982
-446
lines changed

composer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@
3333
},
3434
"require-dev": {
3535
"phpunit/phpunit": "^10.0",
36-
"orchestra/testbench": "^8.0|^9.0"
36+
"orchestra/testbench": "^8.0|^9.0",
37+
"laravel/pint": "^1.25"
3738
},
3839
"autoload": {
3940
"psr-4": {
@@ -54,4 +55,4 @@
5455
},
5556
"minimum-stability": "stable",
5657
"prefer-stable": true
57-
}
58+
}

composer.lock

Lines changed: 67 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/laravel-plugin-system.php

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,157 @@
5757
|
5858
*/
5959
'enable_volt_support' => true,
60+
61+
/*
62+
|--------------------------------------------------------------------------
63+
| Health Monitoring
64+
|--------------------------------------------------------------------------
65+
|
66+
| Configuration for plugin health monitoring system.
67+
|
68+
*/
69+
'health_monitoring' => [
70+
/*
71+
|--------------------------------------------------------------------------
72+
| Enable Health Monitoring
73+
|--------------------------------------------------------------------------
74+
|
75+
| Whether to enable the plugin health monitoring system.
76+
|
77+
*/
78+
'enabled' => env('PLUGIN_HEALTH_MONITORING_ENABLED', true),
79+
80+
/*
81+
|--------------------------------------------------------------------------
82+
| Health Check Interval
83+
|--------------------------------------------------------------------------
84+
|
85+
| How often to run health checks (in minutes).
86+
|
87+
*/
88+
'check_interval' => env('PLUGIN_HEALTH_CHECK_INTERVAL', 5),
89+
90+
/*
91+
|--------------------------------------------------------------------------
92+
| Metrics Retention
93+
|--------------------------------------------------------------------------
94+
|
95+
| How long to keep health metrics (in days).
96+
|
97+
*/
98+
'metrics_retention_days' => env('PLUGIN_HEALTH_METRICS_RETENTION', 30),
99+
100+
/*
101+
|--------------------------------------------------------------------------
102+
| Health Thresholds
103+
|--------------------------------------------------------------------------
104+
|
105+
| Thresholds for determining plugin health status.
106+
|
107+
*/
108+
'thresholds' => [
109+
'memory_usage_mb' => env('PLUGIN_HEALTH_MEMORY_THRESHOLD', 100),
110+
'response_time_ms' => env('PLUGIN_HEALTH_RESPONSE_TIME_THRESHOLD', 5000),
111+
'error_rate_percent' => env('PLUGIN_HEALTH_ERROR_RATE_THRESHOLD', 5),
112+
'uptime_percent' => env('PLUGIN_HEALTH_UPTIME_THRESHOLD', 95),
113+
'cpu_usage_percent' => env('PLUGIN_HEALTH_CPU_THRESHOLD', 80),
114+
],
115+
116+
/*
117+
|--------------------------------------------------------------------------
118+
| Alert System
119+
|--------------------------------------------------------------------------
120+
|
121+
| Configuration for health monitoring alerts.
122+
|
123+
*/
124+
'alerts' => [
125+
'enabled' => env('PLUGIN_HEALTH_ALERTS_ENABLED', true),
126+
'channels' => ['log'], // Available: log, email, slack, webhook
127+
'cooldown_minutes' => env('PLUGIN_HEALTH_ALERT_COOLDOWN', 60),
128+
],
129+
130+
/*
131+
|--------------------------------------------------------------------------
132+
| Alert Thresholds
133+
|--------------------------------------------------------------------------
134+
|
135+
| Thresholds for triggering alerts.
136+
|
137+
*/
138+
'alert_thresholds' => [
139+
'critical_error_count' => env('PLUGIN_HEALTH_CRITICAL_ERROR_COUNT', 5),
140+
'warning_error_count' => env('PLUGIN_HEALTH_WARNING_ERROR_COUNT', 10),
141+
'memory_threshold' => env('PLUGIN_HEALTH_ALERT_MEMORY_THRESHOLD', 100 * 1024 * 1024), // 100MB
142+
'response_time_threshold' => env('PLUGIN_HEALTH_ALERT_RESPONSE_TIME', 5000), // 5 seconds
143+
'uptime_threshold' => env('PLUGIN_HEALTH_ALERT_UPTIME', 95), // 95%
144+
],
145+
146+
/*
147+
|--------------------------------------------------------------------------
148+
| Email Notifications
149+
|--------------------------------------------------------------------------
150+
|
151+
| Email settings for health monitoring alerts.
152+
|
153+
*/
154+
'email_recipients' => env('PLUGIN_HEALTH_EMAIL_RECIPIENTS', ''),
155+
156+
/*
157+
|--------------------------------------------------------------------------
158+
| Slack Integration
159+
|--------------------------------------------------------------------------
160+
|
161+
| Slack webhook URL for health monitoring alerts.
162+
|
163+
*/
164+
'slack_webhook_url' => env('PLUGIN_HEALTH_SLACK_WEBHOOK', ''),
165+
166+
/*
167+
|--------------------------------------------------------------------------
168+
| Custom Webhook
169+
|--------------------------------------------------------------------------
170+
|
171+
| Custom webhook URL for health monitoring alerts.
172+
|
173+
*/
174+
'webhook_url' => env('PLUGIN_HEALTH_WEBHOOK_URL', ''),
175+
176+
/*
177+
|--------------------------------------------------------------------------
178+
| Storage Path
179+
|--------------------------------------------------------------------------
180+
|
181+
| Path where health monitoring data will be stored.
182+
|
183+
*/
184+
'storage_path' => storage_path('app/plugin-health'),
185+
186+
/*
187+
|--------------------------------------------------------------------------
188+
| Cache Settings
189+
|--------------------------------------------------------------------------
190+
|
191+
| Cache configuration for health monitoring.
192+
|
193+
*/
194+
'cache' => [
195+
'prefix' => 'plugin_health_',
196+
'ttl' => env('PLUGIN_HEALTH_CACHE_TTL', 3600), // 1 hour
197+
],
198+
199+
/*
200+
|--------------------------------------------------------------------------
201+
| Auto Recovery
202+
|--------------------------------------------------------------------------
203+
|
204+
| Automatic recovery settings for failed plugins.
205+
|
206+
*/
207+
'auto_recovery' => [
208+
'enabled' => env('PLUGIN_HEALTH_AUTO_RECOVERY', false),
209+
'max_attempts' => env('PLUGIN_HEALTH_RECOVERY_ATTEMPTS', 3),
210+
'retry_delay_minutes' => env('PLUGIN_HEALTH_RETRY_DELAY', 5),
211+
],
212+
],
60213
];

0 commit comments

Comments
 (0)