romalytar/yammi-jobs-monitoring-laravel
Real-time queue monitoring & observability for Laravel. Dashboard for job runs, retries, failures, DLQ, stats, worker heartbeat, scheduled task outcomes, duration anomalies, and alerts (Slack/email/webhooks). Works with Redis, SQS, database, or sync—no extra infra.
Installation:
composer require romalytar/yammi-jobs-monitoring-laravel
php artisan vendor:publish --provider="RomaLytar\YammiJobsMonitor\YammiJobsMonitorServiceProvider" --tag="migrations"
php artisan migrate
First Use Case:
/jobs-monitor.dispatch(new ProcessPayment($userId));
Quick Wins:
.env (e.g., YAMMI_SLACK_WEBHOOK_URL) to notify on failures or anomalies.Job Lifecycle Tracking:
job.processing, job.failed, etc.).YammiJobsMonitor\Contracts\MonitorableJob for custom job metadata:
use YammiJobsMonitor\Contracts\MonitorableJob;
class ProcessPayment implements MonitorableJob {
public function getMonitoringMetadata(): array {
return ['user_id' => $this->userId, 'amount' => $this->amount];
}
}
Alerting System:
config/yammi.php:
'alerts' => [
'failure_threshold' => 3, // Retry 3 times before alerting
'duration_threshold' => 60, // Alert if job takes >60s
],
YAMMI_SLACK_WEBHOOK_URL=https://hooks.slack.com/...
YAMMI_ALERT_CHANNELS=slack
Scheduled Tasks:
schedule:run jobs by wrapping them in YammiJobsMonitor\Jobs\ScheduledTaskJob:
ScheduledTaskJob::dispatch($command)->onQueue('scheduled');
Worker Management:
YammiJobsMonitor\Workers\WorkerHeartbeat. Customize heartbeat interval in config:
'worker_heartbeat' => [
'interval' => 30, // Seconds
],
/jobs-monitor/workers.Dead Letter Queue (DLQ):
/jobs-monitor/dlq to inspect failed jobs.YammiJobsMonitor::retryFailedJob($failedJobId);
YammiJobsMonitor\Traits\Monitorable trait to retroactively enable monitoring:
use YammiJobsMonitor\Traits\Monitorable;
class LegacyJob {
use Monitorable;
}
/api/jobs?queue=default) or Laravel’s HTTP client:
$jobs = Http::get('/api/jobs')->json();
Performance Overhead:
worker_heartbeat.interval to balance granularity and performance.Database Bloat:
failed_jobs table.config/yammi.php:
'cleanup' => [
'failed_jobs_ttl' => 30, // Days to retain failed jobs
],
Run the cleanup manually:
php artisan yammi:cleanup
Alert Fatigue:
failure_threshold and fingerprinting to ignore duplicate failures:
'alerts' => [
'fingerprint_fields' => ['exception', 'payload_hash'], // Group similar failures
],
Worker Heartbeat Desync:
worker_heartbeat.interval or implement a secondary heartbeat mechanism (e.g., cron job ping).Queue Driver Quirks:
jobs table growth; consider archiving old jobs.Missing Jobs in Dashboard:
YammiJobsMonitorServiceProvider is registered in config/app.php.storage/logs/laravel.log for YammiJobsMonitor events.Alerts Not Triggering:
.env alert configurations (e.g., YAMMI_SLACK_WEBHOOK_URL).YammiJobsMonitor::alert('test', 'Test alert', ['channel' => 'slack']);
Dashboard Not Loading:
php artisan migrate
php artisan view:clear
php artisan cache:clear
Custom Alert Channels:
RomaLytar\YammiJobsMonitor\Contracts\AlertChannel:
class CustomChannel implements AlertChannel {
public function send(Alert $alert) {
// Send to your custom system (e.g., Teams, Datadog)
}
}
config/yammi.php:
'alert_channels' => [
'custom' => \App\Alerts\CustomChannel::class,
],
Custom Job Metadata:
getMonitoringMetadata() in jobs to include business-specific data (e.g., order IDs, user segments).Dashboard Extensions:
php artisan vendor:publish --provider="RomaLytar\YammiJobsMonitor\YammiJobsMonitorServiceProvider" --tag="views"
YammiJobsMonitor\Dashboard.Bulk Actions:
// Retry all failed jobs for a queue
YammiJobsMonitor::retryFailedJobsForQueue('emails');
Integration with Observability Tools:
YammiJobsMonitor\Metrics\MetricEmitter trait.
```markdown
### Pro Tips
- **Anomaly Detection**: Leverage `duration_threshold` to catch slow jobs early. Example:
```php
'alerts' => [
'duration_threshold' => 30, // Alert if job takes >30s (vs. avg 5s)
],
emails queue stuck due to SMTP issues).laravel-debugbar to correlate job failures with server metrics.yammi:cleanup step to your deploy script to prune old monitoring data.How can I help you explore Laravel packages today?