From d20c22fb9623e5ed79b00f6198ccac26492c9d84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrea=20Denisse=20G=C3=B3mez-Mart=C3=ADnez?= Date: Thu, 16 May 2024 12:59:07 -0600 Subject: [PATCH] librenms: Replace deprecated OID 'ssCpuIdle' with 'ssCpuRawIdle' The 'ssCpuIdle' OID has been deprecated in favor of 'ssCpuRawIdle', which provides more accurate CPU usage metrics over any desired time period. This commit updates the OID used in LibreNMS from 'ssCpuIdle' to 'ssCpuRawIdle' in FsSwitch.php to ensure more reliable CPU usage monitoring. Changes: - Replaced 'ssCpuIdle' with 'ssCpuRawIdle' in the SNMP walk. - Updated the CPU usage calculation to use 'ssCpuRawIdle'. Bug: T285229 Change-Id: I63120ccc03b597d5b9623a77a0f9e6ebd7b6cf3e --- LibreNMS/OS/FsSwitch.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/LibreNMS/OS/FsSwitch.php b/LibreNMS/OS/FsSwitch.php index 77a539ff21..b3c1d8e09d 100644 --- a/LibreNMS/OS/FsSwitch.php +++ b/LibreNMS/OS/FsSwitch.php @@ -41,10 +41,21 @@ public function discoverProcessors() { $processors = []; + // Get the number of CPUs + $num_cpus_data = snmpwalk_cache_oid($this->getDeviceArray(), 'ssCpuNumCpus', [], 'UCD-SNMP-MIB'); + $num_cpus = isset($num_cpus_data[0]['ssCpuNumCpus']) ? $num_cpus_data[0]['ssCpuNumCpus'] : 1; + + // Assuming a tick rate of 100 ticks per second + $ticks_per_second = 100; + // Tests OID from SWITCH MIB. - $processors_data = snmpwalk_cache_oid($this->getDeviceArray(), 'ssCpuIdle', [], 'SWITCH', 'fs'); + $processors_data = snmpwalk_cache_oid($this->getDeviceArray(), 'ssCpuRawIdle', [], 'SWITCH', 'fs'); foreach ($processors_data as $index => $entry) { + // Calculate total ticks for all CPUs + $total_ticks = $num_cpus * $ticks_per_second; + $idle_percentage = ($entry['ssCpuRawIdle'] / $total_ticks) * 100; + $processors[] = Processor::discover( 'fs-SWITCHMIB', $this->getDeviceId(), @@ -52,7 +63,7 @@ public function discoverProcessors() $index, 'CPU', -1, - 100 - $entry['ssCpuIdle'] + 100 - $idle_percentage ); }