Projet

Général

Profil

Paste
Télécharger au format
Statistiques
| Branche: | Révision:

root / plugins / moodle / moodle_modules_total.php @ ac1f67b2

Historique | Voir | Annoter | Télécharger (2,09 ko)

1
#!/usr/bin/php
2
<?php
3
/**
4
 * Moodle Modules Total
5
 * Munin plugin to count total modules instances
6
 *
7
 * It's required to define a container entry for this plugin in your
8
 * /etc/munin/plugin-conf.d/munin-node (or a separate and dedicated file).
9
 *
10
 * @example Example entry for configuration:
11
 * [moodle*]
12
 * env.type mysql
13
 * env.db moodle
14
 * env.user mysql_user
15
 * env.pass mysql_pass
16
 * env.host localhost
17
 * env.port 3306
18
 * env.table_prefix mdl_
19
 *
20
 * @author Arnaud Trouvé <ak4t0sh@free.fr>
21
 * @version 1.0 2014
22
 *
23
 */
24

    
25
$dbh = null;
26
$db = getenv('db');
27
$type = getenv('type');
28
$host = getenv('host');
29
$user = getenv('user');
30
$pass = getenv('pass');
31
$table_prefix = getenv('table_prefix');
32
$port = getenv('port');
33
if (!$port)
34
    $port = 3306;
35
//$graph_period = getenv('graph_period');
36
$graph_period = time() - 5*60;
37

    
38

    
39
try {
40
    $dsn = $type . ':host=' . $host . ';port=' . $port . ';dbname=' . $db;
41
    $dbh = new PDO($dsn, $user, $pass);
42
} catch (Exception $e) {
43
    echo "Connection failed\n";
44
    exit(1);
45
}
46
//All users
47
$data = array();
48
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) {
49
    $data = $stmt->fetchAll(PDO::FETCH_OBJ);
50
}
51

    
52
if (count($argv) === 2 && $argv[1] === 'config') {
53
    echo "graph_title Moodle Modules\n";
54
    echo "graph_args --base 1000 --lower-limit 0\n";
55
    echo "graph_vlabel modules\n";
56
    echo "graph_category Moodle\n";
57
    echo "graph_scale no\n";
58
    echo "graph_info Displays the sum of module, as well as module instance number by type, in your Moodle site\n";
59
    echo "graph_total.label total\n";
60

    
61
    foreach($data as $entry) {
62
        echo "modules_".$entry->modulename.".label ".$entry->modulename."\n";
63
        echo "modules_".$entry->modulename.".min 0\n";
64
        echo "modules_".$entry->modulename.".draw AREA\n";
65
    }
66
    exit(0);
67
}
68
foreach($data as $entry) {
69
    echo "modules_".$entry->modulename.".label ".$entry->modulename."\n";
70
    echo "modules_".$entry->modulename.".value ".$entry->moduleinstance."\n";
71
}