Lines
100.00%
14 / 14
Functions and Methods
100.00%
1 / 1
Classes and Traits
100.00%
1 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| BrokerMetricSource | 100.00% | 14 / 14 | 100.00% | 1 / 1 | 1 | 100.00% | 1 / 1 | |||
| collectMetrics | 100.00% | 14 / 14 | 100.00% | 1 / 1 | 1 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | declare(strict_types=1); | |
| 4 | ||
| 5 | namespace Stewart\Runtime\Metrics\Source; | |
| 6 | ||
| 7 | use Stewart\Runtime\Control\Protocol\Status\RuntimeSnapshot; | |
| 8 | use Stewart\Runtime\Metrics\Exposition\MetricFamily; | |
| 9 | use Stewart\Runtime\Metrics\Exposition\MetricLabels; | |
| 10 | use Stewart\Runtime\Metrics\Exposition\MetricType; | |
| 11 | use Stewart\Runtime\Metrics\RuntimeMetricSource; | |
| 12 | ||
| 13 | final readonly class BrokerMetricSource implements RuntimeMetricSource | |
| 14 | { | |
| 15 | /** @return list<MetricFamily> */ | |
| 16 | public function collectMetrics(RuntimeSnapshot $snapshot): array | |
| 17 | { | |
| 18 | $broker = $snapshot->broker; | |
| 19 | $routing = $broker->routing; | |
| 20 | $none = MetricLabels::none(); | |
| 21 | ||
| 22 | return [ | |
| 23 | MetricFamily::createWithSample('stewart_workers', 'Worker slots the broker supervises.', MetricType::Gauge, $none, $broker->workers), | |
| 24 | MetricFamily::createWithSample('stewart_workers_live', 'Worker processes currently running.', MetricType::Gauge, $none, $broker->liveWorkers), | |
| 25 | MetricFamily::createWithSample('stewart_service_calls_in_flight', 'Home Assistant calls awaiting an answer.', MetricType::Gauge, $none, $broker->inFlightServiceCalls), | |
| 26 | MetricFamily::createWithSample('stewart_service_calls_refused_total', 'Home Assistant calls refused for lack of a free slot.', MetricType::Counter, $none, $broker->refusedServiceCalls), | |
| 27 | MetricFamily::createWithSample('stewart_routing_subscriptions', 'Subscriptions in the broker routing index.', MetricType::Gauge, $none, $routing->subscriptions), | |
| 28 | MetricFamily::createWithSample('stewart_routing_patterns', 'Wildcard patterns in the broker routing index.', MetricType::Gauge, $none, $routing->patterns), | |
| 29 | MetricFamily::createWithSample('stewart_routing_cached_keys', 'Routing keys with a cached match.', MetricType::Gauge, $none, $routing->cachedKeys), | |
| 30 | MetricFamily::createWithSample('stewart_routing_cache_hits_total', 'Routing lookups answered from the cache.', MetricType::Counter, $none, $routing->cacheHits), | |
| 31 | MetricFamily::createWithSample('stewart_routing_cache_misses_total', 'Routing lookups that missed the cache.', MetricType::Counter, $none, $routing->cacheMisses), | |
| 32 | ]; | |
| 33 | } | |
| 34 | } |