From 10de7876dcfd4f4289dd3936df495731a5a8f057 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Fri, 24 Oct 2008 16:11:44 +0000 Subject: [PATCH] - enhancemenets to dbinfo.php, from Tolu svn path=/trunk/boinc/; revision=16309 --- html/ops/dbinfo.php | 337 ++++++++++++++++++++++++++++++-------------- 1 file changed, 234 insertions(+), 103 deletions(-) diff --git a/html/ops/dbinfo.php b/html/ops/dbinfo.php index 078dee8060..3daf6f3709 100644 --- a/html/ops/dbinfo.php +++ b/html/ops/dbinfo.php @@ -1,103 +1,234 @@ -"); - -db_init(); - -admin_page_head("BOINC Database Info"); - -// if you have other db's just add more get_db_info lines -get_db_info($db_name); - -admin_page_tail(); - -function get_db_info($mydb) -{ - // Carl grabbed this from the mysql.com boards http://dev.mysql.com/doc/refman/5.0/en/show-table-status.html - - $MB = 1048576; - $KB = 1024; - - echo "
Database$mydb
"; - echo ""; - - $result = mysql_query("SHOW TABLE STATUS FROM $mydb"); - -/* SQL output - - mysql> show table status from qcnalpha; - -| Name | Engine | Version | Row_format | Rows | Avg_row_length | Data_length | Max_data_length | Index_length | Data_free | Auto_increment | Create_time | Update_time | Check_time | Collation | Checksum | Create_options | Comment | - -*/ - - $gdata = 0; - $gindex = 0; - $gtotal = 0; - $grows = 0; - - while($myarr = mysql_fetch_assoc($result)) { - $total = $myarr["Data_length"]+$myarr["Index_length"]; - - // sum grand totals - $gdata += $myarr["Data_length"]; - $gindex += $myarr["Index_length"]; - $gtotal += $total; - $grows += $myarr["Rows"]; - - - echo ""; - - echo " - "; - } - - $gdata /= $MB; - $gindex /= $MB; - $gtotal /= $MB; - - echo "
TableData SizeIndex SizeTotal sizeTotal RowsAvg. Size per Row
"; - echo $myarr["Name"] . "
"; - if ( $myarr["Data_length"] < $KB) { - echo " " . $myarr["Data_length"]; - } elseif ( ($myarr["Data_length"] > $KB) && ($myarr["Data_length"] < $MB) ) { - printf("%.0fK",($myarr["Data_length"] / $KB) ); - } elseif ( $myarr["Data_length"] >= $MB) { - printf("%.2fMB",($myarr["Data_length"] / $MB) ); - } - echo ""; - - if ( $myarr["Index_length"] < $KB) { - echo " ".$myarr["Index_length"]; - } elseif ( ($myarr["Index_length"] > $KB) && ($myarr["Index_length"] < $MB) ) { - printf("%.0fK",($myarr["Index_length"] / $KB) ); - } elseif ( $myarr["Index_length"] >= $MB) { - printf("%.2fMB",($myarr["Index_length"] / $MB) ); - } - echo "
"; - - if ( $total < $KB) { - echo " ".$total; - } elseif ( ($total > $KB) && ($total < $MB) ) { - printf("%.0fK",($total / $KB) ); - } elseif ( $total >= $MB) { - printf("%.2fMB",($total / $MB) ); - } - echo "
"; - - echo " - " . $myarr["Rows"]." - ".$myarr["Avg_row_length"]."
Totals:"; - printf("%.2fMB", $gdata); - echo ""; - printf("%.2fMB", $gindex); - echo ""; - printf("%.2fMB", $gtotal); - echo " - " . $grows . "


"; -} - -?> +name = $n; + $this->data_size = $d; + $this->index_size = $i; + $this->total_size = $t; + $this->rows = $r; + $this->size_per_row = $s; + } + function __destruct() { + } +} + + +$db_name = parse_config($config, ""); + +db_init(); + +admin_page_head("BOINC Database Info"); + +// if you have other db's just add more get_db_info lines +$db_rec = get_db_info($db_name); + +// show_db_info($db_name, $db_rec); +sort_db_info($db_name, $db_rec); + +admin_page_tail(); + + +// returns formatted data size +function size_format($size){ + $retval = 0; + + $KB = 1024; + $MB = 1024*1024; + $GB = 1024*1024*1024; + $TB = 1024*1024*1024*1024; + + if ($size < $KB) { + $retval = $size; + } elseif (($size > $KB) && ($size < $MB)) { + $retval = sprintf("%.0fK", ($size / $KB)); + } elseif ( ($size >= $MB) && ($size < $GB)) { + $retval = sprintf("%.2fMB", ($size / $MB)); + } elseif ( ($size >= $GB) && ($size < $TB)) { + $retval = sprintf("%.2fGB", ($size / $GB)); + } elseif ( $size >= $TB ) { + $retval = sprintf("%.2fTB", ($size / $TB)); + } + return $retval; +} + + +// returns the DB data structure as DB_REC +function get_db_info($db_name) +{ + // Carl grabbed this from the mysql.com boards http://dev.mysql.com/doc/refman/5.0/en/show-table-status.html + $result = mysql_query("SHOW TABLE STATUS FROM $db_name"); + + // SQL output + // mysql> show table status from [table_name]; + // | Name | Engine | Version | Row_format | Rows + // | Avg_row_length | Data_length | Max_data_length + // | Index_length | Data_free | Auto_increment | Create_time + // | Update_time | Check_time | Collation | Checksum | Create_options | Comment | + // + + $gdata = 0; + $gindex = 0; + $gtotal = 0; + $grows = 0; + + $i = 0; + $db_rec = array(); + while($myarr = mysql_fetch_assoc($result)) { + + // sum grand totals + $total = $myarr["Data_length"] + $myarr["Index_length"]; + $gindex += $myarr["Index_length"]; + $gdata += $myarr["Data_length"]; + $grows += $myarr["Rows"]; + $gtotal += $total; + + $db_rec[$i] = new DB_REC ($myarr["Name"], $myarr["Data_length"], $myarr["Index_length"], $total, $myarr["Rows"], $myarr["Avg_row_length"] ); + $i++; + } + + $db_rec[$i] = new DB_REC ("Total", $gdata, $gindex, $gtotal, $grows, "" ); + + return $db_rec; +} + + +// shows the plain db structure +function show_db_info($db_name, $db_rec) +{ + + echo ""; + echo ""; + echo ""; + echo ""; + + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + + for ($i = 0; $i < sizeof($db_rec)-1; $i++){ + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + } + + // Last record is just a summary + $i = sizeof($db_rec)-1; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + + echo "
Database $db_name
TableData SizeIndex SizeTotal SizeTotal RowsAvg. Size per Row
" . $db_rec[$i]->name . "" . size_format($db_rec[$i]->data_size) . "" . size_format($db_rec[$i]->index_size) . "" . size_format($db_rec[$i]->total_size) . "" . number_format($db_rec[$i]->rows) . "" . size_format($db_rec[$i]->size_per_row) . "
" . $db_rec[$i]->name . "" . size_format($db_rec[$i]->data_size) . "" . size_format($db_rec[$i]->index_size) . "" . size_format($db_rec[$i]->total_size) . "" . number_format($db_rec[$i]->rows) . "
"; +} + + + +// NB: same as show_db_info but with sortable cloumns +function sort_db_info($db_name, $db_rec) +{ + // sort + $file_list = array(); + $file_sort = array(); + + $sort = get_str("sort", true); + $r = get_str("r", true); + + // check if its empty + if(empty($sort)) $sort = "name"; + // check for allowed keys + if ((strcmp($sort, "name")!=0) && + (strcmp($sort, "data_size")!=0) && + (strcmp($sort, "index_size")!=0) && + (strcmp($sort, "total_size")!=0) && + (strcmp($sort, "rows")!=0) && + (strcmp($sort, "size_per_row")!=0)) + $sort = "name"; + if(empty($r)) $r=0; + + for ($i = 0; $i < sizeof($db_rec)-1; $i++){ + $file_details["name"] = $db_rec[$i]->name; + $file_details["data_size"] = $db_rec[$i]->data_size; + $file_details["index_size"] = $db_rec[$i]->index_size; + $file_details["total_size"] = $db_rec[$i]->total_size; + $file_details["rows"] = $db_rec[$i]->rows; + $file_details["size_per_row"] = $db_rec[$i]->size_per_row; + + $file_list[$i] = $file_details; + $key = strtolower($file_details[$sort]); + $file_sort[$i] = $key; + } + + if($r)arsort($file_sort); + else asort($file_sort); + // -- end sort + + echo ""; + echo ""; + echo ""; + echo ""; + + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + + $i = 0; + while ( list($key, $value) = each($file_sort) ) { + $value = $file_list[$key]; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + $i++; + } + + // Last record is just a summary + $i = sizeof($db_rec)-1; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + + echo "
Database $db_name
Table Data SizeIndex SizeTotal SizeTotal RowsAvg. Size per Row
" . $value["name"] . "" . size_format($value["data_size"]) . "" . size_format($value["index_size"]) . "" . size_format($value["total_size"]) . "" . number_format($value["rows"]) . "" . size_format($value["size_per_row"]) . "
" . $db_rec[$i]->name . "" . size_format($db_rec[$i]->data_size) . "" . size_format($db_rec[$i]->index_size) . "" . size_format($db_rec[$i]->total_size) . "" . number_format($db_rec[$i]->rows) . "
"; +} + + +?>