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 1
14final readonly class DaemonMetricSource implements RuntimeMetricSource
15{
16    /** @return list<MetricFamily> */
17    public function collectMetrics(RuntimeSnapshot $snapshot): array
18    {
19        $daemon = $snapshot->daemon;
20        $none = MetricLabels::none();
21        $build = MetricLabels::fromLabel('version', $daemon->version)->withLabel('ha_version', $daemon->haVersion ?? '');
22
23        return [
24            MetricFamily::createWithSample('stewart_build_info', 'Stewart and Home Assistant versions; always 1.', MetricType::Gauge, $build, 1),
25            MetricFamily::createWithSample('stewart_start_time_seconds', 'Unix time the daemon started.', MetricType::Gauge, $none, PrometheusNumber::convertToEpochSeconds($daemon->startedAt)),
26            MetricFamily::createWithSample('stewart_broker_memory_bytes', 'Memory the broker process holds.', MetricType::Gauge, $none, $daemon->memoryBytes),
27            MetricFamily::createWithSample('stewart_ha_entities', 'Entities in the Home Assistant state cache.', MetricType::Gauge, $none, $daemon->entities),
28        ];
29    }
30}