generated from worksome/package-skeleton-laravel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CurrentProcessesMetric.php
40 lines (33 loc) · 1.32 KB
/
CurrentProcessesMetric.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
39
40
<?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 CurrentProcessesMetric
{
public function __construct(
private MeterProvider $meterProvider,
private WorkloadRepository $workloadRepository,
) {
}
public function __invoke(): void
{
$meter = $this->meterProvider->getMeter(MeterName::CurrentProcesses);
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::CurrentProcesses->with($workload['name']),
MeterUnit::Processes->value,
'The total number of processes per queue.',
fn (ObserverInterface $observer) => $observer->observe($workload['processes'])
);
}
);
}
}