Skip to content

Commit

Permalink
Performance check for dir sizes #172
Browse files Browse the repository at this point in the history
  • Loading branch information
brendanheywood committed Dec 5, 2023
1 parent 6921071 commit cdb34ec
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 2 deletions.
79 changes: 79 additions & 0 deletions classes/check/dirsizes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Dir sizes performance check.
*
* @package tool_heartbeat
* @copyright 2023 Brendan Heywood <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*
*/

namespace tool_heartbeat\check;
use core\check\check;
use core\check\result;

/**
* Dir sizes performance check.
*
* @copyright 2023
* @author Brendan Heywood <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class dirsizes extends check {

/**
* Get Result.
*
* @return result
*/
public function get_result() : result {
global $CFG;

$sizedataroot = get_directory_size($CFG->dataroot);
$summary = $sizedataroot;
$details = "Shared paths:<br>";
$details .= '$CFG->dataroot = ' . display_size($sizedataroot);

$details .= $this->dirsize('themedir');
$details .= $this->dirsize('tempdir');
$details .= $this->dirsize('cachedir');

$host = gethostname();
$details .= "<br><br>Optionally local paths (Host: $host)\n";
$details .= $this->dirsize('localcachedir');
$details .= $this->dirsize('localrequestdir');

return new result(result::INFO, $summary, $details);
}
/**
* Get a paths sizet
* @param string $cfg the path to check
* @return string size for a path as html
*/
private function dirsize(string $cfg) {
global $CFG;
if (!property_exists($CFG, $cfg)) {
return "<br>\$CFG->$cfg not in use";
}
$path = $CFG->{$cfg};
$size = get_directory_size($path);

return "<br>\$CFG->{$cfg} = " . display_size($size);
}

}
1 change: 1 addition & 0 deletions lang/en/tool_heartbeat.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
$string['taskconfigbad'] = 'Bad configurations {$a}';
$string['tasklatencyok'] = 'Task latency OK.';
$string['checkfailingtaskcheck'] = 'Failing tasks';
$string['checkdirsizes'] = 'CFG->dataroot size';

/*
* Privacy provider (GDPR)
Expand Down
1 change: 1 addition & 0 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ function tool_heartbeat_status_checks() {
function tool_heartbeat_performance_checks() {
return [
new \tool_heartbeat\check\rangerequestcheck(),
new \tool_heartbeat\check\dirsizes(),
];
}

Expand Down
4 changes: 2 additions & 2 deletions version.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@

defined('MOODLE_INTERNAL') || die();

$plugin->version = 2023110700;
$plugin->release = 2023110700; // Match release exactly to version.
$plugin->version = 2023120500;
$plugin->release = 2023120500; // Match release exactly to version.
$plugin->requires = 2020061500; // Support for 3.9 and above, due to the Check API.
$plugin->supported = [39, 401];
$plugin->component = 'tool_heartbeat';
Expand Down

0 comments on commit cdb34ec

Please sign in to comment.