health: Use average value for metrics dbus value

In https://gbmc-review.git.corp.google.com/c/meta-gbmc-staging/+/45155,
we added the change to use average value for threshold... however, it
also changed the metric dbus value to use instantaneous value.

Tested:
- Platform5: http://fusion2/a7d4b885-8193-3222-927b-a5ad7c86721b
- Platform11:
  - http://fusion2/4b0eda88-3a0f-37d6-8670-0cf9d18e79e9
  - http://fusion2/33e0ae4c-6606-3770-9b1a-f9863ed9897d
- Platform15: http://fusion2/16ee84a1-b837-3591-bfcc-9e83cda12df8
- Platform17: http://fusion2/843869a6-dbeb-3f8d-bd5f-463e9ab04470
Platforms-Affected: all TTF
Google-Bug-Id: 425363873
Change-Id: Ic8e901eed76e4b6abb2f76de158e7bbb27a23db2
Signed-off-by: Willy Tu <wltu@google.com>
(cherry picked from commit fc9a13231f4eb0935791e5877b2e2a7c976f1cd2)
(cherry picked from commit 3900d3d5030d07fd7ad2f557dfb821a3862ed4b6)
diff --git a/recipes-phosphor/health/phosphor-health-monitor/0002-add-option-to-update-dbus-with-average-value.patch b/recipes-phosphor/health/phosphor-health-monitor/0002-add-option-to-update-dbus-with-average-value.patch
new file mode 100644
index 0000000..e8e981d
--- /dev/null
+++ b/recipes-phosphor/health/phosphor-health-monitor/0002-add-option-to-update-dbus-with-average-value.patch
@@ -0,0 +1,72 @@
+From 427abc78e62a0bd3e66f166d7505e7cc703608bc Mon Sep 17 00:00:00 2001
+From: Willy Tu <wltu@google.com>
+Date: Mon, 16 Jun 2025 17:06:24 +0000
+Subject: [PATCH] add option to update dbus with average value
+
+Change-Id: I85aedcc359345d7a8f87e7a80b4ca222f8dbfcc8
+Signed-off-by: Willy Tu <wltu@google.com>
+---
+ health_metric.cpp | 7 +++++++
+ meson.build       | 2 +-
+ meson.options     | 7 +++++++
+ 3 files changed, 15 insertions(+), 1 deletion(-)
+
+diff --git a/health_metric.cpp b/health_metric.cpp
+index f80f479..4bf714c 100644
+--- a/health_metric.cpp
++++ b/health_metric.cpp
+@@ -1,3 +1,5 @@
++#include "config.h"
++
+ #include "health_metric.hpp"
+ 
+ #include <phosphor-logging/lg2.hpp>
+@@ -199,7 +201,9 @@ void HealthMetric::checkThresholds(MValue value)
+ 
+ void HealthMetric::update(MValue value)
+ {
++#ifndef MONITOR_AVERAGE_VALUE
+     ValueIntf::value(value.current);
++#endif
+ 
+     // Maintain window size for threshold calculation
+     if (history.size() >= config.windowSize)
+@@ -218,6 +222,9 @@ void HealthMetric::update(MValue value)
+     double average = (std::accumulate(history.begin(), history.end(), 0.0)) /
+                      history.size();
+     value.current = average;
++#ifdef MONITOR_AVERAGE_VALUE
++    ValueIntf::value(value.current);
++#endif
+     checkThresholds(value);
+ }
+ 
+diff --git a/meson.build b/meson.build
+index 5f9b276..037a633 100644
+--- a/meson.build
++++ b/meson.build
+@@ -43,7 +43,7 @@ conf_data.set('HEALTH_BUS_NAME', '"xyz.openbmc_project.HealthMon"')
+ conf_data.set('HEALTH_SENSOR_PATH', '"/xyz/openbmc_project/sensors/utilization/"')
+ conf_data.set('SENSOR_OBJPATH', '"/xyz/openbmc_project/sensors"')
+ conf_data.set('INVENTORY_OBJPATH', '"/xyz/openbmc_project/inventory"')
+-
++conf_data.set('MONITOR_AVERAGE_VALUE', get_option('use-average-value').allowed())
+ configure_file(output : 'config.h',
+                configuration : conf_data)
+ 
+diff --git a/meson.options b/meson.options
+index 0fc2767..c841bf4 100644
+--- a/meson.options
++++ b/meson.options
+@@ -1 +1,8 @@
+ option('tests', type: 'feature', description: 'Build tests')
++
++option(
++    'use-average-value',
++    type: 'feature',
++    value: 'disabled',
++    description: 'Update the metric with average value.',
++)
+-- 
+2.50.0.rc2.692.g299adb8693-goog
+
diff --git a/recipes-phosphor/health/phosphor-health-monitor_%.bbappend b/recipes-phosphor/health/phosphor-health-monitor_%.bbappend
index cc0446e..72679ef 100644
--- a/recipes-phosphor/health/phosphor-health-monitor_%.bbappend
+++ b/recipes-phosphor/health/phosphor-health-monitor_%.bbappend
@@ -1,3 +1,9 @@
 FILESEXTRAPATHS:prepend:gbmc := "${THISDIR}/${PN}:"
 
-SRC_URI:append:gbmc = " file://0001-health-metric-use-instantaneous-value.patch"
+SRC_URI:append:gbmc = " \
+  file://0001-health-metric-use-instantaneous-value.patch \
+  file://0002-add-option-to-update-dbus-with-average-value.patch \
+"
+
+PACKAGECONFIG:append:gbmc = " average-value"
+PACKAGECONFIG[average-value] = "-Duse-average-value=enabled,-Duse-average-value=disabled"
\ No newline at end of file