From 725e4bf35457dc5f8a724892694b3c08d8a702e0 Mon Sep 17 00:00:00 2001 From: Qubad786 Date: Fri, 10 Jan 2025 21:24:54 +0500 Subject: [PATCH] Only retrieve aggregated CPU temperature (#15364) --- .../usr/lib/netdata/python.d/cputemp.chart.py | 25 ++++++++----------- .../middlewared/plugins/reporting/events.py | 5 +++- .../plugins/reporting/netdata/graphs.py | 2 +- .../middlewared/plugins/reporting/utils.py | 2 +- .../reporting/test_netdata_approximation.py | 18 ++++++------- 5 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/freenas/usr/lib/netdata/python.d/cputemp.chart.py b/src/freenas/usr/lib/netdata/python.d/cputemp.chart.py index e6f8edc42f923..8cae5256a3355 100755 --- a/src/freenas/usr/lib/netdata/python.d/cputemp.chart.py +++ b/src/freenas/usr/lib/netdata/python.d/cputemp.chart.py @@ -1,23 +1,24 @@ -from bases.FrameworkServices.SimpleService import SimpleService from collections import defaultdict from copy import deepcopy + +from bases.FrameworkServices.SimpleService import SimpleService from third_party import lm_sensors as sensors -from middlewared.utils.cpu import amd_cpu_temperatures, generic_cpu_temperatures, cpu_info +from middlewared.utils.cpu import amd_cpu_temperatures, generic_cpu_temperatures CPU_TEMPERATURE_FEAT_TYPE = 2 ORDER = [ - 'temperatures', + 'temp', ] # This is a prototype of chart definition which is used to dynamically create self.definitions CHARTS = { - 'temperatures': { + 'temp': { 'options': [None, 'Temperature', 'Celsius', 'temperature', 'sensors.temperature', 'line'], - 'lines': [] + 'lines': [['cpu_temp', 'cpu_temp', 'absolute']] } } @@ -75,11 +76,11 @@ def get_data(self): self.error(error) cpu_temps = {} - data = {} - for core, temp in cpu_temps.items(): - data[str(core)] = temp + core_temp = [] + for temp in cpu_temps.values(): + core_temp.append(temp) - return data or {str(i): 0 for i in range(cpu_info()['core_count'])} + return {'cpu_temp': sum(core_temp) / len(core_temp)} if len(core_temp) else {'cpu_temp': 0} def check(self): try: @@ -88,8 +89,4 @@ def check(self): self.error(error) return False - data = self.get_data() - for i in data: - self.definitions['temperatures']['lines'].append([str(i)]) - - return bool(data) + return True diff --git a/src/middlewared/middlewared/plugins/reporting/events.py b/src/middlewared/middlewared/plugins/reporting/events.py index 63a6b3b2587a6..acbcc6a984d95 100644 --- a/src/middlewared/middlewared/plugins/reporting/events.py +++ b/src/middlewared/middlewared/plugins/reporting/events.py @@ -6,6 +6,7 @@ from middlewared.validators import Range from .realtime_reporting import get_arc_stats, get_cpu_stats, get_disk_stats, get_interface_stats, get_memory_info +from .realtime_reporting.utils import safely_retrieve_dimension class RealtimeEventSource(EventSource): @@ -105,7 +106,9 @@ def run_sync(self): } # CPU temperature - data['cpu']['temperature_celsius'] = self.middleware.call_sync('reporting.cpu_temperatures') or None + data['cpu']['temperature_celsius'] = safely_retrieve_dimension( + netdata_metrics, 'cputemp.temp', 'cpu_temp', + ) or None self.send_event('ADDED', fields=data) time.sleep(interval) diff --git a/src/middlewared/middlewared/plugins/reporting/netdata/graphs.py b/src/middlewared/middlewared/plugins/reporting/netdata/graphs.py index 651b698ab3055..c9deec45dc054 100644 --- a/src/middlewared/middlewared/plugins/reporting/netdata/graphs.py +++ b/src/middlewared/middlewared/plugins/reporting/netdata/graphs.py @@ -29,7 +29,7 @@ class CPUTempPlugin(GraphBase): skip_zero_values_in_aggregation = True def get_chart_name(self, identifier: typing.Optional[str]) -> str: - return 'cputemp.temperatures' + return 'cputemp.temp' class MemoryPlugin(GraphBase): diff --git a/src/middlewared/middlewared/plugins/reporting/utils.py b/src/middlewared/middlewared/plugins/reporting/utils.py index ba68faaf9fa18..9fbdcd1fd83e0 100644 --- a/src/middlewared/middlewared/plugins/reporting/utils.py +++ b/src/middlewared/middlewared/plugins/reporting/utils.py @@ -122,7 +122,7 @@ def get_metrics_approximation( 'cpu.usage': core_count + 1, # cputemp - 'cputemp.temperatures': core_count, + 'cputemp.temp': 1, # ups 'nut_ups.charge': 1, diff --git a/src/middlewared/middlewared/pytest/unit/plugins/reporting/test_netdata_approximation.py b/src/middlewared/middlewared/pytest/unit/plugins/reporting/test_netdata_approximation.py index 4b1a82b48bac4..b48f228d32daa 100644 --- a/src/middlewared/middlewared/pytest/unit/plugins/reporting/test_netdata_approximation.py +++ b/src/middlewared/middlewared/pytest/unit/plugins/reporting/test_netdata_approximation.py @@ -4,9 +4,9 @@ @pytest.mark.parametrize('disk_count,core_count,interface_count,services_count,vms_count,expected_output', [ - (4, 2, 1, 10, 2, {1: 708, 60: 4}), - (1600, 32, 4, 10, 1, {1: 8763, 60: 1600}), - (10, 16, 2, 12, 3, {1: 847, 60: 10}), + (4, 2, 1, 10, 2, {1: 707, 60: 4}), + (1600, 32, 4, 10, 1, {1: 8732, 60: 1600}), + (10, 16, 2, 12, 3, {1: 832, 60: 10}), ]) def test_netdata_metrics_count_approximation( disk_count, core_count, interface_count, services_count, vms_count, expected_output @@ -19,14 +19,14 @@ def test_netdata_metrics_count_approximation( @pytest.mark.parametrize( 'disk_count,core_count,interface_count,services_count,vms_count,days,' 'bytes_per_point,tier_interval,expected_output', [ - (4, 2, 1, 10, 2, 7, 1, 1, 408), + (4, 2, 1, 10, 2, 7, 1, 1, 407), (4, 2, 1, 10, 1, 7, 4, 60, 25), - (1600, 32, 4, 2, 4, 4, 1, 1, 2928), - (1600, 32, 4, 1, 4, 4, 4, 900, 13), - (10, 16, 2, 12, 1, 3, 1, 1, 185), + (1600, 32, 4, 2, 4, 4, 1, 1, 2918), + (1600, 32, 4, 1, 4, 4, 4, 900, 12), + (10, 16, 2, 12, 1, 3, 1, 1, 181), (10, 16, 2, 10, 3, 3, 4, 60, 13), - (1600, 32, 4, 12, 3, 18, 1, 1, 13196), - (1600, 32, 4, 12, 1, 18, 4, 900, 58), + (1600, 32, 4, 12, 3, 18, 1, 1, 13150), + (1600, 32, 4, 12, 1, 18, 4, 900, 57), ], ) def test_netdata_disk_space_approximation(