| Total Complexity | 5 |
| Total Lines | 53 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 8 | class SystemMetric extends Model |
||
| 9 | { |
||
| 10 | use HasFactory; |
||
|
|
|||
| 11 | |||
| 12 | protected $fillable = [ |
||
| 13 | 'metric_type', |
||
| 14 | 'value', |
||
| 15 | 'recorded_at', |
||
| 16 | ]; |
||
| 17 | |||
| 18 | protected $casts = [ |
||
| 19 | 'value' => 'float', |
||
| 20 | 'recorded_at' => 'datetime', |
||
| 21 | ]; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * Scope to get CPU metrics |
||
| 25 | */ |
||
| 26 | public function scopeCpu($query) |
||
| 27 | { |
||
| 28 | return $query->where('metric_type', 'cpu'); |
||
| 29 | } |
||
| 30 | |||
| 31 | /** |
||
| 32 | * Scope to get RAM metrics |
||
| 33 | */ |
||
| 34 | public function scopeRam($query) |
||
| 37 | } |
||
| 38 | |||
| 39 | /** |
||
| 40 | * Scope to get metrics for a specific time period |
||
| 41 | */ |
||
| 42 | public function scopeForPeriod($query, int $hours) |
||
| 43 | { |
||
| 44 | return $query->where('recorded_at', '>=', now()->subHours($hours)); |
||
| 45 | } |
||
| 46 | |||
| 47 | /** |
||
| 48 | * Scope to get metrics for a specific date range |
||
| 49 | */ |
||
| 50 | public function scopeBetweenDates($query, $startDate, $endDate) |
||
| 53 | } |
||
| 54 | |||
| 55 | /** |
||
| 56 | * Clean up old metrics (older than specified days) |
||
| 57 | */ |
||
| 58 | public static function cleanupOldMetrics(int $days = 60): int |
||
| 61 | } |
||
| 62 | } |
||
| 63 |