From c6bd005ed6110e2a823270945b0e846fb19201e2 Mon Sep 17 00:00:00 2001 From: Matt Lebofsky Date: Tue, 20 Sep 2005 22:48:35 +0000 Subject: [PATCH] *** empty log message *** svn path=/trunk/boinc/; revision=8121 --- checkin_notes | 16 +++ html/inc/util.inc | 26 +++- html/user/server_status.php | 230 ++++++++++++++++++++++++++++++++++++ 3 files changed, 267 insertions(+), 5 deletions(-) create mode 100644 html/user/server_status.php diff --git a/checkin_notes b/checkin_notes index 04c6a800c0..c27e6baee1 100755 --- a/checkin_notes +++ b/checkin_notes @@ -11902,6 +11902,22 @@ Charlie 19 Sept 2005 lib/ mac_backtrace.C, .h +Matt 20 Sept 2005 + - added new file server_status.php to html/user which is a generic server + status page, which can be run as a regular php page or as a standalone + program (which can output static .html as well as .xml). Instructions + for use are in the comments at the top. + - fixed the function parse_element so that it returns *all* the text + between open/close tags, not just the text between the opening tag + and the next "<" sign. + - made a new function parse_next_element which gives the user a cursor so + that they can iterate through multiple similar tags (like ). + + html/user/ + server_status.php + html/inc/ + util.inc + David 20 Sept 2005 - code cleanup diff --git a/html/inc/util.inc b/html/inc/util.inc index 20a238d550..9eb61b96c1 100644 --- a/html/inc/util.inc +++ b/html/inc/util.inc @@ -313,11 +313,12 @@ function print_login_form() { // function parse_element($xml, $tag) { $element = null; + $closetag = "")) return $tag; $y = substr($x, strlen($tag)); - $n = strpos($y, "<"); + $n = strpos($y, $closetag); if ($n) { $element = substr($y, 0, $n); } @@ -325,6 +326,23 @@ function parse_element($xml, $tag) { return $element; } +function parse_next_element($xml, $tag, $cursor) { + $element = null; + $closetag = "")) return $tag; + $y = substr($x, strlen($tag)); + $n = strpos($y, $closetag); + if ($n) { + $element = substr($y, 0, $n); + } + $cursor = (strlen($xml) - strlen($x)) + strlen($tag) + strlen($closetag) + strlen($element); + } + return $element; +} + if (!function_exists("file_get_contents")) { function file_get_contents($path) { $x = ""; @@ -423,10 +441,8 @@ function user_links($user) { if ($user->has_profile) { $x .= " id>"; } - // Does this project accept donations? - // If so, do you want to have a link next to user - // name as it appears on the web site? - // + # Does this project accept donations? + # If so, do you want to have a link next to user name as it appears on the web site? if ($user->donated == 1) { require_once("../project/donations.inc"); $x .= DONATION_LINK; diff --git a/html/user/server_status.php b/html/user/server_status.php new file mode 100644 index 0000000000..01eb6a6915 --- /dev/null +++ b/html/user/server_status.php @@ -0,0 +1,230 @@ +\n"); + fwrite($xmloutfile," $host\n"); + fwrite($xmloutfile," $function\n"); + } + echo "$function$host"; + if ($running == 1) { + echo "Running\n"; + if ($xmlout) { fwrite($xmloutfile," running\n"); } + } elseif ($running == 0) { + echo "Not Running\n"; + if ($xmlout) { fwrite($xmloutfile," not running\n"); } + } else { + echo "Disabled\n"; + if ($xmlout) { fwrite($xmloutfile," disabled\n"); } + } + echo ""; + if ($xmlout) { + fwrite($xmloutfile," \n"); + } +} + +function show_daemon_status($host, $pidname, $progname, $disabled) { + $running = daemon_status($host, $pidname, $progname, $disabled); + show_status($host, $pidname, $running); +} + +function show_counts($key, $xmlkey, $value) { + global $xmlout, $xmloutfile; + $formattedvalue = number_format($value); + echo "$key$formattedvalue"; + if ($xmlout) { + fwrite($xmloutfile," <$xmlkey>$value\n"); + } +} + +function get_mysql_count ($query) { + $result = mysql_query("select count(*) as count from " . $query); + $count = mysql_fetch_object($result); + mysql_free_result($result); + return $count->count; +} + +page_head("Server status page"); + +echo "

"; + +echo " + [As of ", time_str(time()), "] + + + + + + +
+

Server status

+ + +"; + +if ($xmlout) { + fwrite($xmloutfile,"\n"); + fwrite($xmloutfile," " . time() . "\n"); + fwrite($xmloutfile," \n"); +} + +# Are the data-driven web sites running? Check for existence +# of stop_web. If it is there, set $web_running to -1 for +# "disabled," otherwise it will be already set to 1 for "enabled." +# Set $web_host to the name of server hosting WWW site. +$web_running = !file_exists("../../stop_web"); +if ($web_running == 0) { $web_running = -1; } +show_status($web_host, "data-driven web pages", $web_running); + +# Check for httpd.pid file of upload/download server. +$uldl_running = file_exists($uldl_pid); +if ($uldl_running == 0) { $uldl_running = -1; } +show_status($uldl_host, "upload/download server", $uldl_running); + +# $sched_running = !file_exists("../../stop_sched"); +$sched_running = file_exists($sched_pid); +if ($sched_running == 0) { $sched_running = -1; } +show_status($sched_host, "scheduler", $sched_running); + +# parse through config.xml to get all daemons running +$config_xml = get_config(); +$cursor = 0; +# while ($thisxml = trim(parse_next_element($config_xml,"",&$cursor))) { +$thisxml = trim(parse_next_element($config_xml,"",&$cursor)); + $host = parse_element($thisxml,""); + $cmd = parse_element($thisxml,""); + list($ncmd) = explode(" ",$cmd); + $log = parse_element($thisxml,""); + if (!$log) { $log = $ncmd . ".log"; } + list($nlog) = explode(".log",$log); + $pid = parse_element($thisxml,""); + if (!$pid) { $pid = $ncmd . ".pid"; } + $disabled = parse_element($thisxml,""); + show_daemon_status($host,$nlog,$ncmd,$disabled); +# } + +if ($xmlout) { + fwrite($xmloutfile," \n \n"); +} + +echo " + + + + + + +
ProgramHostStatus
Running:Program is operating normally
Not Running:Program failed or ran out of work
+ (or the project is down)
Disabled:Program has been disabled by staff
+ (for debugging/maintenance)
+
+

Database/file status

+"; + +$retval = db_init_aux(); +if ($retval) { + echo "The database server is not accessible"; +} else { + echo " + + + "; + + show_counts("Results ready to send","results_ready_to_send",get_mysql_count("result where server_state = 2")); + show_counts("Results in progress","results_in_progress",get_mysql_count("result where server_state = 4")); + show_counts("Workunits waiting for validation","workunits_waiting_for_validation",get_mysql_count("workunit where need_validate=1")); + show_counts("Workunits waiting for assimilation","workunits_waiting_for_assimilation",get_mysql_count("workunit where assimilate_state=1")); + show_counts("Workunits waiting for deletion","workunits_waiting_for_deletion",get_mysql_count("workunit where file_delete_state=1")); + show_counts("Results waiting for deletion","results_waiting_for_deletion",get_mysql_count("result where file_delete_state=1")); + + $result = mysql_query("select MIN(transition_time) as min from workunit"); + $min = mysql_fetch_object($result); + mysql_free_result($result); + $gap = (time() - $min->min)/3600; + if ($gap < 0) { $gap = 0; } + show_counts("Transitioner backlog (hours)","transitioner_backlog_hours",$gap); + echo "
State#
"; +} + +if ($xmlout) { + fwrite($xmloutfile," \n"); + fwrite($xmloutfile,"\n"); +} + +echo " +
 
+"; + +page_tail(); + +?>