mirror of https://github.com/BOINC/boinc.git
reintroduced xml->output file code
svn path=/trunk/boinc/; revision=8177
This commit is contained in:
parent
209f0d3199
commit
dfedc30dff
|
@ -1,25 +1,36 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
// server_status.php [-f xml_output_filename]
|
// server_status.php [-f xml_output_filename]
|
||||||
|
// (or server_status.php?xml=1)
|
||||||
//
|
//
|
||||||
// outputs general information about BOINC server status gathered from
|
// outputs general information about BOINC server status gathered from
|
||||||
// config.xml or mysql database queries.
|
// config.xml or mysql database queries. If you are running all your
|
||||||
|
// services on one machine, and the database isn't so large, this should
|
||||||
|
// work right out of the box. Otherwise see configureables below.
|
||||||
//
|
//
|
||||||
// Daemons in config.xml are checked to see if they are running by ssh'ing
|
// Daemons in config.xml are checked to see if they are running by ssh'ing
|
||||||
// into the respective hosts and searching for active pids. Passwordless
|
// into the respective hosts and searching for active pids. Passwordless
|
||||||
// logins must be in effect.
|
// logins must be in effect if there are multiple hosts involved.
|
||||||
//
|
//
|
||||||
// The database queries are rather slow. You might consider running these
|
// The database queries may be very slow. You might consider running these
|
||||||
// queries elsewhere via cronjob, outputing numbers into a readable file,
|
// queries elsewhere via cronjob, outputing numbers into a readable file,
|
||||||
// and then getting the # latest values with a `/bin/tail -1 data_file`
|
// and then getting the latest values with a `/bin/tail -1 data_file`.
|
||||||
|
// See commented example in the code.
|
||||||
|
//
|
||||||
|
// You can get an xml version of the stats via the web when the url has the
|
||||||
|
// optional "?xml=1" tag at the end, i.e
|
||||||
|
// http://yourboincproject.edu/server_status.php?xml=1
|
||||||
//
|
//
|
||||||
// If running as a standalone program there is an optional -f flag where
|
// If running as a standalone program there is an optional -f flag where
|
||||||
// you can generate xml server status output to the filename you provide.
|
// you can generate xml server status output to the filename you provide
|
||||||
|
// (this will output both html to stdout and xml to the filename given).
|
||||||
|
// Some may prefer to do this if takes so long to dredge up the stats for
|
||||||
|
// the html, you won't have to do it again to generate the xml.
|
||||||
//
|
//
|
||||||
// It is highly recommended that you run this program every 10 minutes and
|
// It is highly recommended that you run this program every 10 minutes and
|
||||||
// send its stdout to an .html file every 10 minutes, rather than having
|
// send its stdout to an .html file, rather than having the values get
|
||||||
// the values get regenerated every time the page is accessed. Or use the
|
// regenerated every time the page is accessed. Or use the available
|
||||||
// available web page cache utilities.
|
// web page cache utilities.
|
||||||
//
|
//
|
||||||
// You should edit the following variables in config.xml to suit your needs:
|
// You should edit the following variables in config.xml to suit your needs:
|
||||||
//
|
//
|
||||||
|
@ -47,6 +58,14 @@ if ($xml) $cache_args = "xml=1";
|
||||||
$cache_period = 600;
|
$cache_period = 600;
|
||||||
start_cache($cache_period, $cache_args);
|
start_cache($cache_period, $cache_args);
|
||||||
|
|
||||||
|
$xmlout = "";
|
||||||
|
if ($argv[1] == "-f") { $xmlout = $argv[2];
|
||||||
|
$xmloutfile = fopen($xmlout,"w+");
|
||||||
|
if (!$xmloutfile) {
|
||||||
|
die( "failed to open file: $xmlout");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// daemon status outputs: 1 (running) 0 (not running) or -1 (disabled)
|
// daemon status outputs: 1 (running) 0 (not running) or -1 (disabled)
|
||||||
//
|
//
|
||||||
function daemon_status($host, $pidname, $progname, $disabled) {
|
function daemon_status($host, $pidname, $progname, $disabled) {
|
||||||
|
@ -71,40 +90,27 @@ function daemon_status($host, $pidname, $progname, $disabled) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function show_status($host, $function, $running) {
|
function show_status($host, $function, $running) {
|
||||||
global $xml;
|
global $xml,$xmlout,$xmloutfile;
|
||||||
if ($xml) {
|
$xmlstring = " <daemon>\n <host>$host</host>\n <command>$function</command>\n";
|
||||||
echo "
|
$htmlstring = "<tr><td>$function</td><td>$host</td>";
|
||||||
<daemon>
|
|
||||||
<host>$host</host>
|
|
||||||
<command>$function</command>
|
|
||||||
";
|
|
||||||
} else {
|
|
||||||
echo "<tr><td>$function</td><td>$host</td>";
|
|
||||||
}
|
|
||||||
if ($running == 1) {
|
if ($running == 1) {
|
||||||
if ($xml) {
|
$xmlstring .= " <status>running</status>\n";
|
||||||
echo " <status>running</status>\n";
|
$htmlstring .= "<td bgcolor=00ff00>Running</td>\n";
|
||||||
} else {
|
|
||||||
echo "<td bgcolor=00ff00>Running</td>\n";
|
|
||||||
}
|
}
|
||||||
} elseif ($running == 0) {
|
elseif ($running == 0) {
|
||||||
if ($xml) {
|
$xmlstring .= " <status>not running</status>\n";
|
||||||
echo " <status>not running</status>\n";
|
$htmlstring .= "<td bgcolor=ff0000>Not Running</td>\n";
|
||||||
} else {
|
|
||||||
echo "<td bgcolor=ff0000>Not Running</td>\n";
|
|
||||||
}
|
}
|
||||||
} else {
|
else {
|
||||||
if ($xml) {
|
$xmlstring .= " <status>disabled</status>\n";
|
||||||
echo " <status>disabled</status>\n";
|
$htmlstring .= "<td bgcolor=ff8800>Disabled</td>\n";
|
||||||
} else {
|
|
||||||
echo "<td bgcolor=ff8800>Disabled</td>\n";
|
|
||||||
}
|
}
|
||||||
}
|
$xmlstring .= " </daemon>\n";
|
||||||
if ($xml) {
|
$htmlstring .= "</tr>\n";
|
||||||
echo " </daemon>\n";
|
if ($xml) { echo $xmlstring; return 0; }
|
||||||
} else {
|
if ($xmlout) { fwrite($xmloutfile,$xmlstring); }
|
||||||
echo "</tr>";
|
echo $htmlstring;
|
||||||
}
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
function show_daemon_status($host, $pidname, $progname, $disabled) {
|
function show_daemon_status($host, $pidname, $progname, $disabled) {
|
||||||
|
@ -113,13 +119,13 @@ function show_daemon_status($host, $pidname, $progname, $disabled) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function show_counts($key, $xmlkey, $value) {
|
function show_counts($key, $xmlkey, $value) {
|
||||||
global $xml;
|
global $xml,$xmlout,$xmloutfile;
|
||||||
$formattedvalue = number_format($value);
|
$formattedvalue = number_format($value);
|
||||||
if ($xml) {
|
$xmlstring = " <$xmlkey>$value</$xmlkey>\n";
|
||||||
echo " <$xmlkey>$value</$xmlkey>\n";
|
if ($xml) { echo $xmlstring; return 0; }
|
||||||
} else {
|
if ($xmlout) { fwrite($xmloutfile,$xmlstring); }
|
||||||
echo "<tr><td>$key</td><td>$formattedvalue</td></tr>";
|
echo "<tr><td>$key</td><td>$formattedvalue</td></tr>";
|
||||||
}
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_mysql_count ($query) {
|
function get_mysql_count ($query) {
|
||||||
|
@ -148,12 +154,14 @@ $ps_exe = parse_element($config_vars,"<ps_exe>");
|
||||||
if ($ps_exe == "") { $ps_exe = "/bin/ps"; }
|
if ($ps_exe == "") { $ps_exe = "/bin/ps"; }
|
||||||
|
|
||||||
|
|
||||||
|
$xmlstring = "<server_status>\n <update_time>" . time() . "</update_time>\n <daemon_status>\n";
|
||||||
if ($xml) {
|
if ($xml) {
|
||||||
xml_header();
|
xml_header();
|
||||||
echo "<server_status>\n";
|
echo $xmlstring;
|
||||||
echo " <update_time>" . time() . "</update_time>\n";
|
|
||||||
echo " <daemon_status>\n";
|
|
||||||
} else {
|
} else {
|
||||||
|
if ($xmlout) {
|
||||||
|
fwrite($xmloutfile,$xmlstring);
|
||||||
|
}
|
||||||
page_head("Server status page");
|
page_head("Server status page");
|
||||||
echo "<p>
|
echo "<p>
|
||||||
[As of ", time_str(time()), "]
|
[As of ", time_str(time()), "]
|
||||||
|
@ -205,9 +213,10 @@ while ($thisxml = trim(parse_next_element($config_xml,"<daemon>",&$cursor))) {
|
||||||
show_daemon_status($host,$nlog,$ncmd,$disabled);
|
show_daemon_status($host,$nlog,$ncmd,$disabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($xml) {
|
$xmlstring = " </daemon_status>\n <database_file_states>\n";
|
||||||
echo " </daemon_status>\n <database_file_states>\n";
|
if ($xml) { echo $xmlstring; }
|
||||||
} else {
|
else {
|
||||||
|
if ($xmlout) { fwrite($xmloutfile,$xmlstring); }
|
||||||
echo "
|
echo "
|
||||||
<tr><td align=right><b>Running:</b></td>
|
<tr><td align=right><b>Running:</b></td>
|
||||||
<td colspan=2>Program is operating normally</td></tr>
|
<td colspan=2>Program is operating normally</td></tr>
|
||||||
|
@ -235,6 +244,13 @@ if ($retval) {
|
||||||
";
|
";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If you are reading these values from a file rather than
|
||||||
|
// making live queries to the database, do something like this:
|
||||||
|
//
|
||||||
|
// $sendfile = "/home/boincadm/server_status_data/count_results_unsent.out";
|
||||||
|
// $n = `/bin/tail -1 $sendfile`;
|
||||||
|
// show_counts("Results ready to send","results_ready_to_send",$n);
|
||||||
|
|
||||||
show_counts("Results ready to send","results_ready_to_send",get_mysql_count("result where server_state = 2"));
|
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("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 validation","workunits_waiting_for_validation",get_mysql_count("workunit where need_validate=1"));
|
||||||
|
@ -253,10 +269,10 @@ if ($retval) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($xml) {
|
$xmlstring = " </database_file_states>\n</server_status>\n";
|
||||||
echo " </database_file_states>\n";
|
if ($xml) { echo $xmlstring; }
|
||||||
echo "</server_status>\n";
|
else {
|
||||||
} else {
|
if ($xmlout) { fwrite($xmloutfile,$xmlstring); }
|
||||||
echo "
|
echo "
|
||||||
</td>
|
</td>
|
||||||
<td> </td>
|
<td> </td>
|
||||||
|
|
Loading…
Reference in New Issue