mirror of
https://github.com/munin-monitoring/contrib.git
synced 2025-07-22 14:16:00 +00:00
add module plugin
This commit is contained in:
parent
43c4646592
commit
5ac6279f44
1 changed files with 75 additions and 0 deletions
75
plugins/moodle/moodle_modules_total.php
Normal file
75
plugins/moodle/moodle_modules_total.php
Normal file
|
@ -0,0 +1,75 @@
|
||||||
|
#!/usr/bin/php
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Moodle Modules Total
|
||||||
|
* Munin plugin to count total modules instances
|
||||||
|
*
|
||||||
|
* It's required to define a container entry for this plugin in your
|
||||||
|
* /etc/munin/plugin-conf.d/munin-node (or a separate and dedicated file).
|
||||||
|
*
|
||||||
|
* @example Example entry for configuration:
|
||||||
|
* [moodle*]
|
||||||
|
* env.type mysql
|
||||||
|
* env.db moodle
|
||||||
|
* env.user mysql_user
|
||||||
|
* env.pass mysql_pass
|
||||||
|
* env.host localhost
|
||||||
|
* env.port 3306
|
||||||
|
* env.table_prefix mdl_
|
||||||
|
*
|
||||||
|
* @author Arnaud Trouvé <ak4t0sh@free.fr>
|
||||||
|
* @version 1.0 2014
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
$dbh = null;
|
||||||
|
$db = getenv('db');
|
||||||
|
$type = getenv('type');
|
||||||
|
$host = getenv('host');
|
||||||
|
$user = getenv('user');
|
||||||
|
$pass = getenv('pass');
|
||||||
|
$table_prefix = getenv('table_prefix');
|
||||||
|
$port = getenv('port');
|
||||||
|
if (!$port)
|
||||||
|
$port = 3306;
|
||||||
|
//$graph_period = getenv('graph_period');
|
||||||
|
$graph_period = time() - 5*60;
|
||||||
|
|
||||||
|
|
||||||
|
try {
|
||||||
|
$dsn = $type . ':host=' . $host . ';port=' . $port . ';dbname=' . $db;
|
||||||
|
$dbh = new PDO($dsn, $user, $pass);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
echo "Connection failed\n";
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
//All users
|
||||||
|
$data = array();
|
||||||
|
if (($stmt = $dbh->query("SELECT m.name as modulename, count(cm.id) as moduleinstance FROM {$table_prefix}modules m, {$table_prefix}course_modules cm WHERE cm.module=m.id GROUP BY cm.module ORDER BY m.name ASC")) != false) {
|
||||||
|
$data = $stmt->fetchAll(PDO::FETCH_OBJ);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (count($argv) === 2 && $argv[1] === 'config') {
|
||||||
|
echo "graph_title Moodle Modules\n";
|
||||||
|
echo "graph_args --base 1000 --lower-limit 0\n";
|
||||||
|
echo "graph_vlabel modules\n";
|
||||||
|
echo "graph_category Moodle\n";
|
||||||
|
echo "graph_scale no\n";
|
||||||
|
echo "graph_info Displays the sum of module, as well as module instance number by type, in your Moodle site\n";
|
||||||
|
|
||||||
|
foreach($data as $entry) {
|
||||||
|
echo "modules_".$entry->modulename.".label ".$entry->modulename."\n";
|
||||||
|
echo "modules_".$entry->modulename.".min 0\n";
|
||||||
|
echo "modules_".$entry->modulename.".draw AREA\n";
|
||||||
|
}
|
||||||
|
echo "modules_total.label total users\n";
|
||||||
|
echo "modules_total.min 0\n";
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
$total = 0;
|
||||||
|
foreach($data as $entry) {
|
||||||
|
echo "modules_".$entry->modulename.".label ".$entry->modulename."\n";
|
||||||
|
echo "modules_".$entry->modulename.".value ".$entry->moduleinstance."\n";
|
||||||
|
$total += $entry->moduleinstance;
|
||||||
|
}
|
||||||
|
echo "modules_total.value $total\n";
|
Loading…
Add table
Add a link
Reference in a new issue