1 #pragma once 2 3 #include "interfaces/clock.hpp" 4 #include "interfaces/metric.hpp" 5 #include "interfaces/sensor.hpp" 6 #include "interfaces/sensor_listener.hpp" 7 8 class Metric : 9 public interfaces::Metric, 10 public interfaces::SensorListener, 11 public std::enable_shared_from_this<Metric> 12 { 13 public: 14 Metric(Sensors sensors, OperationType operationType, std::string id, 15 std::string metadata, CollectionTimeScope, CollectionDuration, 16 std::unique_ptr<interfaces::Clock>); 17 ~Metric(); 18 19 void initialize() override; 20 std::vector<MetricValue> getReadings() const override; 21 void sensorUpdated(interfaces::Sensor&, uint64_t) override; 22 void sensorUpdated(interfaces::Sensor&, uint64_t, double value) override; 23 LabeledMetricParameters dumpConfiguration() const override; 24 25 private: 26 class CollectionData; 27 class DataPoint; 28 class DataInterval; 29 class DataStartup; 30 31 static std::vector<std::unique_ptr<CollectionData>> 32 makeCollectionData(size_t size, OperationType, CollectionTimeScope, 33 CollectionDuration); 34 35 void attemptUnpackJsonMetadata(); 36 CollectionData& findAssociatedData(const interfaces::Sensor& notifier); 37 38 std::string id; 39 std::string metadata; 40 std::vector<MetricValue> readings; 41 Sensors sensors; 42 OperationType operationType; 43 CollectionTimeScope collectionTimeScope; 44 CollectionDuration collectionDuration; 45 std::vector<std::unique_ptr<CollectionData>> collectionAlgorithms; 46 std::unique_ptr<interfaces::Clock> clock; 47 }; 48