Lines
100.00%
4 / 4
Functions and Methods
100.00%
3 / 3
Classes and Traits
100.00%
1 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| RuntimeMetricsCollector | 100.00% | 4 / 4 | 100.00% | 3 / 3 | 4 | 100.00% | 1 / 1 | |||
| __construct | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| collectMetrics | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| yieldFamilies | 100.00% | 2 / 2 | 100.00% | 1 / 1 | 2 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | declare(strict_types=1); | |
| 4 | ||
| 5 | namespace Stewart\Runtime\Metrics; | |
| 6 | ||
| 7 | use Stewart\Runtime\Control\Protocol\Status\RuntimeSnapshot; | |
| 8 | use Stewart\Runtime\Metrics\Exposition\MetricFamily; | |
| 9 | ||
| 10 | final readonly class RuntimeMetricsCollector | |
| 11 | { | |
| 12 | /** @param iterable<RuntimeMetricSource> $runtimeMetricSources */ | |
| 13 | public function __construct(private iterable $runtimeMetricSources) {} | |
| 14 | ||
| 15 | /** @return list<MetricFamily> */ | |
| 16 | public function collectMetrics(RuntimeSnapshot $snapshot): array | |
| 17 | { | |
| 18 | return iterator_to_array($this->yieldFamilies($snapshot), false); | |
| 19 | } | |
| 20 | ||
| 21 | /** @return iterable<MetricFamily> */ | |
| 22 | private function yieldFamilies(RuntimeSnapshot $snapshot): iterable | |
| 23 | { | |
| 24 | foreach ($this->runtimeMetricSources as $source) { | |
| 25 | yield from $source->collectMetrics($snapshot); | |
| 26 | } | |
| 27 | } | |
| 28 | } |