summaryrefslogtreecommitdiffstats
path: root/ml/Dimension.h
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2022-04-14 18:12:10 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2022-04-14 18:12:10 +0000
commitb5321aff06d6ea8d730d62aec2ffd8e9271c1ffc (patch)
tree36c41e35994786456154f9d3bf88c324763aeea4 /ml/Dimension.h
parentAdding upstream version 1.33.1. (diff)
downloadnetdata-b5321aff06d6ea8d730d62aec2ffd8e9271c1ffc.tar.xz
netdata-b5321aff06d6ea8d730d62aec2ffd8e9271c1ffc.zip
Adding upstream version 1.34.0.upstream/1.34.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--ml/Dimension.h49
1 files changed, 37 insertions, 12 deletions
diff --git a/ml/Dimension.h b/ml/Dimension.h
index fdf923ccc..44b348e9b 100644
--- a/ml/Dimension.h
+++ b/ml/Dimension.h
@@ -12,11 +12,7 @@ namespace ml {
class RrdDimension {
public:
- RrdDimension(RRDDIM *RD) : RD(RD), Ops(&RD->state->query_ops) {
- std::stringstream SS;
- SS << RD->rrdset->id << "|" << RD->name;
- ID = SS.str();
- }
+ RrdDimension(RRDDIM *RD) : RD(RD), Ops(&RD->state->query_ops) { }
RRDDIM *getRD() const { return RD; }
@@ -26,12 +22,29 @@ public:
unsigned updateEvery() const { return RD->update_every; }
- const std::string getID() const { return ID; }
+ const std::string getID() const {
+ RRDSET *RS = RD->rrdset;
+
+ std::stringstream SS;
+ SS << RS->context << "|" << RS->id << "|" << RD->name;
+ return SS.str();
+ }
- virtual ~RrdDimension() {}
+ void setAnomalyRateRD(RRDDIM *ARRD) { AnomalyRateRD = ARRD; }
+ RRDDIM *getAnomalyRateRD() const { return AnomalyRateRD; }
+
+ void setAnomalyRateRDName(const char *Name) const {
+ rrddim_set_name(AnomalyRateRD->rrdset, AnomalyRateRD, Name);
+ }
+
+ virtual ~RrdDimension() {
+ rrddim_free_custom(AnomalyRateRD->rrdset, AnomalyRateRD, 0);
+ }
private:
RRDDIM *RD;
+ RRDDIM *AnomalyRateRD;
+
struct rrddim_volatile::rrddim_query_ops *Ops;
std::string ID;
@@ -55,27 +68,28 @@ public:
}
bool shouldTrain(const TimePoint &TP) const {
+ if (ConstantModel)
+ return false;
+
return (LastTrainedAt + TrainEvery) < TP;
}
bool isTrained() const { return Trained; }
- double updateTrainingDuration(double Duration) {
- return TrainingDuration.exchange(Duration);
- }
-
private:
std::pair<CalculatedNumber *, size_t> getCalculatedNumbers();
public:
TimePoint LastTrainedAt{Seconds{0}};
+protected:
+ std::atomic<bool> ConstantModel{false};
+
private:
Seconds TrainEvery;
KMeans KM;
std::atomic<bool> Trained{false};
- std::atomic<double> TrainingDuration{0.0};
};
class PredictableDimension : public TrainableDimension {
@@ -88,9 +102,20 @@ public:
bool isAnomalous() { return AnomalyBit; }
+ void updateAnomalyBitCounter(RRDSET *RS, unsigned Elapsed, bool IsAnomalous) {
+ AnomalyBitCounter += IsAnomalous;
+
+ if (Elapsed == Cfg.DBEngineAnomalyRateEvery) {
+ double AR = static_cast<double>(AnomalyBitCounter) / Cfg.DBEngineAnomalyRateEvery;
+ rrddim_set_by_pointer(RS, getAnomalyRateRD(), AR * 1000);
+ AnomalyBitCounter = 0;
+ }
+ }
+
private:
CalculatedNumber AnomalyScore{0.0};
std::atomic<bool> AnomalyBit{false};
+ unsigned AnomalyBitCounter{0};
std::vector<CalculatedNumber> CNs;
};