enescode / laravel-api-watchdog
API performance and status monitoring package.
Requires
- php: ^8.1
- guzzlehttp/guzzle: ^7.0
- illuminate/support: ^10.0|^11.0|^12.0
README
English
Laravel API Watchdog is a lightweight and powerful package designed to monitor your external API endpoints. It tracks response times, verifies status codes, and alerts you via Email or Logs when an API is down or performing poorly.
✨ Features
- 📡 Multi-Method Support: Monitor both
GETandPOSTrequests seamlessly. - ⚡ Performance Monitoring: Automatically alerts you if an API response exceeds your threshold (default: 2 seconds).
- 🔐 Authorization Support: Easily add custom headers and Bearer tokens for secure APIs.
- 🚨 Smart Alerting: Sends instant email notifications. If email is not configured, it intelligently falls back to
laravel.log. - 🛠 Scheduler Ready: Designed to work perfectly with Laravel's Task Scheduler.
🛠 Installation
- Install the package via composer:
composer require enescode/laravel-api-watchdog
✨ Publish the configuration file:
php artisan vendor:publish --tag="api-watchdog-config"
⚙️ Configuration
return [ 'notify_email' => 'admin@example.com', 'max_response_time' => 2000, // miliseconds 'endpoints' => [ [ 'name' => 'Payment Gateway', 'url' => '[https://api.example.com/v1/status](https://api.example.com/v1/status)', 'method' => 'POST', 'headers' => [ 'Authorization' => 'Bearer your-token-here' ], 'data' => ['check' => true], 'expect' => 200, ], ], ];
🚀 Usage
php artisan watchdog:check
📧 Email Configuration
To receive email alerts, make sure your .env file is properly configured with your SMTP settings.
Additionally, define the recipient email address for the watchdog alerts:
Laravel 10 add the command to your app/Console/Kernel.php:
protected function schedule(Schedule $schedule) { $schedule->command('watchdog:check')->everyFiveMinutes(); }
Laravel 10+ add the command to your routes/console.php:
Schedule::command('watchdog:check')->everyFiveMinutes();
Türkçe
Laravel API Watchdog, config dosyanızda belirlediğiniz API rotalarını sizin belirlediğiniz saniyelerde izler ve bir Endpoint uzun süre yada hiç yanıt vermezse sizi e-posta ile bilgilendirir. Böylece herhangi bir olumsuzlukta önceden bilgilendirilirsiniz.
✨ Özellikler
- 📡 Method Desteği: Hem
GEThem dePOSTisteklerini sorunsuz bir şekilde izleyin. - ⚡ Performans İzleme: Bir API yanıtı eşiğinizi aşarsa otomatik olarak sizi uyarır (varsayılan: 2 saniye).
- 🔐 Yetkilendirme Desteği: Güvenli API'ler için kolayca özel başlıklar ve Bearer token'ları ekleyin.
- 🚨 Akıllı Uyarı: Anında e-posta bildirimleri gönderir. E-posta yapılandırılmadıysa,
laravel.logdosyasına akıllıca geri döner. - 🛠 Zamanlayıcı Hazırlığı: Laravel'in Görev Zamanlayıcısı ile mükemmel şekilde çalışmak için tasarlanmıştır.
🛠 Kurulum
- Paketi composer aracılığıyla kurun:
composer require enescode/laravel-api-watchdog
✨ Yapılandırma dosyasını yayınlayın:
php artisan vendor:publish --tag="api-watchdog-config"
⚙️ Yapılandırma
return [ 'notify_email' => 'admin@example.com', 'max_response_time' => 2000, // milisaniye 'endpoints' => [ [ 'name' => 'Ödeme Geçidi', 'url' => '[https://api.example.com/v1/status](https://api.example.com/v1/status)', 'method' => 'POST', 'headers' => [ 'Authorization' => 'Bearer your-token-here' ], 'data' => ['check' => true], 'expect' => 200, ], ], ];
🚀 Kullanımı
php artisan watchdog:check
📧 E-Posta Ayarlaması
E-posta bildirimlerini alabilmek için .env dosyanızda SMTP ayarlarının yapılmış olduğundan emin olun.
Ayrıca, uyarıların gönderileceği e-posta adresini şu şekilde tanımlayın:
Laravel 10'da app/Console/Kernel.php dosyanıza ekleyin:
protected function schedule(Schedule $schedule) { $schedule->command('watchdog:check')->everyFiveMinutes(); }
Laravel 11 ve 12 de routes/console.php dosyanıza ekleyin:
Schedule::command('watchdog:check')->everyFiveMinutes();