Added the database usage statistics.

master
Loic d'Anterroches 2009-06-19 22:42:44 +02:00
parent 6cf4f00f92
commit 0873d44162
2 changed files with 41 additions and 12 deletions

View File

@ -327,8 +327,8 @@ function IDF_Views_Admin_getForgeSize()
.escapeshellarg(Pluf::f('upload_issue_path')); .escapeshellarg(Pluf::f('upload_issue_path'));
$out = split(' ', shell_exec($cmd), 2); $out = split(' ', shell_exec($cmd), 2);
$res['attachments'] = $out[0]*1024; $res['attachments'] = $out[0]*1024;
$res['total'] = $res['repositories'] + $res['downloads'] + $res['attachments']; $res['database'] = IDF_Views_Admin_getForgeDbSize();
// TODO: now we need the db $res['total'] = $res['repositories'] + $res['downloads'] + $res['attachments'] + $res['database'];
return $res; return $res;
} }
@ -339,9 +339,36 @@ function IDF_Views_Admin_getForgeSize()
*/ */
function IDF_Views_Admin_getForgeDbSize() function IDF_Views_Admin_getForgeDbSize()
{ {
$db = Pluf::db();
// MySQL: SHOW TABLE STATUS FROM database; if (Pluf::f('db_engine') == 'SQLite') {
// then sum Data_length and Index_length for each table return filesize(Pluf::f('db_database'));
// PostgreSQL: }
// Directly stats the database file switch (Pluf::f('db_engine')) {
case 'PostgreSQL':
$sql = 'SELECT relname, pg_total_relation_size(relname) AS size FROM pg_class AS pgc, pg_namespace AS pgn
WHERE pg_table_is_visible(pgc.oid) IS TRUE AND relkind = \'r\'
AND pgc.relnamespace = pgn.oid
AND pgn.nspname NOT IN (\'information_schema\', \'pg_catalog\')';
break;
case 'MySQL':
default:
$sql = 'SHOW TABLE STATUS FROM '.Pluf::f('db_database');
break;
}
$rs = $db->select($sql);
$total = 0;
switch (Pluf::f('db_engine')) {
case 'PostgreSQL':
foreach ($rs as $table) {
$total += $table['size'];
}
break;
case 'MySQL':
default:
foreach ($rs as $table) {
$total += $table['Data_length'] + $table['Index_length'];
}
break;
}
return $total;
} }

View File

@ -8,13 +8,15 @@
{block context} {block context}
<div class="issue-submit-info"> <div class="issue-submit-info">
<p><strong>{trans 'Space Usage Statistics'}</strong></p>
<ul> <ul>
<li>{trans 'Repository size:'} {$size['repositories']|size}</li> <li>{trans 'Repositories:'} {$size['repositories']|size}</li>
<li>{trans 'Attachment size:'} {$size['attachments']|size}</li> <li>{trans 'Attachments:'} {$size['attachments']|size}</li>
<li>{trans 'Download size:'} {$size['downloads']|size}</li> <li>{trans 'Downloads:'} {$size['downloads']|size}</li>
<li>{trans 'Forge size:'} {$size['total']|size}</li> <li>{trans 'Database:'} {$size['database']|size}</li>
<li><strong>{trans 'Total Forge:'} {$size['total']|size}</strong></li>
</ul> </ul>
<p>{trans 'The forge size does not include the database space yet.'}</p>
</div> </div>
{/block} {/block}