Lines
100.00%
9 / 9
Methods
100.00%
1 / 1
Classes
100.00%
1 / 1
| Name | Lines | Methods | CRAP | ||||
|---|---|---|---|---|---|---|---|
| collectMetrics | 100.00% | 9 / 9 | 100.00% | 1 / 1 | 5 | ||
| 14 | final readonly class ComponentMetricSource implements RuntimeMetricSource | |
| 15 | { | |
| 16 | /** @return list<MetricFamily> */ | |
| 17 | public function collectMetrics(RuntimeSnapshot $snapshot): array | |
| 18 | { | |
| 19 | $component = $snapshot->component; | |
| 20 | $info = new MetricFamily('stewart_component_info', 'Version and protocol of the stewart Home Assistant integration; always 1.', MetricType::Gauge); | |
| 21 | $states = new MetricFamily('stewart_component_state', 'State of the stewart Home Assistant integration; 1 for the current one.', MetricType::Gauge); | |
| 22 | ||
| 23 | if ($component?->version !== null && $component->protocol !== null) { | |
| 24 | $info->recordSample(MetricLabels::fromLabel('version', $component->version)->withLabel('protocol', (string) $component->protocol), 1); | |
| 25 | } | |
| 26 | ||
| 27 | if ($component !== null) { | |
| 28 | foreach (ComponentState::cases() as $state) { | |
| 29 | $states->recordSample(MetricLabels::fromLabel('state', $state->value), $state === $component->state); | |
| 30 | } | |
| 31 | } | |
| 32 | ||
| 33 | return [$info, $states]; | |
| 34 | } | |
| 35 | } |