blob: 7929aac6faa376ede173499a0bf6e2af530225de [file] [log] [blame]
Krzysztof Grobelnyc8e3a642020-10-23 12:29:16 +02001#pragma once
2
Krzysztof Grobelny80697712021-03-04 09:49:27 +00003#include "interfaces/clock.hpp"
Krzysztof Grobelnyc8e3a642020-10-23 12:29:16 +02004#include "interfaces/metric.hpp"
Krzysztof Grobelny6ccfcbf2020-11-04 09:31:36 +01005#include "interfaces/sensor.hpp"
Krzysztof Grobelnyc8e3a642020-10-23 12:29:16 +02006#include "interfaces/sensor_listener.hpp"
7
Krzysztof Grobelny6ccfcbf2020-11-04 09:31:36 +01008class Metric :
9 public interfaces::Metric,
10 public interfaces::SensorListener,
11 public std::enable_shared_from_this<Metric>
Krzysztof Grobelnyc8e3a642020-10-23 12:29:16 +020012{
13 public:
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +000014 Metric(Sensors sensors, OperationType operationType, std::string id,
Krzysztof Grobelny80697712021-03-04 09:49:27 +000015 std::string metadata, CollectionTimeScope, CollectionDuration,
16 std::unique_ptr<interfaces::Clock>);
17 ~Metric();
Krzysztof Grobelnyc8e3a642020-10-23 12:29:16 +020018
Krzysztof Grobelny6ccfcbf2020-11-04 09:31:36 +010019 void initialize() override;
Lukasz Kazmierczak7e098e92021-09-16 15:59:56 +020020 void deinitialize() override;
Krzysztof Grobelny80697712021-03-04 09:49:27 +000021 std::vector<MetricValue> getReadings() const override;
Krzysztof Grobelny6ccfcbf2020-11-04 09:31:36 +010022 void sensorUpdated(interfaces::Sensor&, uint64_t) override;
23 void sensorUpdated(interfaces::Sensor&, uint64_t, double value) override;
Krzysztof Grobelnyd2238192020-12-02 09:27:28 +000024 LabeledMetricParameters dumpConfiguration() const override;
Szymon Dompke3eb56862021-09-20 15:32:04 +020025 uint64_t sensorCount() const override;
Krzysztof Grobelnyc8e3a642020-10-23 12:29:16 +020026
27 private:
Krzysztof Grobelny80697712021-03-04 09:49:27 +000028 class CollectionData;
29 class DataPoint;
30 class DataInterval;
31 class DataStartup;
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +000032
Krzysztof Grobelny80697712021-03-04 09:49:27 +000033 static std::vector<std::unique_ptr<CollectionData>>
34 makeCollectionData(size_t size, OperationType, CollectionTimeScope,
35 CollectionDuration);
36
37 void attemptUnpackJsonMetadata();
38 CollectionData& findAssociatedData(const interfaces::Sensor& notifier);
Krzysztof Grobelny6ccfcbf2020-11-04 09:31:36 +010039
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +000040 std::string id;
41 std::string metadata;
42 std::vector<MetricValue> readings;
43 Sensors sensors;
Krzysztof Grobelnye8fc5752021-02-05 14:30:45 +000044 OperationType operationType;
Krzysztof Grobelny80697712021-03-04 09:49:27 +000045 CollectionTimeScope collectionTimeScope;
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +000046 CollectionDuration collectionDuration;
Krzysztof Grobelny80697712021-03-04 09:49:27 +000047 std::vector<std::unique_ptr<CollectionData>> collectionAlgorithms;
48 std::unique_ptr<interfaces::Clock> clock;
Krzysztof Grobelnyc8e3a642020-10-23 12:29:16 +020049};