root / plugins / moodle / moodle_modules_total @ c3660c2a
Historique | Voir | Annoter | Télécharger (2,03 ko)
| 1 | 5ac6279f | ak4t0sh | #!/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 | 9c9c8ee0 | ak4t0sh | * /etc/munin/plugin-conf.d/moodle.conf |
| 9 | 5ac6279f | ak4t0sh | * |
| 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 | |||
| 36 | |||
| 37 | try {
|
||
| 38 | $dsn = $type . ':host=' . $host . ';port=' . $port . ';dbname=' . $db; |
||
| 39 | $dbh = new PDO($dsn, $user, $pass); |
||
| 40 | } catch (Exception $e) {
|
||
| 41 | echo "Connection failed\n"; |
||
| 42 | exit(1); |
||
| 43 | } |
||
| 44 | //All users |
||
| 45 | $data = array(); |
||
| 46 | 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) {
|
||
| 47 | $data = $stmt->fetchAll(PDO::FETCH_OBJ); |
||
| 48 | } |
||
| 49 | |||
| 50 | if (count($argv) === 2 && $argv[1] === 'config') {
|
||
| 51 | echo "graph_title Moodle Modules\n"; |
||
| 52 | echo "graph_args --base 1000 --lower-limit 0\n"; |
||
| 53 | echo "graph_vlabel modules\n"; |
||
| 54 | echo "graph_category Moodle\n"; |
||
| 55 | echo "graph_scale no\n"; |
||
| 56 | echo "graph_info Displays the sum of module, as well as module instance number by type, in your Moodle site\n"; |
||
| 57 | a116a259 | ak4t0sh | echo "graph_total total\n"; |
| 58 | e0ed2449 | ak4t0sh | $draw = "AREA"; |
| 59 | 5ac6279f | ak4t0sh | foreach($data as $entry) {
|
| 60 | echo "modules_".$entry->modulename.".label ".$entry->modulename."\n"; |
||
| 61 | echo "modules_".$entry->modulename.".min 0\n"; |
||
| 62 | e0ed2449 | ak4t0sh | echo "modules_".$entry->modulename.".draw $draw\n"; |
| 63 | $draw = "STACK"; |
||
| 64 | 5ac6279f | ak4t0sh | } |
| 65 | exit(0); |
||
| 66 | } |
||
| 67 | foreach($data as $entry) {
|
||
| 68 | echo "modules_".$entry->modulename.".label ".$entry->modulename."\n"; |
||
| 69 | echo "modules_".$entry->modulename.".value ".$entry->moduleinstance."\n"; |
||
| 70 | c31b957b | ak4t0sh | } |
