Advanced monitoring and alerting system for Laravel applications with real-time notifications across multiple channels.
- 🔍 Query Monitoring - Detect and log slow database queries
- 💾 Memory Monitoring - Track memory usage and prevent leaks
- 🚨 Exception Monitoring - Catch and categorize exceptions
- ⚡ Performance Monitoring - Monitor response times
- 🔐 Security Monitoring - Track security threats and attacks
- 🤖 AI Insights & Predictions - Machine learning powered analysis (v1.2.0)
- 💰 Cost Optimizer - Infrastructure cost analysis and optimization (NEW v1.3.0)
- 📊 Beautiful Dashboard - Real-time metrics visualization
- 🔔 Multi-Channel Alerts - Slack, Telegram, Discord, Email
- 🧩 Modular Architecture - Easily extend with custom modules
- ⚙️ Smart Thresholds - Configurable alert triggers
- 📈 Analytics - Detailed performance insights
composer require picobaz/laravel-sentinel# Install and run migrations
php artisan sentinel:installThis will:
- Publish configuration file to
config/sentinel.php - Publish views to
resources/views/vendor/sentinel - Run migrations automatically
If you prefer manual installation:
# Publish config
php artisan vendor:publish --tag=sentinel-config
# Publish views (optional)
php artisan vendor:publish --tag=sentinel-views
# Run migrations
php artisan migrateIf you encounter "Table sentinel_logs doesn't exist" error:
# Make sure migrations ran
php artisan migrate
# If still having issues, check if table exists
php artisan tinker
>>> Schema::hasTable('sentinel_logs')
# Clear cache
php artisan config:clear
php artisan cache:clearNote: Sentinel is designed to fail gracefully. If tables don't exist, it won't log anything until migrations are run.
Edit config/sentinel.php:
return [
'enabled' => true,
'modules' => [
'queryMonitor' => true,
'memoryMonitor' => true,
'exceptionMonitor' => true,
'performanceMonitor' => true,
],
'thresholds' => [
'query_time' => 1000,
'memory_usage' => 128,
'response_time' => 2000,
],
'notifications' => [
'channels' => [
'telegram' => true,
'slack' => false,
'email' => true,
'discord' => false,
],
],
];SENTINEL_ENABLED=true
SENTINEL_QUERY_TIME_THRESHOLD=1000
SENTINEL_MEMORY_THRESHOLD=128
SENTINEL_RESPONSE_TIME_THRESHOLD=2000
SENTINEL_TELEGRAM_ENABLED=true
SENTINEL_TELEGRAM_BOT_TOKEN=your_bot_token
SENTINEL_TELEGRAM_CHAT_ID=your_chat_id
SENTINEL_SLACK_ENABLED=false
SENTINEL_SLACK_WEBHOOK=your_webhook_url
SENTINEL_EMAIL_ENABLED=true
SENTINEL_EMAIL_RECIPIENTS=admin@example.com,dev@example.comSentinel automatically monitors your application once installed. All modules run in the background.
use PicoBaz\Sentinel\Facades\Sentinel;
Sentinel::log('custom', [
'action' => 'user_login',
'user_id' => 123,
'ip' => request()->ip(),
]);Add to specific routes:
Route::middleware(['sentinel'])->group(function () {
Route::get('/dashboard', [DashboardController::class, 'index']);
});Access the dashboard at: http://your-app.test/sentinel
php artisan sentinel:status
php artisan sentinel:security-report --hours=24
php artisan sentinel:ai-insights --refresh
php artisan sentinel:cost-optimizer --refreshThe AI Insights module uses machine learning algorithms to analyze your application's behavior and provide actionable insights:
Capabilities:
- 📊 Pattern recognition and analysis
- 🔍 Anomaly detection across all metrics
- 🔮 Performance predictions (24h and 7-day forecasts)
- 💡 Automated optimization recommendations
⚠️ Downtime risk assessment- 📈 Trend analysis and forecasting
- Peak Hours Detection - Identifies when your app experiences highest load
- Slow Endpoint Identification - Automatically finds performance bottlenecks
- Memory Trend Analysis - Tracks memory usage patterns over time
- Error Pattern Recognition - Detects recurring errors and their frequency
Uses statistical analysis (Z-score) to detect unusual behavior:
- Response time anomalies
- Memory usage spikes
- Unusual error rates
- Query count anomalies
Machine learning predictions for:
- Performance Trends - Will your app get slower or faster?
- Memory Usage - Predict memory consumption for next 7 days
- Error Rate Forecasting - Anticipate error increases
- Downtime Risk Scoring - 0-100 risk score with severity levels
AI-generated actionable recommendations:
- Optimize slow endpoints
- Scale during peak hours
- Memory optimization suggestions
- Critical issue alerts
SENTINEL_AI_INSIGHTS=true
SENTINEL_AI_ANALYSIS_FREQUENCY=hourly
SENTINEL_AI_PREDICTION_WINDOW=24
SENTINEL_AI_ANOMALY_THRESHOLD=2.5
SENTINEL_AI_MIN_SAMPLES=20php artisan sentinel:ai-insights
# Refresh and view
php artisan sentinel:ai-insights --refreshOutput includes:
🏥 System Health
Score: 85/100 - Status: GOOD
⚠️ Anomalies Detected
response_time: 3 anomalies
Threshold: 2500ms | Max: 4200ms
🔮 Predictions
📉 Performance: degrading
Current: 1200ms | 24h: 1350ms | 7d: 1800ms
⬆️ Memory: increasing
Current: 85MB | 24h: 92MB | 7d: 115MB
💡 AI Recommendations
🚨 [critical] Memory Threshold Breach Predicted
Memory usage is predicted to exceed threshold within 7 days
→ Investigate memory leaks and optimize memory-intensive operations
use PicoBaz\Sentinel\Modules\AIInsights\AIInsightsHelper;
$healthScore = AIInsightsHelper::getHealthScore();
$predictions = AIInsightsHelper::getPredictions();
$anomalies = AIInsightsHelper::getAnomalies();
$recommendations = AIInsightsHelper::getRecommendations();
$summary = AIInsightsHelper::getInsightsSummary();
if (AIInsightsHelper::hasCriticalRecommendations()) {
}AI analysis runs automatically every hour. Customize in your AppServiceProvider:
use PicoBaz\Sentinel\Modules\AIInsights\AIInsightsModule;
$module = app(AIInsightsModule::class);
$module->analyzePatterns();
$module->detectAnomalies();
$module->generatePredictions();
$module->generateRecommendations();- Collects logs from past 7 days
- Groups data by time, endpoint, type
- Calculates statistical distributions
- Identifies significant patterns
Anomaly = |value - mean| > (threshold * standard_deviation)
Default threshold: 2.5 (captures 99% of normal data)
Future Value = Current Average + (Trend * Time Period)
Trend = Slope calculated using least squares method
Health Score = 100 - Downtime Risk - (Active Anomalies * 10)
Range: 0-100
Status: Excellent (80+) | Good (60+) | Fair (40+) | Poor (20+) | Critical (<20)
$ php artisan sentinel:ai-insights
🔮 Predictions
⬆️ Memory: increasing
Current: 128MB | 7d: 195MB
⚠️ WARNING: Threshold breach predicted!
💡 AI Recommendations
🚨 [critical] Memory Threshold Breach Predicted
→ Investigate memory leaks in scheduled jobs📊 Patterns Analysis
🐌 Slowest Endpoints:
/api/reports: 3500ms avg (245 requests)
/dashboard: 2100ms avg (1200 requests)
💡 AI Recommendations
⚠️ [high] Optimize Slow Endpoints
→ Add database indexes for reports queries📊 Patterns Analysis
🕐 Peak Hours: 9:00, 10:00, 11:00, 14:00
Average Load: 450 | Peak: 1200
💡 AI Recommendations
📌 [medium] Scale During Peak Hours
→ Consider auto-scaling during 9:00-11:00, 14:00Get insights via dashboard API:
Route::get('/api/sentinel/ai-insights', function () {
return response()->json(AIInsightsHelper::getInsightsSummary());
});Response:
{
"patterns": {
"peak_hours": {"hours": [9, 10, 14], "peak_load": 1200},
"slow_endpoints": {...}
},
"anomalies": {
"response_time": {"detected": true, "count": 3}
},
"predictions": {
"performance": {"trend": "degrading", "prediction_7d": 1800},
"downtime_risk": {"level": "medium", "score": 45}
},
"recommendations": [...]
}The Security Monitor module tracks and prevents security threats:
- ✅ Failed login attempts
- ✅ SQL Injection attempts
- ✅ XSS (Cross-Site Scripting) attempts
- ✅ Path traversal attempts
- ✅ Command injection attempts
- ✅ Rate limiting violations
- ✅ Unauthorized access attempts
- ✅ File integrity monitoring
- ✅ IP blacklisting (manual & automatic)
- ✅ Security scoring system
SENTINEL_SECURITY_MONITOR=true
SENTINEL_SECURITY_AUTO_BLOCK=true
SENTINEL_SECURITY_AUTO_BLOCK_SCORE=20
SENTINEL_SECURITY_BLACKLIST=192.168.1.100,10.0.0.5Add security middleware to protect routes:
Route::middleware(['sentinel.security'])->group(function () {
Route::get('/admin', [AdminController::class, 'index']);
});use PicoBaz\Sentinel\Modules\SecurityMonitor\SecurityHelper;
SecurityHelper::getSecurityScore('192.168.1.1');
SecurityHelper::addToBlacklist('192.168.1.100', 'Multiple failed logins');
SecurityHelper::removeFromBlacklist('192.168.1.100');
SecurityHelper::isIpBlacklisted('192.168.1.100');
SecurityHelper::getThreatLevel(45);use PicoBaz\Sentinel\Modules\SecurityMonitor\SecurityMonitorModule;
$monitor = app(SecurityMonitorModule::class);
$monitor->checkFileIntegrity([
base_path('.env'),
base_path('composer.json'),
]);Generate comprehensive security reports:
php artisan sentinel:security-report --hours=24Output includes:
- Failed login attempts
- Suspicious requests by type
- Rate limiting violations
- Top threat IPs with security scores
- Blacklisted IPs
namespace App\Sentinel\Modules;
class CustomModule
{
public function boot()
{
// Your monitoring logic
}
}Register in config/sentinel.php:
'modules' => [
'customModule' => true,
],- Create a bot via @BotFather
- Get your chat ID from @userinfobot
- Configure in
.env
- Create incoming webhook in Slack
- Add webhook URL to
.env
- Create webhook in Discord server settings
- Add webhook URL to
.env
GET /sentinel/metrics/{type}?hours=24Types: query, memory, exception, performance
Response:
[
{
"id": 1,
"type": "query",
"data": {...},
"severity": "warning",
"created_at": "2024-01-01 12:00:00"
}
]Contributions are welcome! Please feel free to submit a Pull Request.
This package is open-sourced software licensed under the MIT license.
PicoBaz
- Email: picobaz3@gmail.com
- GitHub: @PicoBaz
- Telegram: @picobaz
If you find this package helpful, please consider giving it a ⭐ on GitHub!
For detailed documentation, visit https://github.com/PicoBaz/laravel-sentinel/wiki
Report issues at https://github.com/PicoBaz/laravel-sentinel/issues
Optimize your infrastructure costs with AI-powered analysis and actionable recommendations. Track spending, identify waste, and save money while maintaining performance.
Key Features:
- 💻 Multi-Cloud Cost Analysis (AWS, DigitalOcean, Linode)
- 📊 Complete Cost Breakdown (Compute, Database, Storage, Network, Cache)
- 💡 Smart Optimization Recommendations
- 📈 ROI Calculator & Payback Analysis
- ⚡ Efficiency Scoring (A-F Grade)
- 💰 Potential Savings Identification
# Analyze infrastructure costs
php artisan sentinel:cost-optimizer
# Force refresh analysis
php artisan sentinel:cost-optimizer --refresh💰 Cost Overview
┌─────────────────────┬──────────┐
│ Metric │ Value │
├─────────────────────┼──────────┤
│ Monthly Cost │ $152.50 │
│ Yearly Cost │ $1,830.00│
│ Cost per 1K Requests│ $0.0234 │
└─────────────────────┴──────────┘
📊 Cost Breakdown
┌──────────┬──────────────┬───────┬──────────────┐
│ Category │ Monthly Cost │ Share │ Distribution │
├──────────┼──────────────┼───────┼──────────────┤
│ Compute │ $60.00 │ 39.3% │ ████░░░░░░░░ │
│ Database │ $45.00 │ 29.5% │ ███░░░░░░░░░ │
│ Storage │ $15.00 │ 9.8% │ █░░░░░░░░░░░ │
│ Network │ $30.00 │ 19.7% │ ██░░░░░░░░░░ │
│ Cache │ $2.50 │ 1.6% │ ░░░░░░░░░░░░ │
└──────────┴──────────────┴───────┴──────────────┘
⚡ Efficiency Score
Grade: B | Score: 82/100
Good! Some minor optimizations available.
💡 Optimization Recommendations
⚠️ [high] Database Query Optimization
⚡ Performance Gain: 40-80%
→ Review queries with: php artisan sentinel:query-report
📌 [medium] Image Optimization
💰 Savings: $12.00/month
→ Implement WebP format and lazy loading
💵 Total Potential Savings: $12.00/month ($144.00/year)
use PicoBaz\Sentinel\Modules\CostOptimizer\CostOptimizerHelper;
// Get total costs
$monthly = CostOptimizerHelper::getTotalMonthlyCost();
$yearly = CostOptimizerHelper::getTotalYearlyCost();
// Cost breakdown by category
$breakdown = CostOptimizerHelper::getCostBreakdown();
// Returns: ['compute' => 60.00, 'database' => 45.00, ...]
// Get potential savings
$savings = CostOptimizerHelper::getPotentialSavings();
// Efficiency metrics
$score = CostOptimizerHelper::getEfficiencyScore(); // 0-100
$grade = CostOptimizerHelper::getEfficiencyGrade(); // A, B, C, D, F
// Cost per request
$perRequest = CostOptimizerHelper::getCostPerRequest();
// ROI calculation
$roi = CostOptimizerHelper::calculateROI(1000);
// Returns: [
// 'annual_savings' => 144.00,
// 'implementation_cost' => 1000,
// 'payback_months' => 6.9,
// 'roi_percent' => -85.6,
// 'break_even_date' => '2025-07-15'
// ]
// Get all optimizations
$optimizations = CostOptimizerHelper::getOptimizations();
foreach ($optimizations as $opt) {
echo "{$opt['title']}: Save \${$opt['savings']}/month\n";
}
// Get complete analysis
$analysis = CostOptimizerHelper::getCostAnalysis();- Server utilization tracking
- Upsize/downsize recommendations
- Multi-instance cost aggregation
- Provider-specific pricing
- Query performance analysis
- Missing index detection
- Cache opportunity identification
- Optimization suggestions with performance impact
- Storage usage tracking
- Compression recommendations
- Lifecycle policy suggestions
- Cost per GB calculation
- Bandwidth usage tracking
- CDN hit rate optimization
- Image optimization recommendations
- Potential bandwidth reduction
- Cache effectiveness scoring
- ROI calculation
- Query caching opportunities
- Performance gain estimation
Server Sizing:
Utilization < 30% → Downgrade recommendation
Utilization > 80% → Upgrade recommendation
Utilization 30-80% → Optimal
Database Optimizations:
- Add missing indexes (0-90% speedup)
- Fix N+1 queries (40-80% speedup)
- Implement query caching (30-60% speedup)
Network Optimizations:
- Optimize CDN cache (potential 40% savings)
- Image format optimization (WebP)
- Lazy loading implementation
Storage Optimizations:
- Enable compression (30% savings)
- Lifecycle policies (20% savings)
Add to your .env:
SENTINEL_COST_OPTIMIZER=true
# Provider Configuration
SENTINEL_COST_PROVIDER=aws
SENTINEL_COST_INSTANCE_TYPE=t3.small
SENTINEL_COST_INSTANCE_COUNT=1
# Database
SENTINEL_COST_DB_PROVIDER=aws
SENTINEL_COST_DB_TYPE=rds.t3.small
# Storage
SENTINEL_COST_STORAGE_PROVIDER=aws
SENTINEL_COST_STORAGE_GB=100
# Network/CDN
SENTINEL_COST_CDN_PROVIDER=aws
SENTINEL_COST_BANDWIDTH_GB=500
SENTINEL_COST_CDN_HIT_RATE=70
# Cache
SENTINEL_COST_CACHE_PROVIDER=aws
SENTINEL_COST_CACHE_INSTANCE=cache.t3.micro
# Analysis
SENTINEL_COST_ANALYSIS_FREQUENCY=dailyAWS:
- EC2 instances (t3 family)
- RDS databases
- S3 storage
- CloudFront CDN
- ElastiCache
DigitalOcean:
- Droplets (Basic plans)
- Managed Databases
- Spaces storage
Linode:
- Compute instances
- All standard plans
Analysis:
- Instance: t3.medium ($60/month)
- Utilization: 25%
- Recommendation: Downgrade to t3.small
Result:
💰 Savings: $30/month ($360/year)
⏱️ Implementation: 1 hour
Risk: Low
Analysis:
- Slow queries: 145
- Missing indexes: 12
- Avg query time: 850ms
Recommendations:
1. Add indexes (Performance: 70% faster)
2. Cache frequent queries (Load reduction: 60%)
Result:
⚡ Performance: 70% improvement
💰 Cost: $12.50/month (caching)
📊 ROI: 340%
Analysis:
- Bandwidth: 2TB/month
- CDN Hit Rate: 55%
- Cost: $170/month
Recommendations:
- Optimize cache headers
- Enable WebP images
- Target hit rate: 85%
Result:
💰 Savings: $68/month ($816/year)
📈 Performance: 40% faster load times
Grade A (90-100): Excellent - Well optimized
Grade B (80-89): Good - Minor improvements available
Grade C (70-79): Fair - Consider optimizations
Grade D (60-69): Poor - Optimization recommended
Grade F (<60): Critical - Immediate action needed
Cost Optimizer works seamlessly with other Sentinel modules:
- AI Insights: Correlates costs with performance predictions
- Query Monitor: Identifies expensive database operations
- Performance Monitor: Links slow endpoints to resource costs
- Memory Monitor: Tracks memory-related cost implications
Route::get('/api/sentinel/costs/overview', function () {
return [
'monthly' => CostOptimizerHelper::getTotalMonthlyCost(),
'breakdown' => CostOptimizerHelper::getCostBreakdown(),
'efficiency' => CostOptimizerHelper::getEfficiencyScore(),
];
});
Route::get('/api/sentinel/costs/savings', function () {
return [
'potential_monthly' => CostOptimizerHelper::getPotentialSavings(),
'potential_yearly' => CostOptimizerHelper::getPotentialSavings() * 12,
'optimizations' => CostOptimizerHelper::getOptimizations(),
];
});- Run Analysis Regularly: Daily automated analysis catches cost drift
- Review Recommendations: Prioritize high-impact, low-risk optimizations
- Track Changes: Monitor cost trends after implementing optimizations
- Test Before Production: Validate sizing changes in staging first
- Document Decisions: Keep track of why certain recommendations were accepted/rejected
The module includes a sophisticated ROI calculator:
$roi = CostOptimizerHelper::calculateROI($implementationCost = 1000);
// Output:
[
'annual_savings' => 144.00,
'implementation_cost' => 1000,
'payback_months' => 6.9,
'roi_percent' => -85.6, // Negative first year, positive after
'break_even_date' => '2025-07-15'
]