Skip to content

Commit

Permalink
Only retrieve aggregated CPU temperature (#15364)
Browse files Browse the repository at this point in the history
  • Loading branch information
Qubad786 authored Jan 10, 2025
1 parent 7f37a6a commit 725e4bf
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 26 deletions.
25 changes: 11 additions & 14 deletions src/freenas/usr/lib/netdata/python.d/cputemp.chart.py
Original file line number Diff line number Diff line change
@@ -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']]
}
}

Expand Down Expand Up @@ -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:
Expand All @@ -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
5 changes: 4 additions & 1 deletion src/middlewared/middlewared/plugins/reporting/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)
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.temperatures'
return 'cputemp.temp'


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.temperatures': core_count,
'cputemp.temp': 1,

# 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: 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
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, 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(
Expand Down

0 comments on commit 725e4bf

Please sign in to comment.