hamzi/corewatch
Embedded DevOps dashboard for Laravel: monitor CPU/RAM/disk, processes, and huge logs via /proc with zero external daemons. Secure whitelisted commands, health endpoint, and scheduled alerts (Slack/Telegram). Works with Livewire and admin panels like Filament/Nova.
Installation:
composer require hamzi/corewatch
php artisan vendor:publish --provider="Hamzi\CoreWatch\CoreWatchServiceProvider" --tag="corewatch-config"
Publish the default config and migrations:
php artisan migrate
First Use Case:
CoreWatchServiceProvider in config/app.php under providers./corewatch (or your configured route).Quick Start:
php artisan corewatch:install to auto-configure routes, middleware, and Filament integration (if used)./corewatch (or /admin/corewatch if using Filament).config/corewatch.php (adjust routes, middleware, and alert thresholds).storage/logs/corewatch.log (for package-level debugging).php artisan corewatch:docs (generates API reference for programmatic access).Process facade.
use Hamzi\CoreWatch\Facades\CoreWatch;
CoreWatch::metrics()->fetch(); // Manually trigger a refresh
CoreWatch::extend('custom_metric', function () {
return ['value' => app('cache')->stats()['memory_usage']['used_memory']];
});
// Frontend (Vue/JS)
Echo.channel('corewatch.logs')
.listen('LogEvent', (e) => console.log(e.message));
config/corewatch.php:
'log' => [
'channels' => ['single', 'daily'], // Monitor specific log channels
'levels' => ['error', 'critical'], // Focus on high-severity logs
],
config/corewatch.php:
'alerts' => [
'cpu' => ['threshold' => 90, 'notify' => ['email', 'slack']],
'memory' => ['threshold' => 80, 'cooldown' => 300], // 5-minute cooldown
],
use Hamzi\CoreWatch\Events\AlertTriggered;
event(new AlertTriggered('custom_alert', 'Database connection failed'));
CoreWatch::ops()->execute('php artisan queue:work --once');
Route::middleware(['corewatch.auth', 'corewatch.roles:admin'])->group(function () {
// Safe ops routes
});
use Hamzi\CoreWatch\Filament\Widgets\CoreWatchMetrics;
public function getWidgets(): array {
return [CoreWatchMetrics::class];
}
CoreWatch::resource('posts')->track('view_count');
Laravel Echo/Pusher:
config/broadcasting.php:
'pusher' => [
'key' => env('PUSHER_APP_KEY'),
'options' => ['cluster' => env('PUSHER_APP_CLUSTER')],
],
Queue Workers:
php artisan queue:work --daemon
Caching:
php artisan cache:clear
Multi-Server Setups:
WebSocket Dependencies:
/corewatch/logs) will fail.CoreWatch::shouldReceive('broadcastLog')->andReturnTrue();
Permission Issues:
www-data). Ensure:
chmod +x for scripts).corewatch.roles).Metric Polling Overhead:
*_interval in config) can spike CPU usage.metrics_interval = 60 (seconds) and adjust based on server load.Log Channel Mismatch:
config/corewatch.php includes the correct log channels (e.g., single, daily).storage/logs/corewatch.log for channel errors.Filament Conflicts:
corewatch route doesn’t conflict with Filament’s admin panel.config/corewatch.php:
'routes' => [
'prefix' => 'admin/corewatch',
],
Enable Debug Mode:
'debug' => env('COREWATCH_DEBUG', false),
storage/logs/corewatch.log.Clear Cached Metrics:
php artisan corewatch:clear-cache
Test Alerts Locally:
php artisan corewatch:test-alert cpu 95
Check Queue Jobs:
php artisan queue:failed-table
php artisan queue:work --once --tries=3
Custom Metric Providers:
Hamzi\CoreWatch\Contracts\MetricProvider:
class DatabaseMetricProvider implements MetricProvider {
public function getMetrics(): array {
return ['queries' => DB::getTotalQueries()];
}
}
config/corewatch.php:
'providers' => [
\App\Providers\DatabaseMetricProvider::class,
],
Alert Notifications:
CoreWatch::extendAlertChannel('discord', function ($alert) {
// Send to Discord webhook
});
UI Customization:
resources/views/vendor/corewatch/.metrics.blade.php to add custom charts.API Extensions:
$metrics = CoreWatch::metrics()->raw();
$logs = CoreWatch::logs()->recent(100);
Environment Variables:
COREWATCH_ (e.g., COREWATCH_ALERT_CPU_THRESHOLD=90)..env take precedence over config/corewatch.php.Middleware Order:
corewatch.auth before web middleware to protect routes:
Route::middleware(['corewatch.auth', 'web'])->group(...);
Log Retention:
Schema::table('corewatch_logs', function (Blueprint $table) {
$table->integer('retention_days')->default(30);
});
How can I help you explore Laravel packages today?