array( // Service name => port 'http' => 80, 'https' => 443, 'ssh' => 22, 'mpd' => 6600, 'ftp' => 21, 'nfs' => 2049, 'samba' => 139, // array of ports only available on localhost 'local_ports' => array(6600, 21, 2049, 139), ), 'alinea.kd2.org' => array( 'dns' => 53, 'http' => 80, 'https' => 443, 'ssh' => 22, 'ftp' => 21, 'icecast'=> 8000, 'local_ports' => array(8000, 21), ), 'barmizo.kd2.org' => array( 'dns' => 53, 'http' => 80, 'https' => 443, 'ssh' => 22, 'ftp' => 21, 'icecast'=> 8000, 'telnet' => 23, 'pop3' => 110, 'smtp' => 25, 'imap' => 143, 'pop3s' => 995, 'imaps' => 993, 'ssh2' => 24, 'mysql' => 3306, // Don't overload your servers: show only vital ports from other servers 'local_ports' => array(21, 24, 23, 25, 110, 143, 8000, 995, 993, 3306), ), 'montagne.kd2.org' => array( 'http' => 80, 'https' => 443, 'ssh' => 22, 'mpd' => 6600, 'dns' => 53, 'nfs' => 2049, 'samba' => 139, 'bitlbee' => 6667, 'smtp' => 25, 'mysql' => 3306, 'local_ports' => array(6600, 53, 2049, 139, 6667, 25, 3306), ), ); /* HTML things */ $images = array( 'fond' => 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAABACAMAAAAULxaFAAAAwFBMVEUAAwAFBwMJDAgOEA0TFBIWGBUaGxkeHx0iIyEmJyUqKyktLywxMzE2ODU5Ozg+Pz1BQ0BGR0VJS0lOUE1SVFFXWFZbXFpeYF1iY2FlZ2Rpa2htb2xydHF2eHV6fHl+gH2ChIGGiIWKjImNj4yRk5CVl5Sam5ieoJyipKGmqKWpq6itr6yytLG2uLW5u7i9v7zCxMDGyMXJy8jO0MzS1NHV19Ta3Nje4N3h5ODm6OXp6+ju8Ozx8/D2+PT5+/j+//z2MjBvAAAAAWJLR0QAiAUdSAAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9YLCAA7IL0Lg5wAAACISURBVCjPRcTFVkIBAADR4T26JASUlkZapOv//4rDZriLy0Pc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PYyAMwAMO9MBqI+Cz0ZiHYtSMhen/0F8wUu+xvAgIUKgFaMJ9vSvfEjWqDXKe4gDmCU8GUgmuIzUx6IZC8FcJ1mRgVs7ahQTNy5CMVYb3X5m/IhL6sdNEifV4DFgxPyghUBUEhyV4sbIAwlUPf+h4iCzeWvHsTBhOilAHy5YxUlWR7JZATpA0oyTEaQLQYw6dOAp5/7AbZDcYvf8gfn5eYS8HOoWukv+Lvh6YUNvsWPt9jrSiSjwSU/xZHJSPTid2Cugs/wvqIUAI6/oNxEbPbnRek7AO6dCVzLZZKklXKdRp8FkCbJdrlQHLLuo1GRfgZAAQC6OISn45kncKySzWzLPgOAPTqzIytNtpNJ9DkAh4Yf0Sze8SuvD/01HX3H75tOvyc8AZwATgAngC8H+B+Wuhtf8+hcqAAAAABJRU5ErkJggg==', ); function get_img($name) { global $images; return $images[$name]; } function kb2mb($int) { return round($int/1024); } function tpl_top($title) { global $monitor; echo ' '.htmlspecialchars($title).'

System status

'; } function tpl_end() { echo '
'; } /* Test functions */ function is_port_local_only($host, $port) { if($host == 'localhost') return false; global $monitor; if(empty($monitor[$host]['local_ports'])) return false; if(in_array($port, $monitor[$host]['local_ports'])) return true; return false; } function status_test_port($host, $port) { if(is_port_local_only($host, $port)) return 'Local port only'; // Only 2 secs, will detect lags on your internet connexion $fp = @fsockopen($host, $port, $errno, $errstr, 2); if($fp) { @fclose($fp); return 'OK'; } else { @fclose($fp); return "$errno - $errstr"; } } function status_get_load() { $load = @file('/proc/loadavg'); if(!$load) { return false; } $load = ereg_replace('^(([0-9.]+ ){3}).*$', '\\1', $load[0]); return $load; } function status_get_mem_usage() { $mem = @file('/proc/meminfo'); if(!$mem) { return false; } $out = array(); foreach($mem as $line) { $line = explode(':', $line); $name = trim($line[0]); $value = ereg_replace('[^0-9]', '', trim($line[1])); switch($name) { case 'MemTotal': $out['total'] = $value; break; case 'MemFree': $out['free'] = $value; break; case 'Buffers': $out['buffers'] = $value; break; case 'Cached': $out['cached'] = $value; break; case 'SwapCached': $out['swap'] = $value; break; default: break; } } $out['free_real'] = $out['free'] + $out['buffers'] + $out['cached']; $out['percent'] = 100 - round(($out['free_real'] / $out['total']) * 100); return $out; } function status_test_host($host, $services) { $out = ''; foreach($services as $service => $port) { if(!is_numeric($port)) continue; if(is_port_local_only($host, $port)) continue; $result = status_test_port($host, $port); $out.= ''; } $out.= '
'.htmlspecialchars($service).' '.($result == 'OK' ? 'OK' : 'Failed! Error: '.$result).'
'; return $out; } /* App general things */ tpl_top($myhost); echo '
Load:
'.(($load = status_get_load()) ? $load : 'Unavailable.').'
Memory usage:
'; $mem = status_get_mem_usage(); if(!$mem) echo 'Unavailable.'; else { echo $mem['percent'].'% used ('.kb2mb($mem['total']).' Mb total, '.kb2mb($mem['free']).' Mb free and '. kb2mb($mem['buffers'] + $mem['cached']).' Mb buffers and cache), and '.kb2mb($mem['swap']).' Mb of swap used.'; } echo '
Services status for localhost
'.status_test_host('localhost', $monitor[$myhost]).'

Other servers status

'; flush(); foreach($monitor as $host => $services) { if($host == $myhost) continue; echo '
'.$host.'
'.status_test_host($host, $services).'
'; flush(); } echo '
http://kd2.org/
'; tpl_end(); ?>