generated from worksome/package-skeleton-laravel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CurrentMasterSupervisorsMetric.php
35 lines (28 loc) · 1.08 KB
/
CurrentMasterSupervisorsMetric.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
<?php
declare(strict_types=1);
namespace Worksome\HorizonTelemetry\Metrics;
use Illuminate\Support\Collection;
use Laravel\Horizon\Contracts\MasterSupervisorRepository;
use OpenTelemetry\API\Metrics\ObserverInterface;
use Worksome\HorizonTelemetry\Enums\MeterName;
use Worksome\HorizonTelemetry\Enums\MeterUnit;
use Worksome\HorizonTelemetry\MeterProvider;
readonly class CurrentMasterSupervisorsMetric
{
public function __construct(
private MeterProvider $meterProvider,
private MasterSupervisorRepository $masterSupervisorRepository,
) {
}
public function __invoke(): void
{
$meter = $this->meterProvider->getMeter(MeterName::CurrentMasterSupervisors);
$masterSupervisors = Collection::make($this->masterSupervisorRepository->all());
$meter->createObservableGauge(
MeterName::CurrentMasterSupervisors->value,
MeterUnit::MasterSupervisors->value,
'The total number of master supervisors.',
fn (ObserverInterface $observer) => $observer->observe($masterSupervisors->count())
);
}
}