Handle when no swap is configured

This commit is contained in:
Isaac Connor 2022-02-08 10:04:19 -05:00
parent fe01af6966
commit 2f5a403fc4
1 changed files with 14 additions and 12 deletions

View File

@ -472,6 +472,10 @@ function getRamHTML() {
} else if ($mem_used_percent > 90) {
$used_class = 'text-warning';
}
$result .= ' <li id="getRamHTML" class="nav-item dropdown mx-2">'.
'<span class="'.$used_class.'" title="' .human_filesize($mem_used). ' of ' .human_filesize($meminfo['MemTotal']). '">'.translate('Memory').': '.$mem_used_percent.'%</span> ';
if ($meminfo['SwapTotal']) {
$swap_used = $meminfo['SwapTotal'] - $meminfo['SwapFree'];
$swap_used_percent = (int)(100*$swap_used/$meminfo['SwapTotal']);
$swap_class = '';
@ -480,11 +484,9 @@ function getRamHTML() {
} else if ($swap_used_percent > 90) {
$swap_class = 'text-warning';
}
$result .= ' <li id="getRamHTML" class="nav-item dropdown mx-2">'.
'<span class="'.$used_class.'" title="' .human_filesize($mem_used). ' of ' .human_filesize($meminfo['MemTotal']). '">'.translate('Memory').': '.$mem_used_percent.'%</span> '.
'<span class="'.$swap_class.'" title="' .human_filesize($swap_used). ' of ' .human_filesize($meminfo['SwapTotal']). '">'.translate('Swap').': '.$swap_used_percent.'%</span> '.
'</li>'.PHP_EOL;
$result .= '<span class="'.$swap_class.'" title="' .human_filesize($swap_used). ' of ' .human_filesize($meminfo['SwapTotal']). '">'.translate('Swap').': '.$swap_used_percent.'%</span> ';
} # end if SwapTotal
$result .= '</li>'.PHP_EOL;
return $result;
}