Skip to content

Commit

Permalink
Revert "Only retrieve aggregated CPU temperature" (#15444)
Browse files Browse the repository at this point in the history
This reverts commit 40b903e.
  • Loading branch information
Qubad786 authored Jan 21, 2025
1 parent 702a237 commit 4057b3e
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 26 deletions.
25 changes: 14 additions & 11 deletions src/freenas/usr/lib/netdata/python.d/cputemp.chart.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
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
from middlewared.utils.cpu import amd_cpu_temperatures, generic_cpu_temperatures, cpu_info


CPU_TEMPERATURE_FEAT_TYPE = 2


ORDER = [
'temp',
'temperatures',
]

# This is a prototype of chart definition which is used to dynamically create self.definitions
CHARTS = {
'temp': {
'temperatures': {
'options': [None, 'Temperature', 'Celsius', 'temperature', 'sensors.temperature', 'line'],
'lines': [['cpu_temp', 'cpu_temp', 'absolute']]
'lines': []
}
}

Expand Down Expand Up @@ -76,11 +75,11 @@ def get_data(self):
self.error(error)
cpu_temps = {}

core_temp = []
for temp in cpu_temps.values():
core_temp.append(temp)
data = {}
for core, temp in cpu_temps.items():
data[str(core)] = temp

return {'cpu_temp': sum(core_temp) / len(core_temp)} if len(core_temp) else {'cpu_temp': 0}
return data or {str(i): 0 for i in range(cpu_info()['core_count'])}

def check(self):
try:
Expand All @@ -89,4 +88,8 @@ def check(self):
self.error(error)
return False

return True
data = self.get_data()
for i in data:
self.definitions['temperatures']['lines'].append([str(i)])

return bool(data)
5 changes: 1 addition & 4 deletions src/middlewared/middlewared/plugins/reporting/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
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):
Expand Down Expand Up @@ -106,9 +105,7 @@ def run_sync(self):
}

# CPU temperature
data['cpu']['temperature_celsius'] = safely_retrieve_dimension(
netdata_metrics, 'cputemp.temp', 'cpu_temp',
) or None
data['cpu']['temperature_celsius'] = self.middleware.call_sync('reporting.cpu_temperatures') or None

self.send_event('ADDED', fields=data)
time.sleep(interval)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.temp'
return 'cputemp.temperatures'


class MemoryPlugin(GraphBase):
Expand Down
2 changes: 1 addition & 1 deletion src/middlewared/middlewared/plugins/reporting/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def get_metrics_approximation(
'cpu.usage': core_count + 1,

# cputemp
'cputemp.temp': 1,
'cputemp.temperatures': core_count,

# ups
'nut_ups.charge': 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: 707, 60: 4}),
(1600, 32, 4, 10, 1, {1: 8732, 60: 1600}),
(10, 16, 2, 12, 3, {1: 832, 60: 10}),
(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}),
])
def test_netdata_metrics_count_approximation(
disk_count, core_count, interface_count, services_count, vms_count, expected_output
Expand All @@ -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, 407),
(4, 2, 1, 10, 2, 7, 1, 1, 408),
(4, 2, 1, 10, 1, 7, 4, 60, 25),
(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),
(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),
(10, 16, 2, 10, 3, 3, 4, 60, 13),
(1600, 32, 4, 12, 3, 18, 1, 1, 13150),
(1600, 32, 4, 12, 1, 18, 4, 900, 57),
(1600, 32, 4, 12, 3, 18, 1, 1, 13196),
(1600, 32, 4, 12, 1, 18, 4, 900, 58),
],
)
def test_netdata_disk_space_approximation(
Expand Down

0 comments on commit 4057b3e

Please sign in to comment.