summaryrefslogtreecommitdiffstats
path: root/ml/Host.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/Host.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 'ml/Host.h')
-rw-r--r--ml/Host.h44
1 files changed, 40 insertions, 4 deletions
diff --git a/ml/Host.h b/ml/Host.h
index 86591d7a..61d3b162 100644
--- a/ml/Host.h
+++ b/ml/Host.h
@@ -14,7 +14,27 @@ namespace ml {
class RrdHost {
public:
- RrdHost(RRDHOST *RH) : RH(RH) {}
+ RrdHost(RRDHOST *RH) : RH(RH) {
+ AnomalyRateRS = rrdset_create(
+ RH,
+ "anomaly_detection",
+ "anomaly_rates",
+ NULL, // name
+ "anomaly_rates",
+ NULL, // ctx
+ "Average anomaly rate",
+ "anomaly rate",
+ "netdata",
+ "ml",
+ 39189,
+ Cfg.DBEngineAnomalyRateEvery,
+ RRDSET_TYPE_LINE
+ );
+
+ AnomalyRateRS->flags = static_cast<RRDSET_FLAGS>(
+ static_cast<int>(AnomalyRateRS->flags) | RRDSET_FLAG_HIDDEN
+ );
+ }
RRDHOST *getRH() { return RH; }
@@ -35,12 +55,13 @@ public:
protected:
RRDHOST *RH;
+ RRDSET *AnomalyRateRS;
// Protect dimension and lock maps
std::mutex Mutex;
- std::map<RRDDIM *, Dimension *> DimensionsMap;
- std::map<Dimension *, std::mutex> LocksMap;
+ std::unordered_map<RRDDIM *, Dimension *> DimensionsMap;
+ std::unordered_map<Dimension *, std::mutex> LocksMap;
};
class TrainableHost : public RrdHost {
@@ -49,9 +70,22 @@ public:
void train();
+ void updateResourceUsage() {
+ std::lock_guard<std::mutex> Lock(ResourceUsageMutex);
+ getrusage(RUSAGE_THREAD, &ResourceUsage);
+ }
+
+ void getResourceUsage(struct rusage *RU) {
+ std::lock_guard<std::mutex> Lock(ResourceUsageMutex);
+ memcpy(RU, &ResourceUsage, sizeof(struct rusage));
+ }
+
private:
std::pair<Dimension *, Duration<double>> findDimensionToTrain(const TimePoint &NowTP);
void trainDimension(Dimension *D, const TimePoint &NowTP);
+
+ struct rusage ResourceUsage{};
+ std::mutex ResourceUsageMutex;
};
class DetectableHost : public TrainableHost {
@@ -88,12 +122,14 @@ private:
static_cast<size_t>(Cfg.ADMinWindowSize * Cfg.ADWindowRateThreshold)
};
- CalculatedNumber AnomalyRate{0.0};
+ CalculatedNumber WindowAnomalyRate{0.0};
size_t NumAnomalousDimensions{0};
size_t NumNormalDimensions{0};
size_t NumTrainedDimensions{0};
+ unsigned AnomalyRateTimer{0};
+
Database DB{Cfg.AnomalyDBPath};
};