threshold: use absolute value for D-Bus

Use the absolute value for threshold rather than percentage value.
This involves passing the total value from the metric collection so it
can be used in percentage calculation within health metric logic.

Change-Id: I46240aee54117c70637f9fbf882018f0eac520b2
Signed-off-by: Jagpal Singh Gill <paligill@gmail.com>
diff --git a/health_metric.cpp b/health_metric.cpp
index a160025..4c391cd 100644
--- a/health_metric.cpp
+++ b/health_metric.cpp
@@ -104,7 +104,7 @@
         if (threshold == thresholds.end())
         {
             bound_map_t bounds;
-            bounds.emplace(bound, value.value);
+            bounds.emplace(bound, std::numeric_limits<double>::quiet_NaN());
             thresholds.emplace(type, bounds);
         }
         else
@@ -138,23 +138,26 @@
 }
 
 void HealthMetric::checkThreshold(ThresholdIntf::Type type,
-                                  ThresholdIntf::Bound bound, double value)
+                                  ThresholdIntf::Bound bound, MValue value)
 {
     auto threshold = std::make_tuple(type, bound);
     auto thresholds = ThresholdIntf::value();
 
     if (thresholds.contains(type) && thresholds[type].contains(bound))
     {
-        auto thresholdValue = thresholds[type][bound];
+        auto tConfig = config.thresholds.at(threshold);
+        auto thresholdValue = tConfig.value / 100 * value.total;
+        thresholds[type][bound] = thresholdValue;
+        ThresholdIntf::value(thresholds);
         auto assertions = ThresholdIntf::asserted();
-        if (didThresholdViolate(bound, thresholdValue, value))
+        if (didThresholdViolate(bound, thresholdValue, value.current))
         {
             if (!assertions.contains(threshold))
             {
                 assertions.insert(threshold);
                 ThresholdIntf::asserted(assertions);
-                ThresholdIntf::assertionChanged(type, bound, true, value);
-                auto tConfig = config.thresholds.at(threshold);
+                ThresholdIntf::assertionChanged(type, bound, true,
+                                                value.current);
                 if (tConfig.log)
                 {
                     error(
@@ -170,7 +173,7 @@
         {
             assertions.erase(threshold);
             ThresholdIntf::asserted(assertions);
-            ThresholdIntf::assertionChanged(type, bound, false, value);
+            ThresholdIntf::assertionChanged(type, bound, false, value.current);
             if (config.thresholds.find(threshold)->second.log)
             {
                 info(
@@ -182,7 +185,7 @@
     }
 }
 
-void HealthMetric::checkThresholds(double value)
+void HealthMetric::checkThresholds(MValue value)
 {
     if (!ThresholdIntf::value().empty())
     {
@@ -205,7 +208,7 @@
     {
         history.pop_front();
     }
-    history.push_back(value.user);
+    history.push_back(value.current);
 
     if (history.size() < config.windowSize)
     {
@@ -217,7 +220,7 @@
     double average = (std::accumulate(history.begin(), history.end(), 0.0)) /
                      history.size();
     ValueIntf::value(average);
-    checkThresholds(value.monitor);
+    checkThresholds(value);
 }
 
 void HealthMetric::create(const paths_t& bmcPaths)