'date', 'disk_used_bytes' => 'integer', 'disk_total_bytes' => 'integer', 'rx_bytes' => 'integer', 'tx_bytes' => 'integer', ]; } public function instance(): BelongsTo { return $this->belongsTo(Instance::class); } /** * The last $days days, oldest first, with gaps left as gaps. * * A missing day is not a zero. Filling it would draw a cliff into the chart * on every day the sampler could not reach the host, and the customer would * read an outage that never happened. * * @return Collection */ public static function series(Instance $instance, int $days = 14): Collection { return self::query() ->where('instance_id', $instance->id) ->where('day', '>=', Carbon::today()->subDays($days - 1)) ->orderBy('day') ->get(); } /** The most recent day that carries a disk reading, or null. */ public static function latestDisk(Instance $instance): ?self { return self::query() ->where('instance_id', $instance->id) ->whereNotNull('disk_used_bytes') ->orderByDesc('day') ->first(); } }