Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
mahara
mahara
Commits
56d51140
Commit
56d51140
authored
Jan 15, 2010
by
Richard Mansfield
Browse files
Display disk usage
Signed-off-by:
Richard Mansfield
<
richardm@catalyst.net.nz
>
parent
636e8972
Changes
6
Hide whitespace changes
Inline
Side-by-side
htdocs/lib/db/upgrade.php
View file @
56d51140
...
...
@@ -1336,7 +1336,7 @@ function xmldb_core_upgrade($oldversion=0) {
$table
->
addKeyInfo
(
'primary'
,
XMLDB_KEY_PRIMARY
,
array
(
'ctime'
,
'type'
));
create_table
(
$table
);
// Insert
a
cron job to save
weekly
site data
// Insert cron job
s
to save site data
$cron
=
new
StdClass
;
$cron
->
callfunction
=
'cron_site_data_weekly'
;
$cron
->
minute
=
55
;
...
...
@@ -1345,6 +1345,15 @@ function xmldb_core_upgrade($oldversion=0) {
$cron
->
month
=
'*'
;
$cron
->
dayofweek
=
6
;
insert_record
(
'cron'
,
$cron
);
$cron
=
new
StdClass
;
$cron
->
callfunction
=
'cron_site_data_daily'
;
$cron
->
minute
=
51
;
$cron
->
hour
=
23
;
$cron
->
day
=
'*'
;
$cron
->
month
=
'*'
;
$cron
->
dayofweek
=
'*'
;
insert_record
(
'cron'
,
$cron
);
}
return
$status
;
...
...
htdocs/lib/function.dirsize.php
0 → 100644
View file @
56d51140
<?php
/**
* Calculate the size of a directory by iterating its contents
*
* @author Aidan Lister <aidan@php.net>
* @version 1.2.0
* @link http://aidanlister.com/repos/v/function.dirsize.php
* @param string $directory Path to directory
*/
function
dirsize
(
$path
)
{
// Init
$size
=
0
;
// Trailing slash
if
(
substr
(
$path
,
-
1
,
1
)
!==
DIRECTORY_SEPARATOR
)
{
$path
.
=
DIRECTORY_SEPARATOR
;
}
// Sanity check
if
(
is_file
(
$path
))
{
return
filesize
(
$path
);
}
elseif
(
!
is_dir
(
$path
))
{
return
false
;
}
// Iterate queue
$queue
=
array
(
$path
);
for
(
$i
=
0
,
$j
=
count
(
$queue
);
$i
<
$j
;
++
$i
)
{
// Open directory
$parent
=
$i
;
if
(
is_dir
(
$queue
[
$i
])
&&
$dir
=
@
dir
(
$queue
[
$i
]))
{
$subdirs
=
array
();
while
(
false
!==
(
$entry
=
$dir
->
read
()))
{
// Skip pointers
if
(
$entry
==
'.'
||
$entry
==
'..'
)
{
continue
;
}
// Get list of directories or filesizes
$path
=
$queue
[
$i
]
.
$entry
;
if
(
is_dir
(
$path
))
{
$path
.
=
DIRECTORY_SEPARATOR
;
$subdirs
[]
=
$path
;
}
elseif
(
is_file
(
$path
))
{
$size
+=
filesize
(
$path
);
}
}
// Add subdirectories to start of queue
unset
(
$queue
[
0
]);
$queue
=
array_merge
(
$subdirs
,
$queue
);
// Recalculate stack size
$i
=
-
1
;
$j
=
count
(
$queue
);
// Clean up
$dir
->
close
();
unset
(
$dir
);
}
}
return
$size
;
}
?>
\ No newline at end of file
htdocs/lib/mahara.php
View file @
56d51140
...
...
@@ -2230,6 +2230,22 @@ function cron_site_data_weekly() {
));
}
function
cron_site_data_daily
()
{
$time
=
db_format_timestamp
(
time
());
require_once
(
'function.dirsize.php'
);
if
(
$diskusage
=
dirsize
(
get_config
(
'dataroot'
)))
{
// Currently there is no need to track disk usage
// over time, so delete old records first.
delete_records
(
'site_data'
,
'type'
,
'disk-usage'
);
insert_record
(
'site_data'
,
(
object
)
array
(
'ctime'
=>
$time
,
'type'
=>
'disk-usage'
,
'value'
=>
$diskusage
,
));
}
}
function
random_string
(
$length
=
15
)
{
$pool
=
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
;
$poollen
=
strlen
(
$pool
);
...
...
htdocs/lib/registration.php
View file @
56d51140
...
...
@@ -208,6 +208,7 @@ function site_statistics() {
$data
[
'release'
]
=
get_config
(
'release'
);
$data
[
'version'
]
=
get_config
(
'version'
);
$data
[
'dbsize'
]
=
db_total_size
();
$data
[
'diskusage'
]
=
get_field
(
'site_data'
,
'value'
,
'type'
,
'disk-usage'
);
return
(
$data
);
}
...
...
htdocs/lib/upgrade.php
View file @
56d51140
...
...
@@ -772,6 +772,7 @@ function core_install_firstcoredata_defaults() {
'export_cleanup_old_exports'
=>
array
(
'0'
,
'3,15'
,
'*'
,
'*'
,
'*'
),
'import_cleanup_old_imports'
=>
array
(
'0'
,
'4,16'
,
'*'
,
'*'
,
'*'
),
'cron_site_data_weekly'
=>
array
(
'55'
,
'23'
,
'*'
,
'*'
,
'6'
),
'cron_site_data_daily'
=>
array
(
'51'
,
'23'
,
'*'
,
'*'
,
'*'
),
);
foreach
(
$cronjobs
as
$callfunction
=>
$times
)
{
$cron
=
new
StdClass
;
...
...
htdocs/theme/raw/templates/admin/stats.tpl
View file @
56d51140
...
...
@@ -13,7 +13,7 @@ addLoadEvent(function () {literal}{{/literal}
<p><strong>
{
str
tag
=
groups
}
:
</strong>
{
$sitedata.groups
}{
if
$sitedata.rank.groups
}
(
{
str
tag
=
Rank
section
=
admin
}
: $sitedata.rank.groups})
{/
if
}
</p>
<p><strong>
{
str
tag
=
views
}
:
</strong>
{
$sitedata.views
}{
if
$sitedata.rank.views
}
(
{
str
tag
=
Rank
section
=
admin
}
: $sitedata.rank.views})
{/
if
}
</p>
<p><strong>
{
str
tag
=
databasesize
section
=
admin
}
:
</strong>
{
$sitedata.dbsize
|
display_size
}
</p>
<
!--
p><strong>
{
str
tag
=
diskusage
section
=
admin
}
:</strong></p
--
>
<p><strong>
{
str
tag
=
diskusage
section
=
admin
}
:
</strong>
{
$sitedata.diskusage
|
display_size
}
</p>
<p><strong>
{
str
tag
=
maharaversion
section
=
admin
}
:
</strong>
{
$sitedata.release
}
</p>
</div>
<div
class=
"cb"
></div>
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment