Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config/pulse.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@
'enabled' => env('PULSE_SLOW_JOBS_ENABLED', true),
'sample_rate' => env('PULSE_SLOW_JOBS_SAMPLE_RATE', 1),
'threshold' => env('PULSE_SLOW_JOBS_THRESHOLD', 1000),
'average' => env('PULSE_SLOW_JOBS_AVERAGE', true),
'ignore' => [
// '/^Package\\\\Jobs\\\\/',
],
Expand Down
16 changes: 16 additions & 0 deletions resources/views/livewire/slow-jobs.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
label="Sort by"
:options="[
'slowest' => 'slowest',
'average' => 'average',
'count' => 'count',
]"
@change="loading = true"
Expand All @@ -28,12 +29,18 @@
<colgroup>
<col width="100%" />
<col width="0%" />
@if ($config['average'] === true)
<col width="0%" />
@endif
<col width="0%" />
</colgroup>
<x-pulse::thead>
<tr>
<x-pulse::th>Job</x-pulse::th>
<x-pulse::th class="text-right">Count</x-pulse::th>
@if ($config['average'] === true)
<x-pulse::th class="text-right">Average</x-pulse::th>
@endif
<x-pulse::th class="text-right">Slowest</x-pulse::th>
</tr>
</x-pulse::thead>
Expand All @@ -53,6 +60,15 @@
{{ number_format($job->count) }}
@endif
</x-pulse::td>
@if ($config['average'] === true)
<x-pulse::td numeric class="text-gray-700 dark:text-gray-300">
@if ($job->average === null)
<strong>Unknown</strong>
@else
<strong>{{ number_format($job->average) ?: '<1' }}</strong> ms
@endif
</x-pulse::td>
@endif
<x-pulse::td numeric class="text-gray-700 dark:text-gray-300">
@if ($job->slowest === null)
<strong>Unknown</strong>
Expand Down
8 changes: 6 additions & 2 deletions src/Livewire/SlowJobs.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,18 @@ public function render(): Renderable
[$slowJobs, $time, $runAt] = $this->remember(
fn () => $this->aggregate(
'slow_job',
['max', 'count'],
['max', 'avg', 'count'],
match ($this->orderBy) {
'count' => 'count',
'average' => 'avg',
default => 'max',
},
)->map(fn ($row) => (object) [
)
->reject(fn ($row) => is_null($row->max))
->map(fn ($row) => (object) [
'job' => $row->key,
'slowest' => $row->max,
'average' => $row->avg,
'count' => $row->count,
]),
$this->orderBy,
Expand Down
21 changes: 16 additions & 5 deletions src/Recorders/SlowJobs.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,22 @@ public function record(JobReleasedAfterException|JobFailed|JobProcessed|JobProce
];

$this->pulse->lazy(function () use ($timestamp, $timestampMs, $name, $lastJobStartedProcessingAt) {
if (
$this->underThreshold($duration = $timestampMs - $lastJobStartedProcessingAt) ||
! $this->shouldSample() ||
$this->shouldIgnore($name)
) {
if (! $this->shouldSample() || $this->shouldIgnore($name)) {
return;
}

$duration = $timestampMs - $lastJobStartedProcessingAt;

if ($this->config->get('pulse.recorders.'.self::class.'.average')) {
$this->pulse->record(
type: 'slow_job',
key: $name,
value: $duration,
timestamp: $timestamp,
)->avg();
}

if ($this->underThreshold($duration)) {
return;
}

Expand Down