system: switch to temperature sensor caching #7730

The hardest part is figuring out the best metric to collect
sensor points.  Luckily "IK" type sysctl values are temperature
readings so we use those with a day of caching in configd to
find the values for the dashboard without skimming all sysctl
output all the time.

Remove supoptimal backend call since no longer used.  The script
temperature.sh is also unused now.  Good-bye.
This commit is contained in:
Franco Fichtner 2024-08-12 23:00:45 +02:00
parent a6337fff16
commit eded37411f
4 changed files with 24 additions and 51 deletions

1
plist
View File

@ -1268,7 +1268,6 @@
/usr/local/opnsense/scripts/system/status.php
/usr/local/opnsense/scripts/system/swapinfo.py
/usr/local/opnsense/scripts/system/sysctl.py
/usr/local/opnsense/scripts/system/temperature.sh
/usr/local/opnsense/scripts/system/tls_groups.py
/usr/local/opnsense/scripts/system/trigger_config_changed_events.py
/usr/local/opnsense/scripts/system/update-crl-fetch.py

View File

@ -226,19 +226,29 @@ class SystemController extends ApiControllerBase
public function systemTemperatureAction()
{
$backend = new Backend();
$result = [];
foreach (explode("\n", (new Backend())->configdRun('system temp')) as $temp) {
$parts = explode('=', $temp);
if (count($parts) >= 2) {
$tempItem = array();
$tempItem['device'] = $parts[0];
$tempItem['device_seq'] = filter_var($tempItem['device'], FILTER_SANITIZE_NUMBER_INT);
$tempItem['temperature'] = trim(str_replace('C', '', $parts[1]));
$tempItem['type'] = strpos($tempItem['device'], 'hw.acpi') !== false ? 'zone' : 'cpu';
$tempItem['type_translated'] = $tempItem['type'] == 'zone' ? gettext('Zone') : gettext('CPU');
$result[] = $tempItem;
/* read temperatures individually from previously derived sensors */
$sensors = explode("\n", $backend->configdRun('system sensors'));
$temps = json_decode($backend->configdpRun('system sysctl values', join(',', $sensors)), true);
foreach ($temps as $name => $value) {
$tempItem = [];
$tempItem['device'] = $name;
$tempItem['device_seq'] = filter_var($tempItem['device'], FILTER_SANITIZE_NUMBER_INT); /* XXX too opportunistic */
$tempItem['temperature'] = trim(str_replace('C', '', $value));
$tempItem['type_translated'] = gettext('CPU');
$tempItem['type'] = 'cpu';
if (strpos($tempItem['device'], 'hw.acpi') !== false) {
$tempItem['type_translated'] = gettext('Zone');
$tempItem['type'] = 'zone';
/* XXX may or may not be a good idea */
} elseif (strpos($tempItem['device'], 'dev.amdtemp') !== false) {
$tempItem['type_translated'] = gettext('AMD');
$tempItem['type'] = 'amd';
}
$result[] = $tempItem;
}
return $result;

View File

@ -1,37 +0,0 @@
#!/bin/sh
# Copyright (C) 2020 Franco Fichtner <franco@opnsense.org>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
# AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
# OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
# The grep is opportunistic and leads some people to believe
# their CPU runs hotter than it should. It's always been this
# way and it should be changed, but so far all simple ideas fail
# to address the fact that we don't know which temperature to
# read until we have asked the kernel. Caching this and unifying
# with RRD collection is a worthwile goal. No hackery in the
# meantime to avoid adding something we cannot get rid of later.
SYSCTLS=$(sysctl -aN | grep temperature)
if [ -n "${SYSCTLS}" ]; then
sysctl -e ${SYSCTLS} | sort
fi

View File

@ -96,11 +96,12 @@ parameters:
type:script
message:Halt system
[temp]
command:/usr/local/opnsense/scripts/system/temperature.sh
[sensors]
command:sysctl -aF | awk -F ": " '$2 ~ "^IK" { print $1 }' | grep -v "\._" | sort
parameters:
type:script_output
message:Reading system temperature values
message:Probing system temperature sensor location
cache_ttl:86400
[ha_reconfigure_backup]
command:/usr/local/bin/flock -n -E 0 -o /tmp/ha_reconfigure_backup.lock /usr/local/etc/rc.filter_synchronize pre_check_master restart_services