-
-
Notifications
You must be signed in to change notification settings - Fork 558
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: RD WebDesign <github@rdwebdesign.com.br>
- Loading branch information
1 parent
ca8a35f
commit b7f131f
Showing
2 changed files
with
65 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
// Return memory usage to show on status block | ||
function getMemUsage() { | ||
$data = explode("\n", file_get_contents("/proc/meminfo")); | ||
$meminfo = array(); | ||
if (count($data) > 0) { | ||
foreach ($data as $line) { | ||
$expl = explode(":", $line); | ||
if (count($expl) == 2) { | ||
// remove " kB" from the end of the string and make it an integer | ||
$meminfo[$expl[0]] = intval(trim(substr($expl[1],0, -3))); | ||
} | ||
} | ||
$memused = $meminfo["MemTotal"] - $meminfo["MemFree"] - $meminfo["Buffers"] - $meminfo["Cached"]; | ||
$memusage = $memused / $meminfo["MemTotal"]; | ||
} else { | ||
$memusage = -1; | ||
} | ||
|
||
return $memusage; | ||
} | ||
|
||
// Try to get temperature value from different places (OS dependent) | ||
// - return an array, containing the temperature and limit. | ||
function getTemperature() { | ||
global $setupVars; | ||
|
||
if (file_exists("/sys/class/thermal/thermal_zone0/temp")) { | ||
$output = rtrim(file_get_contents("/sys/class/thermal/thermal_zone0/temp")); | ||
} elseif (file_exists("/sys/class/hwmon/hwmon0/temp1_input")) { | ||
$output = rtrim(file_get_contents("/sys/class/hwmon/hwmon0/temp1_input")); | ||
} else { | ||
$output = ""; | ||
} | ||
|
||
// Test if we succeeded in getting the temperature | ||
if (is_numeric($output)) { | ||
// $output could be either 4-5 digits or 2-3, and we only divide by 1000 if it's 4-5 | ||
// ex. 39007 vs 39 | ||
$celsius = intval($output); | ||
|
||
// If celsius is greater than 1 degree and is in the 4-5 digit format | ||
if ($celsius > 1000) { | ||
// Use multiplication to get around the division-by-zero error | ||
$celsius *= 1e-3; | ||
} | ||
|
||
// Get user-defined temperature limit if set | ||
if (isset($setupVars['TEMPERATURE_LIMIT'])) { | ||
$limit = intval($setupVars['TEMPERATURE_LIMIT']); | ||
} else { | ||
$limit = 60; | ||
} | ||
|
||
} else { | ||
// Nothing can be colder than -273.15 degree Celsius (= 0 Kelvin) | ||
// This is the minimum temperature possible (AKA absolute zero) | ||
$celsius = -273.16; | ||
// Set templimit to null if no tempsensor was found | ||
$limit = null; | ||
} | ||
|
||
return [$celsius, $limit]; | ||
} | ||
?> |