blob: dfed38308cf4c7185e9f049396617d2c3b88a7ea [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;
Krzysztof Grobelny80697712021-03-04 09:49:27 +000020 std::vector<MetricValue> getReadings() const override;
Krzysztof Grobelny6ccfcbf2020-11-04 09:31:36 +010021 void sensorUpdated(interfaces::Sensor&, uint64_t) override;
22 void sensorUpdated(interfaces::Sensor&, uint64_t, double value) override;
Krzysztof Grobelnyd2238192020-12-02 09:27:28 +000023 LabeledMetricParameters dumpConfiguration() const override;
Krzysztof Grobelnyc8e3a642020-10-23 12:29:16 +020024
25 private:
Krzysztof Grobelny80697712021-03-04 09:49:27 +000026 class CollectionData;
27 class DataPoint;
28 class DataInterval;
29 class DataStartup;
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +000030
Krzysztof Grobelny80697712021-03-04 09:49:27 +000031 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);
Krzysztof Grobelny6ccfcbf2020-11-04 09:31:36 +010037
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +000038 std::string id;
39 std::string metadata;
40 std::vector<MetricValue> readings;
41 Sensors sensors;
Krzysztof Grobelnye8fc5752021-02-05 14:30:45 +000042 OperationType operationType;
Krzysztof Grobelny80697712021-03-04 09:49:27 +000043 CollectionTimeScope collectionTimeScope;
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +000044 CollectionDuration collectionDuration;
Krzysztof Grobelny80697712021-03-04 09:49:27 +000045 std::vector<std::unique_ptr<CollectionData>> collectionAlgorithms;
46 std::unique_ptr<interfaces::Clock> clock;
Krzysztof Grobelnyc8e3a642020-10-23 12:29:16 +020047};