Files

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

93 lines
2.6 KiB
PHP
Raw Permalink Normal View History

2018-02-05 07:39:13 -06:00
<?php
/**
* VxworksProcessorUsage.php
*
* Several devices use the janky output of this oid
* Requires both ProcessorDiscovery and ProcessorPolling
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
2021-02-09 00:29:04 +01:00
* along with this program. If not, see <https://www.gnu.org/licenses/>.
2018-02-05 07:39:13 -06:00
*
2021-02-09 00:29:04 +01:00
* @link https://www.librenms.org
2021-09-10 20:09:53 +02:00
*
2018-02-05 07:39:13 -06:00
* @copyright 2018 Tony Murray
* @author Tony Murray <murraytony@gmail.com>
*/
namespace LibreNMS\OS\Traits;
use LibreNMS\Device\Processor;
trait VxworksProcessorUsage
{
/**
* Discover processors.
* Returns an array of LibreNMS\Device\Processor objects that have been discovered
*
2021-09-08 23:35:56 +02:00
* @param string $oid Custom OID to fetch from
2018-02-05 07:39:13 -06:00
* @return array Processors
*/
public function discoverProcessors($oid = '.1.3.6.1.4.1.4413.1.1.1.1.4.9.0')
{
2020-09-18 08:12:07 -05:00
$usage = $this->parseCpuUsage(snmp_get($this->getDeviceArray(), $oid, '-Ovq'));
2018-02-05 07:39:13 -06:00
if (is_numeric($usage)) {
return [
Processor::discover(
$this->getName(),
$this->getDeviceId(),
$oid,
0,
'Processor',
1,
$usage
),
];
}
return [];
}
/**
* Poll processor data. This can be implemented if custom polling is needed.
*
2021-09-08 23:35:56 +02:00
* @param array $processors Array of processor entries from the database that need to be polled
2018-02-05 07:39:13 -06:00
* @return array of polled data
*/
public function pollProcessors(array $processors)
{
$data = [];
foreach ($processors as $processor) {
$data[$processor['processor_id']] = $this->parseCpuUsage(
2020-09-18 08:12:07 -05:00
snmp_get($this->getDeviceArray(), $processor['processor_oid'])
2018-02-05 07:39:13 -06:00
);
}
return $data;
}
/**
* Parse the silly cpu usage string
* " 5 Secs ( 96.4918%) 60 Secs ( 54.2271%) 300 Secs ( 38.2591%)"
*
2021-09-08 23:35:56 +02:00
* @param string $data
2018-02-05 07:39:13 -06:00
* @return mixed
*/
private function parseCpuUsage($data)
{
preg_match('/([0-9]+.[0-9]+)%/', $data, $matches);
2020-09-21 14:54:51 +02:00
2018-02-05 07:39:13 -06:00
return $matches[1];
}
}