generated from worksome/package-skeleton-laravel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CurrentJobsMetric.php
38 lines (31 loc) · 1.23 KB
/
CurrentJobsMetric.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php
declare(strict_types=1);
namespace Worksome\HorizonTelemetry\Metrics;
use Illuminate\Support\Collection;
use Laravel\Horizon\Contracts\WorkloadRepository;
use OpenTelemetry\API\Metrics\ObserverInterface;
use Worksome\HorizonTelemetry\Enums\MeterName;
use Worksome\HorizonTelemetry\Enums\MeterUnit;
use Worksome\HorizonTelemetry\MeterProvider;
readonly class CurrentJobsMetric
{
public function __construct(
private MeterProvider $meterProvider,
private WorkloadRepository $workloadRepository,
) {
}
public function __invoke(): void
{
$meter = $this->meterProvider->getMeter(MeterName::CurrentJobs);
Collection::make($this->workloadRepository->get())
->each(function (array $workload) use ($meter) {
/** @var array{name: string, length: integer, wait: double, processes: int, split_queues: array} $workload */
$meter->createObservableGauge(
MeterName::CurrentJobs->with($workload['name']),
MeterUnit::Jobs->value,
'The total number of jobs per queue.',
fn (ObserverInterface $observer) => $observer->observe($workload['length'])
);
});
}
}