summaryrefslogtreecommitdiffstats
path: root/ml/Dimension.h
diff options
context:
space:
mode:
Diffstat (limited to 'ml/Dimension.h')
-rw-r--r--ml/Dimension.h49
1 files changed, 37 insertions, 12 deletions
diff --git a/ml/Dimension.h b/ml/Dimension.h
index fdf923cc..44b348e9 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;
};