Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
// This file is part of Moodle - http://moodle.org/
3
//
4
// Moodle is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8
//
9
// Moodle is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13
//
14
// You should have received a copy of the GNU General Public License
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
16
 
17
/**
18
 * Admin tool "Opcache management" - Nagios monitoring check, part "web"
19
 *
20
 * @package    tool_opcache
21
 * @copyright  2017 Alexander Bias, Ulm University <alexander.bias@uni-ulm.de>
22
 * @copyright  inspired by code by Mikanoshi, https://exchange.icinga.com/Mikanoshi/PHP+opcache+monitoring+plugin
23
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24
 */
25
 
26
// @codingStandardsIgnoreFile
27
// Let codechecker ignore this file because otherwise it would complain about a missing MOODLE_INTERNAL check or config.php
28
// inclusion which is really not needed.
29
 
30
require(__DIR__.'/../../../../config.php');
31
 
32
global $CFG, $PAGE;
33
 
34
// Die if secret key is set but the submitted secret key is not correct.
35
if (isset($CFG->tool_opcache_check_secretkey) &&
36
            $CFG->tool_opcache_check_secretkey != clean_param($PAGE->url->get_param('secret'), PARAM_ALPHANUM)) {
37
    echo 'FORBIDDEN';
38
    exit;
39
}
40
 
41
// Get Opcache status.
42
$opcache = opcache_get_status();
43
 
44
// Pick and calculate Opcache figures.
45
$used = $opcache['memory_usage']['used_memory'];
46
$free = $opcache['memory_usage']['free_memory'];
47
$totalreq = $opcache['opcache_statistics']['blacklist_misses'] + $opcache['opcache_statistics']['misses'] +
48
        $opcache['opcache_statistics']['hits'];
49
$hitspct = round($opcache['opcache_statistics']['opcache_hit_rate'], 2, PHP_ROUND_HALF_UP);
50
$misspct = round($opcache['opcache_statistics']['misses'] / $totalreq * 100, 2, PHP_ROUND_HALF_UP);
51
 
52
// Echo Opcache figures.
53
echo $used."\r\n".$free."\r\n".$hitspct."\r\n".$misspct;