1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
require_once("../inc/util_ops.inc"); |
4
|
|
|
require_once("../inc/db_ops.inc"); |
5
|
|
|
|
6
|
|
|
class DB_REC { |
7
|
|
|
|
8
|
|
|
var $name; |
9
|
|
|
var $data_size; |
10
|
|
|
var $index_size; |
11
|
|
|
var $total_size; |
12
|
|
|
var $rows; |
13
|
|
|
var $size_per_row; |
14
|
|
|
|
15
|
|
|
function __construct($n, $d, $i, $t, $r, $s) { |
16
|
|
|
$this->name = $n; |
17
|
|
|
$this->data_size = $d; |
18
|
|
|
$this->index_size = $i; |
19
|
|
|
$this->total_size = $t; |
20
|
|
|
$this->rows = $r; |
21
|
|
|
$this->size_per_row = $s; |
22
|
|
|
} |
23
|
|
|
function __destruct() { |
24
|
|
|
} |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
|
28
|
|
|
$db_name = parse_config(get_config(), "<db_name>"); |
29
|
|
|
|
30
|
|
|
db_init(); |
31
|
|
|
|
32
|
|
|
admin_page_head("BOINC Database Info"); |
33
|
|
|
|
34
|
|
|
// if you have other db's just add more get_db_info lines |
35
|
|
|
$db_rec = get_db_info($db_name); |
36
|
|
|
|
37
|
|
|
// show_db_info($db_name, $db_rec); |
38
|
|
|
sort_db_info($db_name, $db_rec); |
39
|
|
|
|
40
|
|
|
admin_page_tail(); |
41
|
|
|
|
42
|
|
|
|
43
|
|
|
// returns formatted data size |
44
|
|
|
function size_format($size){ |
45
|
|
|
$retval = 0; |
46
|
|
|
|
47
|
|
|
$KB = 1024; |
48
|
|
|
$MB = 1024*1024; |
49
|
|
|
$GB = 1024*1024*1024; |
50
|
|
|
$TB = 1024*1024*1024*1024; |
51
|
|
|
|
52
|
|
|
if ($size < $KB) { |
53
|
|
|
$retval = $size; |
54
|
|
|
} elseif (($size > $KB) && ($size < $MB)) { |
55
|
|
|
$retval = sprintf("%.0fK", ($size / $KB)); |
56
|
|
|
} elseif ( ($size >= $MB) && ($size < $GB)) { |
57
|
|
|
$retval = sprintf("%.2fMB", ($size / $MB)); |
58
|
|
|
} elseif ( ($size >= $GB) && ($size < $TB)) { |
59
|
|
|
$retval = sprintf("%.2fGB", ($size / $GB)); |
60
|
|
|
} elseif ( $size >= $TB ) { |
61
|
|
|
$retval = sprintf("%.2fTB", ($size / $TB)); |
62
|
|
|
} |
63
|
|
|
return $retval; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
|
67
|
|
|
// returns the DB data structure as DB_REC |
68
|
|
|
// see http://dev.mysql.com/doc/refman/5.0/en/show-table-status.html |
69
|
|
|
// |
70
|
|
|
function get_db_info($db_name) { |
71
|
|
|
$result = _mysql_query("SHOW TABLE STATUS FROM $db_name"); |
72
|
|
|
|
73
|
|
|
// SQL output |
74
|
|
|
// mysql> show table status from [table_name]; |
75
|
|
|
// | Name | Engine | Version | Row_format | Rows |
76
|
|
|
// | Avg_row_length | Data_length | Max_data_length |
77
|
|
|
// | Index_length | Data_free | Auto_increment | Create_time |
78
|
|
|
// | Update_time | Check_time | Collation | Checksum | Create_options | Comment | |
79
|
|
|
// |
80
|
|
|
|
81
|
|
|
$gdata = 0; |
82
|
|
|
$gindex = 0; |
83
|
|
|
$gtotal = 0; |
84
|
|
|
$grows = 0; |
85
|
|
|
|
86
|
|
|
$i = 0; |
87
|
|
|
$db_rec = array(); |
88
|
|
|
while ($myarr = _mysql_fetch_assoc($result)) { |
89
|
|
|
if ($myarr['Comment'] == 'VIEW') continue; |
90
|
|
|
|
91
|
|
|
// sum grand totals |
92
|
|
|
$total = $myarr["Data_length"] + $myarr["Index_length"]; |
|
|
|
|
93
|
|
|
$gindex += $myarr["Index_length"]; |
94
|
|
|
$gdata += $myarr["Data_length"]; |
95
|
|
|
$grows += $myarr["Rows"]; |
96
|
|
|
$gtotal += $total; |
97
|
|
|
|
98
|
|
|
$db_rec[$i] = new DB_REC( |
99
|
|
|
$myarr["Name"], |
100
|
|
|
$myarr["Data_length"], |
101
|
|
|
$myarr["Index_length"], |
102
|
|
|
$total, |
103
|
|
|
$myarr["Rows"], |
104
|
|
|
$myarr["Avg_row_length"] |
105
|
|
|
); |
106
|
|
|
$i++; |
107
|
|
|
} |
108
|
|
|
$db_rec[$i] = new DB_REC ("Total", $gdata, $gindex, $gtotal, $grows, "" ); |
109
|
|
|
return $db_rec; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
// show the DB structure |
113
|
|
|
// |
114
|
|
|
function show_db_info($db_name, $db_rec) { |
115
|
|
|
echo "<table cols=6>"; |
116
|
|
|
echo "<tr>"; |
117
|
|
|
echo "<th colspan=6> Database $db_name </th>"; |
118
|
|
|
echo "</tr>"; |
119
|
|
|
|
120
|
|
|
echo "<tr>"; |
121
|
|
|
echo "<th>Table</th>"; |
122
|
|
|
echo "<th>Data Size</th>"; |
123
|
|
|
echo "<th>Index Size</th>"; |
124
|
|
|
echo "<th>Total Size</th>"; |
125
|
|
|
echo "<th>Total Rows</th>"; |
126
|
|
|
echo "<th>Avg. Size per Row</th>"; |
127
|
|
|
echo "</tr>"; |
128
|
|
|
|
129
|
|
|
for ($i = 0; $i < sizeof($db_rec)-1; $i++){ |
|
|
|
|
130
|
|
|
echo "<tr>"; |
131
|
|
|
echo "<td align=left valign=top class=fieldname>" . $db_rec[$i]->name . "</td>"; |
132
|
|
|
echo "<td align=left valign=top class=fieldname>" . size_format($db_rec[$i]->data_size) . "</td>"; |
133
|
|
|
echo "<td align=left valign=top class=fieldname>" . size_format($db_rec[$i]->index_size) . "</td>"; |
134
|
|
|
echo "<td align=left valign=top class=fieldname>" . size_format($db_rec[$i]->total_size) . "</td>"; |
135
|
|
|
echo "<td align=left valign=top class=fieldname>" . number_format($db_rec[$i]->rows) . "</td>"; |
136
|
|
|
echo "<td align=left valign=top class=fieldname>" . size_format($db_rec[$i]->size_per_row) . "</td>"; |
137
|
|
|
echo "</tr>"; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
// Last record is just a summary |
141
|
|
|
$i = sizeof($db_rec)-1; |
142
|
|
|
echo "<tr>"; |
143
|
|
|
echo "<th align=left>" . $db_rec[$i]->name . "</th>"; |
144
|
|
|
echo "<th align=left>" . size_format($db_rec[$i]->data_size) . "</th>"; |
145
|
|
|
echo "<th align=left>" . size_format($db_rec[$i]->index_size) . "</th>"; |
146
|
|
|
echo "<th align=left>" . size_format($db_rec[$i]->total_size) . "</th>"; |
147
|
|
|
echo "<th align=left>" . number_format($db_rec[$i]->rows) . "</th>"; |
148
|
|
|
echo "<th align=left></th>"; |
149
|
|
|
echo "</tr>"; |
150
|
|
|
echo "</table>"; |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
// same as show_db_info but with sortable columns |
154
|
|
|
// |
155
|
|
|
function sort_db_info($db_name, $db_rec) { |
156
|
|
|
$file_list = array(); |
157
|
|
|
$file_sort = array(); |
158
|
|
|
|
159
|
|
|
$sort = get_str("sort", true); |
|
|
|
|
160
|
|
|
$r = get_str("r", true); |
161
|
|
|
|
162
|
|
|
if (empty($sort)) $sort = "name"; |
163
|
|
|
// check for allowed keys |
164
|
|
|
if ((strcmp($sort, "name")!=0) && |
165
|
|
|
(strcmp($sort, "data_size")!=0) && |
166
|
|
|
(strcmp($sort, "index_size")!=0) && |
167
|
|
|
(strcmp($sort, "total_size")!=0) && |
|
|
|
|
168
|
|
|
(strcmp($sort, "rows")!=0) && |
169
|
|
|
(strcmp($sort, "size_per_row")!=0) |
170
|
|
|
) { |
171
|
|
|
$sort = "name"; |
172
|
|
|
} |
173
|
|
|
if (empty($r)) $r=0; |
174
|
|
|
|
175
|
|
|
for ($i=0; $i < sizeof($db_rec)-1; $i++){ |
|
|
|
|
176
|
|
|
$file_details["name"] = $db_rec[$i]->name; |
177
|
|
|
$file_details["data_size"] = $db_rec[$i]->data_size; |
178
|
|
|
$file_details["index_size"] = $db_rec[$i]->index_size; |
179
|
|
|
$file_details["total_size"] = $db_rec[$i]->total_size; |
180
|
|
|
$file_details["rows"] = $db_rec[$i]->rows; |
181
|
|
|
$file_details["size_per_row"] = $db_rec[$i]->size_per_row; |
182
|
|
|
|
183
|
|
|
$file_list[$i] = $file_details; |
|
|
|
|
184
|
|
|
$key = strtolower($file_details[$sort]); |
185
|
|
|
$file_sort[$i] = $key; |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
if ($r) { |
189
|
|
|
arsort($file_sort); |
190
|
|
|
} else { |
191
|
|
|
asort($file_sort); |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
echo "<table cols=6>"; |
195
|
|
|
echo "<tr>"; |
196
|
|
|
echo "<th colspan=6> Database $db_name </th>"; |
197
|
|
|
echo "</tr>"; |
198
|
|
|
|
199
|
|
|
echo "<tr>"; |
200
|
|
|
echo "<th><a href='dbinfo.php?sort=name&r=" . (!$r) . "'>Table </a></th>"; |
201
|
|
|
echo "<th><a href='dbinfo.php?sort=data_size&r=" . (!$r) . "'>Data Size</a></th>"; |
202
|
|
|
echo "<th><a href='dbinfo.php?sort=index_size&r=" . (!$r) . "'>Index Size</a></th>"; |
203
|
|
|
echo "<th><a href='dbinfo.php?sort=total_size&r=" . (!$r) . "'>Total Size</a></th>"; |
204
|
|
|
echo "<th><a href='dbinfo.php?sort=rows&r=" . (!$r) . "'>Total Rows</a></th>"; |
205
|
|
|
echo "<th><a href='dbinfo.php?sort=size_per_row&r=" . (!$r) . "'>Avg. Size per Row</a></th>"; |
206
|
|
|
echo "</tr>"; |
207
|
|
|
|
208
|
|
|
foreach ($file_sort as $key=>$value) { |
|
|
|
|
209
|
|
|
$value = $file_list[$key]; |
210
|
|
|
|
211
|
|
|
echo "<tr>"; |
212
|
|
|
echo "<td align=left valign=top class=fieldname>" . $value["name"] . "</td>"; |
213
|
|
|
echo "<td align=left valign=top class=fieldname>" . size_format($value["data_size"]) . "</td>"; |
214
|
|
|
echo "<td align=left valign=top class=fieldname>" . size_format($value["index_size"]) . "</td>"; |
215
|
|
|
echo "<td align=left valign=top class=fieldname>" . size_format($value["total_size"]) . "</td>"; |
216
|
|
|
echo "<td align=left valign=top class=fieldname>" . number_format($value["rows"]) . "</td>"; |
217
|
|
|
echo "<td align=left valign=top class=fieldname>" . size_format($value["size_per_row"]) . "</td>"; |
218
|
|
|
echo "</tr>"; |
219
|
|
|
} |
220
|
|
|
|
221
|
|
|
// Last record is a summary |
222
|
|
|
$i = sizeof($db_rec)-1; |
223
|
|
|
echo "<tr>"; |
224
|
|
|
echo "<th align=left>" . $db_rec[$i]->name . "</th>"; |
225
|
|
|
echo "<th align=left>" . size_format($db_rec[$i]->data_size) . "</th>"; |
226
|
|
|
echo "<th align=left>" . size_format($db_rec[$i]->index_size) . "</th>"; |
227
|
|
|
echo "<th align=left>" . size_format($db_rec[$i]->total_size) . "</th>"; |
228
|
|
|
echo "<th align=left>" . number_format($db_rec[$i]->rows) . "</th>"; |
229
|
|
|
echo "<th align=left></th>"; |
230
|
|
|
echo "</tr>"; |
231
|
|
|
|
232
|
|
|
echo "</table>"; |
233
|
|
|
} |
234
|
|
|
|
235
|
|
|
?> |
236
|
|
|
|