xref: /openbmc/telemetry/src/metric.hpp (revision cff70c14)
1 #pragma once
2 
3 #include "interfaces/clock.hpp"
4 #include "interfaces/metric.hpp"
5 #include "interfaces/metric_listener.hpp"
6 #include "interfaces/sensor.hpp"
7 #include "interfaces/sensor_listener.hpp"
8 #include "metrics/collection_data.hpp"
9 #include "types/collection_duration.hpp"
10 
11 class Metric :
12     public interfaces::Metric,
13     public interfaces::SensorListener,
14     public std::enable_shared_from_this<Metric>
15 {
16   public:
17     Metric(Sensors sensors, OperationType operationType, CollectionTimeScope,
18            CollectionDuration, std::unique_ptr<interfaces::Clock>);
19 
20     void initialize() override;
21     void deinitialize() override;
22     const std::vector<MetricValue>& getUpdatedReadings() override;
23     void sensorUpdated(interfaces::Sensor&, Milliseconds,
24                        double value) override;
25     LabeledMetricParameters dumpConfiguration() const override;
26     uint64_t metricCount() const override;
27     void registerForUpdates(interfaces::MetricListener& listener) override;
28     void unregisterFromUpdates(interfaces::MetricListener& listener) override;
29     void updateReadings(Milliseconds) override;
30     bool isTimerRequired() const override;
31 
32   private:
33     metrics::CollectionData&
34         findAssociatedData(const interfaces::Sensor& notifier);
35 
36     std::vector<MetricValue> readings;
37     Sensors sensors;
38     OperationType operationType;
39     CollectionTimeScope collectionTimeScope;
40     CollectionDuration collectionDuration;
41     std::vector<std::unique_ptr<metrics::CollectionData>> collectionAlgorithms;
42     std::unique_ptr<interfaces::Clock> clock;
43     std::vector<std::reference_wrapper<interfaces::MetricListener>> listeners;
44 };
45