Lines
100.00%
8 / 8
Methods
100.00%
1 / 1
Classes
100.00%
1 / 1
| Name | Lines | Methods | CRAP | ||||
|---|---|---|---|---|---|---|---|
| collectMetrics | 100.00% | 8 / 8 | 100.00% | 1 / 1 | 3 | ||
| 14 | final readonly class StoreMetricSource implements RuntimeMetricSource | |
| 15 | { | |
| 16 | /** @return list<MetricFamily> */ | |
| 17 | public function collectMetrics(RuntimeSnapshot $snapshot): array | |
| 18 | { | |
| 19 | $store = $snapshot->store; | |
| 20 | $available = new MetricFamily('stewart_store_available', 'Whether workers reach the store; 1 or 0.', MetricType::Gauge); | |
| 21 | $lastFailure = new MetricFamily('stewart_store_last_failure_timestamp_seconds', 'Unix time of the last store failure.', MetricType::Gauge); | |
| 22 | ||
| 23 | if ($store !== null) { | |
| 24 | $available->recordSample(MetricLabels::none(), $store->available); | |
| 25 | } | |
| 26 | ||
| 27 | if ($store?->lastFailureAt !== null) { | |
| 28 | $lastFailure->recordSample(MetricLabels::none(), PrometheusNumber::convertToEpochSeconds($store->lastFailureAt)); | |
| 29 | } | |
| 30 | ||
| 31 | return [$available, $lastFailure]; | |
| 32 | } | |
| 33 | } |