blob: f053691753c6b31394eb32eb5ae3752278fafd89 [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;
Krzysztof Grobelnyc8e3a642020-10-23 12:29:16 +020025
26 private:
Krzysztof Grobelny80697712021-03-04 09:49:27 +000027 class CollectionData;
28 class DataPoint;
29 class DataInterval;
30 class DataStartup;
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +000031
Krzysztof Grobelny80697712021-03-04 09:49:27 +000032 static std::vector<std::unique_ptr<CollectionData>>
33 makeCollectionData(size_t size, OperationType, CollectionTimeScope,
34 CollectionDuration);
35
36 void attemptUnpackJsonMetadata();
37 CollectionData& findAssociatedData(const interfaces::Sensor& notifier);
Krzysztof Grobelny6ccfcbf2020-11-04 09:31:36 +010038
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +000039 std::string id;
40 std::string metadata;
41 std::vector<MetricValue> readings;
42 Sensors sensors;
Krzysztof Grobelnye8fc5752021-02-05 14:30:45 +000043 OperationType operationType;
Krzysztof Grobelny80697712021-03-04 09:49:27 +000044 CollectionTimeScope collectionTimeScope;
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +000045 CollectionDuration collectionDuration;
Krzysztof Grobelny80697712021-03-04 09:49:27 +000046 std::vector<std::unique_ptr<CollectionData>> collectionAlgorithms;
47 std::unique_ptr<interfaces::Clock> clock;
Krzysztof Grobelnyc8e3a642020-10-23 12:29:16 +020048};