<?
Header("Content-type: image/png" );
exec('top -b -n 1', $test);
$cpu = $test[4];
$mem = $test[5];
$swap = $test[7];
/* UTILISATION CPU */
$cpu = substr($cpu, 11, strpos($cpu, '%')-11);
$img = imagecreate(200, 160);
$contour = imagecolorallocate($img, 0, 0, 0);
$vide = imagecolorallocate($img, 0, 150, 0);
$plein = imagecolorallocate($img, 200, 0, 0);
$blanc = imagecolorallocate($img, 255, 255, 255);
imagefill($img, 0, 0, $blanc);
imagefilledrectangle($img, 0, 20, 199, 39, $vide);
$remplissage = round(2*$cpu, 0);
imagefilledrectangle($img, 0, 20, $remplissage, 39, $plein);
imageline($img, 0, 20, 0, 39, $contour);
imageline($img, 0, 20, 199, 20, $contour);
imageline($img, 0, 39, 199, 39, $contour);
imageline($img, 199, 20, 199, 39, $contour);
imagettftext($img, 8, 0, 60, 18, $contour, './include/font/arial.ttf', 'Utilisation CPU :');
imagettftext($img, 6, 0, 80, 33, $blanc, './include/font/hooge.ttf', $cpu.' %');
/* UTILISATION RAM */
$mem_totale = substr($mem, 4, strpos($mem, 'k av')-4);
$mem_util = substr($mem, strpos($mem, 'av, ')+4, strpos($mem, 'k used')-(strpos($mem, 'av, ')+4));
imagefilledrectangle($img, 0, 60, 199, 79, $vide);
$remplissage = round(200*$mem_util/$mem_totale, 0);
imagefilledrectangle($img, 0, 60, $remplissage, 79, $plein);
imageline($img, 0, 60, 0, 79, $contour);
imageline($img, 0, 60, 199, 60, $contour);
imageline($img, 0, 79, 199, 79, $contour);
imageline($img, 199, 60, 199, 79, $contour);
imagettftext($img, 8, 0, 60, 58, $contour, './include/font/arial.ttf', 'Utilisation RAM :');
imagettftext($img, 6, 0, 90, 73, $blanc, './include/font/hooge.ttf', round(100*$mem_util/$mem_totale, 0).' %');
/* UTILISATION SWAP */
$swap_total = substr($swap, 5, strpos($swap, 'k av')-5);
$swap_util = substr($swap, strpos($swap, 'av, ')+5, strpos($swap, 'k used')-(strpos($swap, 'av, ')+5));
imagefilledrectangle($img, 0, 100, 199, 119, $vide);
$remplissage = round(200*$swap_util/$swap_total, 0);
imagefilledrectangle($img, 0, 100, $remplissage, 119, $plein);
imageline($img, 0, 100, 0, 119, $contour);
imageline($img, 0, 100, 199, 100, $contour);
imageline($img, 0, 119, 199, 119, $contour);
imageline($img, 199, 100, 199, 119, $contour);
imagettftext($img, 8, 0, 60, 98, $contour, './include/font/arial.ttf', 'Utilisation Swap :');
imagettftext($img, 6, 0, 90, 113, $blanc, './include/font/hooge.ttf', round(100*$swap_util/$swap_total, 0).' %');
/* UTILISATION DISQUE DUR */
$espace_libre = round((disk_free_space('/'))/1048576, 1);
$espace_total = round((disk_total_space('/'))/1048576, 1);
imagefilledrectangle($img, 0, 140, 199, 159, $vide);
$remplissage = 200*($espace_total-$espace_libre)/$espace_total;
imagefilledrectangle($img, 0, 140, $remplissage, 159, $plein);
imageline($img, 0, 140, 0, 159, $contour);
imageline($img, 0, 140, 199, 140, $contour);
imageline($img, 0, 159, 199, 159, $contour);
imageline($img, 199, 140, 199, 159, $contour);
imagettftext($img, 8, 0, 60, 138, $contour, './include/font/arial.ttf', 'Espace disque :');
imagettftext($img, 6, 0, 90, 153, $blanc, './include/font/hooge.ttf', round(100*($espace_total-$espace_libre)/$espace_total, 0).' %');
imagepng($img);
imagedestroy($img);
?> |