InDefero

Sign in or create your account | Project List | Help

InDefero Commit Details

Date:2009-06-19 22:42:44 (9 months 1 day ago)
Author:Loïc d'Anterroches
Commit:0873d4416232e2170b29f8897a2cc23b5b55ac28
Message:Added the database usage statistics.

Files: src/IDF/Views/Admin.php (2 diffs)
src/IDF/templates/idf/gadmin/projects/index.html (1 diff)

Change Details

src/IDF/Views/Admin.php
327327        .escapeshellarg(Pluf::f('upload_issue_path'));
328328    $out = split(' ', shell_exec($cmd), 2);
329329    $res['attachments'] = $out[0]*1024;
330    $res['total'] = $res['repositories'] + $res['downloads'] + $res['attachments'];
331    // TODO: now we need the db
330    $res['database'] = IDF_Views_Admin_getForgeDbSize();
331    $res['total'] = $res['repositories'] + $res['downloads'] + $res['attachments'] + $res['database'];
332332    return $res;
333333}
334334
...... 
339339 */
340340function IDF_Views_Admin_getForgeDbSize()
341341{
342
343    // MySQL: SHOW TABLE STATUS FROM database;
344    // then sum Data_length and Index_length for each table
345    // PostgreSQL:
346    // Directly stats the database file
342    $db = Pluf::db();
343    if (Pluf::f('db_engine') == 'SQLite') {
344        return filesize(Pluf::f('db_database'));
345    }
346    switch (Pluf::f('db_engine')) {
347    case 'PostgreSQL':
348        $sql = 'SELECT relname, pg_total_relation_size(relname) AS size FROM pg_class AS pgc, pg_namespace AS pgn
349     WHERE pg_table_is_visible(pgc.oid) IS TRUE AND relkind = \'r\'
350     AND pgc.relnamespace = pgn.oid
351     AND pgn.nspname NOT IN (\'information_schema\', \'pg_catalog\')';
352        break;
353    case 'MySQL':
354    default:
355        $sql = 'SHOW TABLE STATUS FROM '.Pluf::f('db_database');
356        break;
357    }
358    $rs = $db->select($sql);
359    $total = 0;
360    switch (Pluf::f('db_engine')) {
361    case 'PostgreSQL':
362        foreach ($rs as $table) {
363            $total += $table['size'];
364        }
365        break;
366    case 'MySQL':
367    default:
368        foreach ($rs as $table) {
369            $total += $table['Data_length'] + $table['Index_length'];
370        }
371        break;
372    }
373    return $total;
347374}
src/IDF/templates/idf/gadmin/projects/index.html
88
99{block context}
1010<div class="issue-submit-info">
11<p><strong>{trans 'Space Usage Statistics'}</strong></p>
1112<ul>
12<li>{trans 'Repository size:'} {$size['repositories']|size}</li>
13<li>{trans 'Attachment size:'} {$size['attachments']|size}</li>
14<li>{trans 'Download size:'} {$size['downloads']|size}</li>
15<li>{trans 'Forge size:'} {$size['total']|size}</li>
13<li>{trans 'Repositories:'} {$size['repositories']|size}</li>
14<li>{trans 'Attachments:'} {$size['attachments']|size}</li>
15<li>{trans 'Downloads:'} {$size['downloads']|size}</li>
16<li>{trans 'Database:'} {$size['database']|size}</li>
17<li><strong>{trans 'Total Forge:'} {$size['total']|size}</strong></li>
1618</ul>
17<p>{trans 'The forge size does not include the database space yet.'}</p>
19
1820</div>
1921{/block}
2022

Archive Download the corresponding diff file

Branches:
dev
master
newdiff
svn