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_collection.cpp b/health_metric_collection.cpp
index 552a2c3..ae7d593 100644
--- a/health_metric_collection.cpp
+++ b/health_metric_collection.cpp
@@ -103,8 +103,7 @@
               std::to_underlying(config.subType), "VALUE",
               (double)activePercValue);
         /* For CPU, both user and monitor uses percentage values */
-        metrics[config.subType]->update(
-            MValue(activePercValue, activePercValue));
+        metrics[config.subType]->update(MValue(activePercValue, 100));
     }
     return true;
 }
@@ -150,21 +149,19 @@
         }
         else if (name.starts_with("Shmem"))
         {
-            memoryValues[MetricIntf::SubType::memoryShared] = value;
+            memoryValues[MetricIntf::SubType::memoryShared] += value;
         }
     }
 
     for (auto& config : configs)
     {
-        auto absoluteValue = memoryValues.at(config.subType);
-        auto memoryTotal = memoryValues.at(MetricIntf::SubType::memoryTotal);
-        double percentValue = (memoryTotal - absoluteValue) / memoryTotal * 100;
         // Convert kB to Bytes
-        absoluteValue = absoluteValue * 1024;
-        debug("Memory Metric {SUBTYPE}: {VALUE}, {PERCENT}", "SUBTYPE",
-              std::to_underlying(config.subType), "VALUE", absoluteValue,
-              "PERCENT", percentValue);
-        metrics[config.subType]->update(MValue(absoluteValue, percentValue));
+        auto value = memoryValues.at(config.subType) * 1024;
+        auto total = memoryValues.at(MetricIntf::SubType::memoryTotal) * 1024;
+        debug("Memory Metric {SUBTYPE}: {VALUE}, {TOTAL}", "SUBTYPE",
+              std::to_underlying(config.subType), "VALUE", value, "TOTAL",
+              total);
+        metrics[config.subType]->update(MValue(value, total));
     }
     return true;
 }
@@ -181,14 +178,12 @@
                   strerror(e), "PATH", config.path);
             continue;
         }
+        double value = buffer.f_bfree * buffer.f_frsize;
         double total = buffer.f_blocks * buffer.f_frsize;
-        double available = buffer.f_bfree * buffer.f_frsize;
-        double availablePercent = ((available / total) * 100);
-
-        debug("Storage Metric {SUBTYPE}: {TOTAL} {AVAIL} {AVAIL_PERCENT}",
-              "SUBTYPE", std::to_underlying(config.subType), "TOTAL", total,
-              "AVAIL", available, "AVAIL_PERCENT", availablePercent);
-        metrics[config.subType]->update(MValue(available, availablePercent));
+        debug("Storage Metric {SUBTYPE}: {VALUE}, {TOTAL}", "SUBTYPE",
+              std::to_underlying(config.subType), "VALUE", value, "TOTAL",
+              total);
+        metrics[config.subType]->update(MValue(value, total));
     }
     return true;
 }