Beispiel #1
0
    case xeon:
    case git:
        sensors();
        memory();
        process();
        break;
    case micro:
    case raspi:
        memory();
        process();
        break;
    case serverRoom:
        serverRoom();
        break;
    case serverRoomPower:
        serverRoomPower();
        break;
}
$db->close();
function sensors()
{
    global $db, $date, $json;
    $core0 = $json["sensors"]["core0"];
    $core1 = $json["sensors"]["core1"];
    $core2 = $json["sensors"]["core2"];
    $core3 = $json["sensors"]["core3"];
    $db->exec("create table if not exists sensors(date, core0, core1, core2, core3)");
    $db->exec("insert into sensors values('{$date}', {$core0}, {$core1}, {$core2}, {$core3})");
}
function memory()
{
Beispiel #2
0
    case xeon:
        $jsonArr = array("name" => $name, "sensors" => sensors(3, 6), "memory" => memory(3, 4), "process" => process());
        break;
    case git:
        $jsonArr = array("name" => $name, "sensors" => sensors(3, 6), "memory" => memory(2, 3), "process" => process());
        break;
    case micro:
    case raspi:
        $jsonArr = array("name" => $name, "memory" => memory(3, 4), "process" => process());
        break;
    case serverRoom:
        $result = serverRoom();
        $jsonArr = array("name" => $name, "temp" => $result[0], "hum" => $result[1], "pres" => $result[2]);
        break;
    case serverRoomPower:
        $jsonArr = array("name" => $name, "status" => serverRoomPower());
        break;
    default:
        die;
}
$json = json_encode($jsonArr);
$options = array('http' => array('method' => 'POST', 'content' => http_build_query(array($json))));
file_get_contents($url, false, stream_context_create($options));
function sensors($start, $end)
{
    $sensors = command("sensors | awk 'NR=={$start},NR=={$end} {print \$3}'");
    $core0 = preg_replace("/\\.0|\\+|°C/", "", $sensors[0]);
    $core1 = preg_replace("/\\.0|\\+|°C/", "", $sensors[1]);
    $core2 = preg_replace("/\\.0|\\+|°C/", "", $sensors[2]);
    $core3 = preg_replace("/\\.0|\\+|°C/", "", $sensors[3]);
    return array("core0" => $core0, "core1" => $core1, "core2" => $core2, "core3" => $core3);