From f33643cbe5f0df69112330847545dc522b820039 Mon Sep 17 00:00:00 2001
From: Niko Ehrenfeuchter <nikolaus.ehrenfeuchter@unibas.ch>
Date: Mon, 12 Mar 2018 15:37:02 +0100
Subject: [PATCH] Distinguish high-load from probation from good-before.

---
 ATxCommon/Monitoring/Cpu.cs | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/ATxCommon/Monitoring/Cpu.cs b/ATxCommon/Monitoring/Cpu.cs
index f4fd3d3..c30332f 100644
--- a/ATxCommon/Monitoring/Cpu.cs
+++ b/ATxCommon/Monitoring/Cpu.cs
@@ -110,9 +110,15 @@ namespace ATxCommon.Monitoring
                 _loadReadings[3] = _cpuCounter.NextValue();
                 _load = _loadReadings.Average();
                 if (_loadReadings[3] > _limit) {
-                    Log.Debug("CPU load ({0}) violating limit ({1})!", _loadReadings[3], _limit);
-                    _behaving = 0;
-                    // TODO: fire callback for violating load limit
+                    if (_behaving > _probation) {
+                        // this means the load was considered as "low" before
+                        // TODO: fire callback for violating load limit
+                        Log.Debug("CPU load ({0}) violating limit ({1})!", _loadReadings[3], _limit);
+                    } else if (_behaving > 0) {
+                        // this means we were still in probation, so no need to trigger again...
+                        Log.Debug("Resetting behaving counter to 0 (was {0}).", _behaving);
+                    }
+                  _behaving = 0;
                 } else {
                     _behaving++;
                     if (_behaving == _probation) {
-- 
GitLab