Ticket #913: sample_server_status.patch

File sample_server_status.patch, 11.2 KB (added by Christian Beer, 14 years ago)

patch to ops/sample_server_status.php to show more info

  • C:/Coding/Sources/BOINC-help/

    old new  
    6363require_once("../inc/util_ops.inc");
    6464require_once("../inc/xml.inc");
    6565require_once("../inc/cache.inc");
     66require_once("../inc/translation.inc");
    6667
    6768$xml = get_int("xml", true);
    6869
    69 $cache_args = "";
     70$cache_args = $languages_in_use[0];
    7071if ($xml) $cache_args = "xml=1";
    7172$cache_period = 600;
    7273start_cache($cache_period, $cache_args);
     
    110111    $htmlstring = "<tr><td>$function</td><td>$host</td>";
    111112    if ($running == 1) {
    112113        $xmlstring .= "      <status>running</status>\n";
    113         $htmlstring .= "<td class=\"running\">Running</td>\n";
     114        $htmlstring .= "<td class=\"running\">".tra("Running")."</td>\n";
    114115    } elseif ($running == 0) {
    115116        $xmlstring .= "      <status>not running</status>\n";
    116         $htmlstring .= "<td class=\"notrunning\">Not Running</td>\n";
     117        $htmlstring .= "<td class=\"notrunning\">".tra("Not Running")."</td>\n";
    117118    } else {
    118119        $xmlstring .= "      <status>disabled</status>\n";
    119         $htmlstring .= "<td class=\"disabled\">Disabled</td>\n";
     120        $htmlstring .= "<td class=\"disabled\">".tra("Disabled")."</td>\n";
    120121    }
    121122    $xmlstring .= "    </daemon>\n";
    122123    $htmlstring .= "</tr>\n";
     
    157158    return $count->count;
    158159}
    159160
     161function get_mysql_value ($query) {
     162    $result = mysql_query($query);
     163    $row = mysql_fetch_object($result);
     164    mysql_free_result($result);
     165    return $row->value;
     166}
     167
     168function get_mysql_assoc($query) {
     169    $sql = "SELECT * FROM app WHERE deprecated != 1";
     170    $result = mysql_query($sql);
     171    while($row = mysql_fetch_assoc($result)) {
     172        $assoc[] = $row;
     173    }
     174    mysql_free_result($result);
     175    return $assoc;
     176}
     177
     178function get_mysql_user ($clause) {
     179    $result = mysql_query("select count(userid) as userid from (SELECT distinct userid FROM result where validate_state=1 and received_time > (unix_timestamp()-(3600*24*1)) " . $clause . ") t");
     180    $count = mysql_fetch_object($result);
     181    mysql_free_result($result);
     182    return $count->userid;
     183}
     184
     185function get_cpu_time ($appid) {
     186    $result = mysql_query("
     187        Select ceil(avg(cpu_time)/3600*100)/100 as cpu_time,
     188                ceil(min(cpu_time)/3600*100)/100 as min,
     189                ceil(max(cpu_time)/3600*100)/100 as max
     190        from (SELECT cpu_time FROM `result` WHERE appid = $appid and validate_state =1 and received_time > (unix_timestamp()-(3600*24)) ORDER BY `received_time` DESC limit 100) t");
     191    $count = mysql_fetch_object($result);
     192    mysql_free_result($result);
     193    return $count;
     194}
     195
    160196$config_xml = get_config();
    161197$config_vars = parse_element($config_xml,"<config>");
    162198$project_host = parse_element($config_vars,"<host>");
     
    205241    if ($xmlout) {
    206242        fwrite($xmloutfile,$xmlstring);
    207243    }
    208     page_head("Server status page");
     244    page_head(tra("Server status page"));
    209245    if ($version) {
    210         echo "Server software version: $version<p>\n";
     246        echo tra("Server software version: %1", $version) . " / ";
    211247    }
    212248    echo time_str(time()), "
    213249        <table width=100%>
    214250        <tr>
    215251        <td width=40% valign=top>
    216         <h2>Server status</h2>
     252        <h2>".tra("Server status")."</h2>
    217253        <table border=0 cellpadding=4>
    218         <tr><th>Program</th><th>Host</th><th>Status</th></tr>
     254        <tr><th>".tra("Program")."</th><th>".tra("Host")."</th><th>".tra("Status")."</th></tr>
    219255    ";
    220256}
    221257;
     
    226262//
    227263$web_running = !file_exists("../../stop_web");
    228264if ($web_running == 0) $web_running = -1;
    229 show_status($www_host, "data-driven web pages", $web_running);
     265show_status($www_host, tra("data-driven web pages"), $web_running);
    230266
    231267// Check for httpd.pid file of upload/download server.
    232268//
    233269$uldl_running = file_exists($uldl_pid);
    234270if ($uldl_running == 0) $uldl_running = -1;
    235 show_status($uldl_host, "upload/download server", $uldl_running);
     271show_status($uldl_host, tra("upload/download server"), $uldl_running);
    236272
    237273$sched_running = !file_exists("../../stop_sched");
    238 show_status($sched_host, "scheduler", $sched_running);
     274show_status($sched_host, tra("scheduler"), $sched_running);
    239275
    240276// parse through config.xml to get all daemons running
    241277//
     
    268304        fwrite($xmloutfile,$xmlstring);
    269305    }
    270306    echo "
    271         <tr><td align=right><b>Running:</b></td>
    272         <td colspan=2>Program is operating normally</td></tr>
    273         <tr><td align=right><b>Not Running:</b></td>
    274         <td colspan=2>Program failed or ran out of work<br>
    275            (or the project is down)</td></tr>
    276         <tr><td align=right><b>Disabled:</b></td>
    277         <td colspan=2>Program has been disabled by staff<br>
    278            (for debugging/maintenance)</td></tr>
     307        <tr><td align=right><b>".tra("Running:")."</b></td>
     308        <td colspan=2>".tra("Program is operating normally")."</td></tr>
     309        <tr><td align=right><b>".tra("Not Running:")."</b></td>
     310        <td colspan=2>".tra("Program failed or ran out of work<br>
     311(or the project is down)")."</td></tr>
     312        <tr><td align=right><b>".tra("Disabled:")."</b></td>
     313        <td colspan=2>".tra("Program has been disabled by staff<br>
     314(for debugging/maintenance)")."</td></tr>
    279315        </table>
    280316        </td>
    281         <td width=40% valign=top>
    282         <h2>Database/file status</h2>
     317        <td valign=top>
     318        <h2>".tra("Database/file status")."</h2>
    283319    ";
    284320}
    285321
    286322$retval = db_init_aux();
    287323if ($retval) {
    288     echo "The database server is not accessible";
     324    echo tra("The database server is not accessible");
    289325} else {
    290326    if (!$xml) {
    291         echo "
     327        echo "<table border=0 cellpadding=0 cellspacing=0><tr><td>
    292328            <table border=0 cellpadding=4>
    293             <tr><th>State</th><th>#</th></tr>
     329            <tr><th>".tra("State")."</th><th>#</th></tr>
    294330        ";
    295331    }
    296332
     
    302338    // show_counts("Tasks ready to send","results_ready_to_send",$n);
    303339
    304340    show_counts(
    305         "Tasks ready to send",
     341        tra("Tasks ready to send"),
    306342        "results_ready_to_send",
    307343        get_mysql_count("result where server_state = 2")
    308344    );
    309345    show_counts(
    310         "Tasks in progress",
     346        tra("Tasks in progress"),
    311347        "results_in_progress",
    312348        get_mysql_count("result where server_state = 4")
    313349    );
    314350    show_counts(
    315         "Workunits waiting for validation",
     351        tra("Workunits waiting for validation"),
    316352        "workunits_waiting_for_validation",
    317353        get_mysql_count("workunit where need_validate=1")
    318354    );
    319355    show_counts(
    320         "Workunits waiting for assimilation",
     356        tra("Workunits waiting for assimilation"),
    321357        "workunits_waiting_for_assimilation",
    322358        get_mysql_count("workunit where assimilate_state=1")
    323359    );
    324360    show_counts(
    325         "Workunits waiting for file deletion",
     361        tra("Workunits waiting for file deletion"),
    326362        "workunits_waiting_for_deletion",
    327363        get_mysql_count("workunit where file_delete_state=1")
    328364    );
    329365    show_counts(
    330         "Tasks waiting for file deletion",
     366        tra("Tasks waiting for file deletion"),
    331367        "results_waiting_for_deletion",
    332368        get_mysql_count("result where file_delete_state=1")
    333369    );
     
    340376        $gap = 0;
    341377    }
    342378    show_counts(
    343         "Transitioner backlog (hours)",
     379        tra("Transitioner backlog (hours)"),
    344380        "transitioner_backlog_hours",
    345381        $gap
    346382    );
    347383    if (!$xml) {
    348         echo "</table>";
     384        echo "</table></td><td>";
     385        echo "<table>";
     386        echo "<tr><th>".tra("Users")."</th><th>#</th></tr>";
     387        show_counts(
     388                tra("in database"),
     389                "users_in_database",
     390                get_mysql_count("user")
     391        );
     392        show_counts(
     393                tra("with credit"),
     394                "users_with_credit",
     395                get_mysql_count("user where total_credit>0")
     396        );
     397        show_counts(
     398                tra("registered in past 24 hours"),
     399                "users_registered_in_past_24_hours",
     400                get_mysql_count("user where create_time > (unix_timestamp() - (24*3600))")
     401        );
     402        echo "<tr><th>".tra("Computers")."</th><th>#</th></tr>";
     403        show_counts(
     404                tra("in database"),
     405                "hosts_in_database",
     406                get_mysql_count("host")
     407        );
     408        show_counts(
     409                tra("with credit"),
     410                "hosts_with_credit",
     411                get_mysql_count("host where total_credit>0")
     412        );
     413        show_counts(
     414                tra("registered in past 24 hours"),
     415                "hosts_registered_in_past_24_hours",
     416                get_mysql_count("host where create_time > (unix_timestamp() - (24*3600))")
     417        );
     418        show_counts(
     419                tra("active in past 7 days"),
     420                "hosts_active_in_past_7_days",
     421                get_mysql_count("host where rpc_time > (unix_timestamp() - (7*24*3600))")
     422        );
     423        show_counts(
     424                tra("potential GigaFLOPs")."<sup>1)</sup>",
     425                "potential_gflops",
     426                get_mysql_value("select sum(p_fpops)/1e9 as value FROM host")
     427        );
     428        show_counts(
     429                tra("pot. GigaFLOPs in past 7 days")."<sup>2)</sup>",
     430                "pot_gflops_in_past_7_days",
     431                get_mysql_value("select sum(p_fpops)/1e9 as value FROM host WHERE rpc_time > (unix_timestamp() - (7*86400))")
     432        );
     433        // 100,000 cobblestones = 1 TeraFLOPS
     434        // divide by 2, because double credits
     435        show_counts(
     436                tra("current GigaFLOPs")."<sup>3)</sup>",
     437                "current_floating_point_speed",
     438                get_mysql_value("SELECT sum(expavg_credit)/2/100 as value FROM user")
     439        );
     440
     441        end_table();
     442        echo "</td></tr></table>";
     443
     444        start_table();
     445        echo "<tr><th colspan=5>".tra("Tasks by application")."</th></tr>";
     446        row_heading_array(array(tra("application"),tra("unsent"),tra("in progress"),tra("avg runtime of last 100 results in h (min-max)"),tra("users in last 24h")));
     447        $apps = get_mysql_assoc("SELECT * FROM app WHERE deprecated != 1");
     448        foreach($apps as $app) {
     449            $appid = $row["id"];
     450            $uf_name = $row["user_friendly_name"];
     451            echo "<tr><td>$uf_name</td>
     452                    <td>" . number_format(get_mysql_count("result where server_state = 2 and appid = $appid")) . "</td>
     453                    <td>" . number_format(get_mysql_count("result where server_state = 4 and appid = $appid")) . "</td>
     454                    <td>";
     455            $count = get_cpu_time($appid);
     456            echo number_format($count->cpu_time,2) . " (" . number_format($count->min,2) . " - " . number_format($count->max,2) . ")";
     457            echo "</td>
     458                    <td>" . number_format(get_mysql_user("and appid = $appid")) . "</td>
     459                </tr>";
     460        }
     461        end_table();
     462       
     463        // This can be used to show the status of Workunits of the same Batch if they have a common
     464        // substring within the Workunits name. Adjust to your own naming convention first.
     465        //start_table();
     466        //row1(tra("Workunits to do"));
     467
     468        //$sql = "SELECT substring(workunit.name, 1, (locate(']', workunit.name))) as b, count(*) as todo FROM workunit where assimilate_state!=2 group by substring(workunit.name, 1, (locate(']', workunit.name)))";
     469        //$result = mysql_query($sql);
     470        //while ($row = mysql_fetch_assoc($result)) {
     471        //      row2($row["b"], $row["todo"]);
     472        //}
     473        //end_table();
    349474    }
    350475}
    351476
     
    358483    }
    359484    echo "
    360485        </td>
    361         <td>&nbsp;</td>
    362486        </tr>
    363487        </table>
    364488    ";
     489    echo tra("1) the sum of the benchmarked FLOPs of all hosts in the database")."<br/>";
     490    echo tra("2) the sum of the benchmarked FLOPs of all hosts that have contacted the server within the past week")."<br/>";
     491    echo tra("3) from the sum of the Recent Average Credit (RAC) for all users");
    365492    page_tail();
    366493}
    367494