function disk_list() { $partitions = array(); // Fetch partition information from df command // I would have used disk_free_space() and disk_total_space() here but // there appears to be no way to get a list of partitions in PHP? $output = array(); exec('/bin/df --block-size=1', $output, $return_var); if ($return_var) { return FALSE; } foreach ($output as $line) { $columns = get_columns($line); // Only process 6 column rows // (This has the bonus of ignoring the first row which is 7) if (count($columns) == 6) { $partition = $columns[5]; $partitions[$partition]['Temporary']['bool'] = in_array($columns[0], array('tmpfs', 'devtmpfs')); $partitions[$partition]['Partition']['text'] = $partition; $partitions[$partition]['FileSystem']['text'] = $columns[0]; if (is_numeric($columns[1]) && is_numeric($columns[2]) && is_numeric($columns[3])) { // Reset the power unit so it is recalculated based on the size unset($power); $partitions[$partition]['Size']['value'] = $columns[1]; $partitions[$partition]['Size']['text'] = si_unit($columns[1], $power, 1024, 1) . 'B'; $partitions[$partition]['Free']['value'] = $columns[3]; $partitions[$partition]['Free']['text'] = si_unit($columns[3], $power, 1024, 1) . 'B'; $partitions[$partition]['Used']['value'] = $columns[2]; $partitions[$partition]['Used']['text'] = si_unit($columns[2], $power, 1024, 1) . 'B'; $partitions[$partition]['Used']['min'] = 0; $partitions[$partition]['Used']['max'] = $columns[1]; $partitions[$partition]['Used']['positive'] = FALSE; } else { // Fallback if we don't get numerical values $partitions[$partition]['Size']['text'] = $columns[1]; $partitions[$partition]['Used']['text'] = $columns[2]; $partitions[$partition]['Free']['text'] = $columns[3]; } } } return $partitions; }
<?php if ($temperature != '') { ?> Temperature <?php echo str_pad($temperature . '\'C', 7, ' ', STR_PAD_RIGHT); ?> <?php echo graph_horizontal_bar($temperature, CPU_TEMP_MIN, CPU_TEMP_MAX, FALSE); ?> <?php } if ($speed != '') { ?> Speed <?php echo str_pad(si_unit($speed, $na, 1000, 0) . 'Hz', 7, ' ', STR_PAD_RIGHT); ?> <?php echo graph_horizontal_bar($speed, CPU_SPEED_MIN, CPU_SPEED_MAX, FALSE); ?> <?php } if ($voltage != '') { ?> Voltage <?php echo str_pad($voltage . 'V', 7, ' ', STR_PAD_RIGHT); ?> <?php echo graph_horizontal_bar($voltage, $voltage < CPU_VOLT_MIN ? $voltage : CPU_VOLT_MIN, CPU_VOLT_MAX, FALSE); ?>
<sup>o</sup>C</td> <td class="code"><?php echo graph_horizontal_bar($temperature, CPU_TEMP_MIN, CPU_TEMP_MAX, FALSE, TRUE, 'cpu_temp'); ?> </td> </tr> <?php } ?> <?php if ($speed != '') { ?> <tr> <th>Speed</th> <td id="cpu_speed_num"><?php echo h(si_unit($speed, $na, 1000, 0)); ?> Hz</td> <td class="code"><?php echo graph_horizontal_bar($speed, CPU_SPEED_MIN, CPU_SPEED_MAX, FALSE, TRUE, 'cpu_speed'); ?> </td> </tr> <?php } ?> <?php if ($voltage != '') { ?> <tr> <th>Voltage</th>
function memory_list() { // Fixed memory amounts $memory_cpu = memory_cpu(); $memory_gpu = memory_gpu(); $locations = array(); // Fetch location information from free command // Should probably rewrite this to cat /proc/meminfo $output = array(); exec('/usr/bin/free --bytes --old', $output, $return_var); if ($return_var) { return FALSE; } foreach ($output as $line) { $columns = get_columns($line); // Only process 4 or more column rows // Ignore row with column titles if (count($columns) >= 4 && $columns[0] != 'total') { $location = rtrim($columns[0], ':'); // Tidyup abbreviations used in free command if ($location == 'Mem') { $location = 'RAM'; $tr = $columns[1]; $ur = $columns[2]; $fr = $columns[3]; } if (is_numeric($columns[1]) && is_numeric($columns[2]) && is_numeric($columns[3])) { // Reset the power unit so it is recalculated based on the size unset($power); // Include onboard GPU memory if ($memory_cpu && $memory_gpu && $location == 'RAM') { $reserved = $memory_cpu - $columns[1]; $used = $columns[2] + $memory_gpu + $reserved; // RAM (Total) $locations[$location]['Virtual']['bool'] = !($location == 'RAM'); $locations[$location]['Type']['text'] = $location; $locations[$location]['Size']['value'] = $memory_cpu + $memory_gpu; $locations[$location]['Size']['text'] = si_unit($memory_cpu + $memory_gpu, $power, 1024, 1) . 'B'; $locations[$location]['Free']['value'] = $columns[3]; $locations[$location]['Free']['text'] = si_unit($columns[3], $power, 1024, 1) . 'B'; $locations[$location]['Used']['value'] = $used; $locations[$location]['Used']['text'] = si_unit($used, $power, 1024, 1) . 'B'; $locations[$location]['Used']['min'] = 0; $locations[$location]['Used']['max'] = $memory_cpu + $memory_gpu; $locations[$location]['Used']['positive'] = FALSE; $locations[$location]['Used']['absolute'] = TRUE; // RAM (GPU) $locations[$location . ' (GPU)']['Virtual']['bool'] = !($location == 'RAM'); $locations[$location . ' (GPU)']['Type']['text'] = $location . ' (GPU)'; $locations[$location . ' (GPU)']['Used']['value'] = $memory_gpu; $locations[$location . ' (GPU)']['Used']['text'] = si_unit($memory_gpu, $power, 1024, 1) . 'B'; $locations[$location . ' (GPU)']['Used']['min'] = 0; $locations[$location . ' (GPU)']['Used']['max'] = $columns[3] + $memory_gpu; $locations[$location . ' (GPU)']['Used']['positive'] = FALSE; $locations[$location . ' (GPU)']['Used']['absolute'] = FALSE; // RAM (Reserved) $locations[$location . ' (Reserved)']['Virtual']['bool'] = !($location == 'RAM'); $locations[$location . ' (Reserved)']['Type']['text'] = $location . ' (Reserved)'; $locations[$location . ' (Reserved)']['Used']['value'] = $reserved; $locations[$location . ' (Reserved)']['Used']['text'] = si_unit($reserved, $power, 1024, 1) . 'B'; $locations[$location . ' (Reserved)']['Used']['min'] = 0; $locations[$location . ' (Reserved)']['Used']['max'] = $columns[3] + $reserved; $locations[$location . ' (Reserved)']['Used']['positive'] = FALSE; $locations[$location . ' (Reserved)']['Used']['absolute'] = FALSE; } else { $locations[$location]['Virtual']['bool'] = !($location == 'RAM'); $locations[$location]['Type']['text'] = $location; $locations[$location]['Size']['value'] = $columns[1]; $locations[$location]['Size']['text'] = si_unit($columns[1], $power, 1024, 1) . 'B'; $locations[$location]['Free']['value'] = $columns[3]; $locations[$location]['Free']['text'] = si_unit($columns[3], $power, 1024, 1) . 'B'; $locations[$location]['Used']['value'] = $columns[2]; $locations[$location]['Used']['text'] = si_unit($columns[2], $power, 1024, 1) . 'B'; $locations[$location]['Used']['min'] = 0; $locations[$location]['Used']['max'] = $columns[1]; $locations[$location]['Used']['positive'] = FALSE; $locations[$location]['Used']['absolute'] = TRUE; } // If we know the buffers and the cache we can calculate the app if (isset($columns[5]) && is_numeric($columns[5]) && is_numeric($columns[6]) && is_numeric($columns[6])) { $apps = $columns[1] - $columns[3] - $columns[5] - $columns[6]; $locations[$location . ' (Apps)']['Virtual']['bool'] = !($location == 'RAM'); $locations[$location . ' (Apps)']['Type']['text'] = $location . ' (Apps)'; $locations[$location . ' (Apps)']['Used']['value'] = $apps; $locations[$location . ' (Apps)']['Used']['text'] = si_unit($apps, $power, 1024, 1) . 'B'; $locations[$location . ' (Apps)']['Used']['min'] = 0; $locations[$location . ' (Apps)']['Used']['max'] = $columns[3] + $apps; $locations[$location . ' (Apps)']['Used']['positive'] = FALSE; $locations[$location . ' (Apps)']['Used']['absolute'] = FALSE; } // Buffer calulations if (isset($columns[5]) && is_numeric($columns[5])) { $locations[$location . ' (Buffers)']['Virtual']['bool'] = !($location == 'RAM'); $locations[$location . ' (Buffers)']['Type']['text'] = $location . ' (Buffers)'; $locations[$location . ' (Buffers)']['Used']['value'] = $columns[5]; $locations[$location . ' (Buffers)']['Used']['text'] = si_unit($columns[5], $power, 1024, 1) . 'B'; $locations[$location . ' (Buffers)']['Used']['min'] = 0; $locations[$location . ' (Buffers)']['Used']['max'] = $columns[3] + $columns[5]; $locations[$location . ' (Buffers)']['Used']['positive'] = FALSE; $locations[$location . ' (Buffers)']['Used']['absolute'] = FALSE; } elseif (isset($columns[5])) { $locations[$location . ' (Cache)']['Used']['text'] = $columns[5]; } // Cache calulations if (isset($columns[6]) && is_numeric($columns[6])) { $locations[$location . ' (Cache)']['Virtual']['bool'] = !($location == 'RAM'); $locations[$location . ' (Cache)']['Type']['text'] = $location . ' (Cache)'; $locations[$location . ' (Cache)']['Used']['value'] = $columns[6]; $locations[$location . ' (Cache)']['Used']['text'] = si_unit($columns[6], $power, 1024, 1) . 'B'; $locations[$location . ' (Cache)']['Used']['min'] = 0; $locations[$location . ' (Cache)']['Used']['max'] = $columns[3] + $columns[6]; $locations[$location . ' (Cache)']['Used']['positive'] = FALSE; $locations[$location . ' (Cache)']['Used']['absolute'] = FALSE; } elseif (isset($columns[6])) { $locations[$location . ' (Cache)']['Used']['text'] = $columns[6]; } } else { // Fallback if we don't get numerical values $locations[$location]['Virtual']['bool'] = !($location == 'RAM'); $locations[$location]['Type']['text'] = $location; $locations[$location]['Size']['text'] = $columns[1]; $locations[$location]['Used']['text'] = $columns[2]; $locations[$location]['Free']['text'] = $columns[3]; } } } return $locations; }