Skip to content
Snippets Groups Projects
Commit 84557f8d authored by Thibault Debatty's avatar Thibault Debatty
Browse files

use dmidecode info to extract CPU name, which supports freebsd/opnsense

parent 9a0bf9a4
No related branches found
No related tags found
No related merge requests found
Pipeline #18535 failed
......@@ -16,26 +16,9 @@ class ServerInfoCPU extends ServerInfoParser
{
// count the number of vCores
$REGEX = "/^processor : (.+)$/m";
$result["threads"] = preg_match_all($REGEX, $string);
$result["name"] = "undefined";
// try to extract the CPU model
$REGEX = "/^model name : (.+)$/m";
$matches = array();
if (preg_match($REGEX, $string, $matches) === 1) {
$result["name"] = $matches[1];
$info->cpuinfo = $result;
return;
}
// for raspberry pi
$REGEX = '/^Model\s*: (.+)$/m';
$matches = array();
if (preg_match($REGEX, $string, $matches) === 1) {
$result["name"] = $matches[1];
$info->cpuinfo = $result;
return;
}
$cpuinfo = $info->cpuinfo;
$cpuinfo["threads"] = preg_match_all($REGEX, $string);
$info->cpuinfo = $cpuinfo;
}
public function config(): SensorConfig
......
<?php
namespace App\Sensor;
use App\SensorConfig;
use App\ServerInfo;
/**
* Uses DMI info to extract CPU name.
*
* @author tibo
*/
class ServerInfoCPUName extends ServerInfoParser
{
public function analyzeString(string $string, ServerInfo $info)
{
$cpuinfo = $info->cpuinfo;
$REGEX = "/\tVersion: (.*)/m";
$matches = [];
if (preg_match($REGEX, $string, $matches) === 1) {
$cpuinfo["name"] = $matches[1];
}
$info->cpuinfo = $cpuinfo;
}
public function config(): SensorConfig
{
return new SensorConfig("cpu-name", "cpu-dmi");
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment