From e579a0ad56fef01efda712500a09804bd30c1078 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Tue, 7 Jan 2014 13:13:44 -0800 Subject: [PATCH] web: change server status page to use DB interface; from Janus --- html/user/server_status.php | 125 +++++++++++++++--------------------- html/user/white.css | 5 +- 2 files changed, 55 insertions(+), 75 deletions(-) diff --git a/html/user/server_status.php b/html/user/server_status.php index c305d0b8ff..d65f193c1d 100644 --- a/html/user/server_status.php +++ b/html/user/server_status.php @@ -129,66 +129,50 @@ function show_counts($key, $xmlkey, $value) { return 0; } -function get_mysql_count($query) { - $count = unserialize(get_cached_data(3600, "get_mysql_count".$query)); +function get_mysql_count($table, $query) { + $count = unserialize(get_cached_data(3600, "get_mysql_count".$table.$query)); if ($count == false) { - $result = mysql_query("select count(*) as count from " . $query); - $count = mysql_fetch_object($result); - mysql_free_result($result); - $count = $count->count; - set_cached_data(3600, serialize($count), "get_mysql_count".$query); + $count = BoincDB::get()->count($table,$query); + set_cached_data(3600, serialize($count), "get_mysql_count".$table.$query); } return $count; } -function get_mysql_value($query) { - $value = unserialize(get_cached_data(3600, "get_mysql_value".$query)); +function get_mysql_sum($table, $field) { + $value = unserialize(get_cached_data(3600, "get_mysql_sum".$table.$field)); if ($value == false) { - $result = mysql_query($query); - $row = mysql_fetch_object($result); - mysql_free_result($result); - $value = $row->value; - set_cached_data(3600, serialize($value), "get_mysql_value".$query); + $value = BoincDB::get()->sum($table, $field); + set_cached_data(3600, serialize($value), "get_mysql_sum".$table.$field); } return $value; } -function get_mysql_assoc($query) { - $assoc = unserialize(get_cached_data(3600, "get_mysql_assoc".$query)); - if ($assoc == false) { - $sql = "SELECT * FROM app WHERE deprecated != 1"; - $result = mysql_query($sql); - while($row = mysql_fetch_assoc($result)) { - $assoc[] = $row; - } - mysql_free_result($result); - set_cached_data(3600, serialize($assoc), "get_mysql_assoc".$query); +function get_cached_apps() { + $apps = unserialize(get_cached_data(3600, "get_cached_apps")); + if ($apps == false) { + $apps = BoincApp::enum("deprecated=0"); + set_cached_data(3600, serialize($apps), "get_cached_apps"); } - return $assoc; -} - -function get_mysql_user($clause) { - $count = unserialize(get_cached_data(3600, "get_mysql_user".$clause)); - if ($count == false) { - $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"); - $count = mysql_fetch_object($result); - mysql_free_result($result); - $count = $count->userid; - set_cached_data(3600, serialize($count), "get_mysql_user".$clause); - } - return $count; + return $apps; } function get_runtime_info($appid) { $info = unserialize(get_cached_data(3600, "get_runtime_info".$appid)); if ($info == false) { - $result = mysql_query(" - Select ceil(avg(elapsed_time)/3600*100)/100 as avg, + $info = BoincDB::get()->lookup_fields("result", "stdClass", + "ceil(avg(elapsed_time)/3600*100)/100 as avg, ceil(min(elapsed_time)/3600*100)/100 as min, - ceil(max(elapsed_time)/3600*100)/100 as max - from (SELECT elapsed_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"); - $info = mysql_fetch_object($result); - mysql_free_result($result); + ceil(max(elapsed_time)/3600*100)/100 as max, + count(distinct userid) as users", + "appid = $appid + AND validate_state=1 + AND received_time > (unix_timestamp()-(3600*24)) + GROUP BY appid"); + if (!$info){ + // No workunits found recently + $info = new stdClass; + $info->avg = $info->min = $info->max = $info->users = 0; + } set_cached_data(3600, serialize($info), "get_runtime_info".$appid); } return $info; @@ -340,39 +324,38 @@ if ($retval) { show_counts( tra("Tasks ready to send"), "results_ready_to_send", - get_mysql_count("result where server_state = 2") + get_mysql_count("result", "server_state = 2") ); show_counts( tra("Tasks in progress"), "results_in_progress", - get_mysql_count("result where server_state = 4") + get_mysql_count("result", "server_state = 4") ); show_counts( tra("Workunits waiting for validation"), "workunits_waiting_for_validation", - get_mysql_count("workunit where need_validate=1") + get_mysql_count("workunit", "need_validate=1") ); show_counts( tra("Workunits waiting for assimilation"), "workunits_waiting_for_assimilation", - get_mysql_count("workunit where assimilate_state=1") + get_mysql_count("workunit", "assimilate_state=1") ); show_counts( tra("Workunits waiting for file deletion"), "workunits_waiting_for_deletion", - get_mysql_count("workunit where file_delete_state=1") + get_mysql_count("workunit", "file_delete_state=1") ); show_counts( tra("Tasks waiting for file deletion"), "results_waiting_for_deletion", - get_mysql_count("result where file_delete_state=1") + get_mysql_count("result", "file_delete_state=1") ); $gap = unserialize(get_cached_data(3600, "transitioner_backlog")); if ($gap === false) { - $result = mysql_query("select MIN(transition_time) as min from workunit"); - $min = mysql_fetch_object($result); - mysql_free_result($result); + $min = BoincDB::get()->lookup_fields("workunit", "stdClass", "MIN(transition_time) as min", "TRUE"); + //$gap = BoincDB::get()->min("workunit", "transition_time"); $gap = time()-$gap/3600; $gap = (time() - $min->min)/3600; if (($gap < 0) || ($min->min == 0)) { $gap = 0; @@ -392,17 +375,17 @@ if ($retval) { show_counts( tra("with recent credit"), "users_with_recent_credit", - get_mysql_count("user where expavg_credit>1") + get_mysql_count("user", "expavg_credit>1") ); show_counts( tra("with credit"), "users_with_credit", - get_mysql_count("user where total_credit>0") + get_mysql_count("user", "total_credit>0") ); show_counts( tra("registered in past 24 hours"), "users_registered_in_past_24_hours", - get_mysql_count("user where create_time > (unix_timestamp() - (24*3600))") + get_mysql_count("user", "create_time > (unix_timestamp() - (24*3600))") ); if (!$xml) { echo "".tra("Computers")."#"; @@ -410,23 +393,23 @@ if ($retval) { show_counts( tra("with recent credit"), "hosts_with_recent_credit", - get_mysql_count("host where expavg_credit>1") + get_mysql_count("host", "expavg_credit>1") ); show_counts( tra("with credit"), "hosts_with_credit", - get_mysql_count("host where total_credit>0") + get_mysql_count("host", "total_credit>0") ); show_counts( tra("registered in past 24 hours"), "hosts_registered_in_past_24_hours", - get_mysql_count("host where create_time > (unix_timestamp() - (24*3600))") + get_mysql_count("host", "create_time > (unix_timestamp() - (24*3600))") ); // 200 cobblestones = 1 GigaFLOPS show_counts( tra("current GigaFLOPs"), "current_floating_point_speed", - get_mysql_value("SELECT sum(expavg_credit)/200 as value FROM user") + get_mysql_sum("user", "expavg_credit/200") ); if (!$xml) { end_table(); @@ -444,34 +427,32 @@ if ($retval) { ) ); } - $apps = get_mysql_assoc("SELECT * FROM app WHERE deprecated != 1"); + $apps = get_cached_apps(); if ($xml) { echo " \n"; } foreach($apps as $app) { - $appid = $app["id"]; - $uf_name = $app["user_friendly_name"]; - $info = get_runtime_info($appid); + $info = get_runtime_info($app->id); if ($xml) { echo " \n"; - echo " ".$appid."\n"; - echo " ".$app["name"]."\n"; - echo " ".get_mysql_count("result where server_state = 2 and appid = $appid")."\n"; - echo " ".get_mysql_count("result where server_state = 4 and appid = $appid")."\n"; + echo " ".$app->id."\n"; + echo " ".$app->name."\n"; + echo " ".get_mysql_count("result", "server_state = 2 and appid = ".$app->id)."\n"; + echo " ".get_mysql_count("result", "server_state = 4 and appid = ".$app->id)."\n"; echo " ".round($info->avg, 2)."\n"; echo " ".round($info->min, 2)."\n"; echo " ".round($info->max, 2)."\n"; - echo " ".get_mysql_user("and appid = $appid")."\n"; + echo " ".$info->users."\n"; echo " \n"; } else { - echo "$uf_name - " . number_format(get_mysql_count("result where server_state = 2 and appid = $appid")) . " - " . number_format(get_mysql_count("result where server_state = 4 and appid = $appid")) . " + echo "".$app->user_friendly_name." + " . number_format(get_mysql_count("result", "server_state = 2 and appid = ".$app->id)) . " + " . number_format(get_mysql_count("result", "server_state = 4 and appid = ".$app->id)) . " " ; echo number_format($info->avg,2) . " (" . number_format($info->min,2) . " - " . number_format($info->max,2) . ")"; echo " - " . number_format(get_mysql_user("and appid = $appid")) . " + " . number_format($info->users) . " " ; } diff --git a/html/user/white.css b/html/user/white.css index 35031c686e..de629aaa7e 100644 --- a/html/user/white.css +++ b/html/user/white.css @@ -206,6 +206,5 @@ div.pm_preview { td.running { background-color: #9aff4f; } -td.notrunning { background-color: #feff6f; } - -td.disabled { background-color: #ff4f4f; } +td.notrunning { background-color: #ff4f4f; } +td.disabled { background-color: #bbb; }