root / plugins / moodle / moodle_logs @ eaf6c2d7
Historique | Voir | Annoter | Télécharger (1,7 ko)
| 1 | b9f9e90a | ak4t0sh | #!/usr/bin/php |
|---|---|---|---|
| 2 | <?php |
||
| 3 | /** |
||
| 4 | * Moodle Logs |
||
| 5 | * Munin plugin to count logs entries |
||
| 6 | * |
||
| 7 | eb2979cb | ak4t0sh | * Note : This plugin does not support Moodle 2.7 or newer versions |
| 8 | * If you want to use this plugin with Moodle 2.7 you have to enable logstore_legacy mode in your Moodle settings |
||
| 9 | * |
||
| 10 | b9f9e90a | ak4t0sh | * It's required to define a container entry for this plugin in your |
| 11 | 9c9c8ee0 | ak4t0sh | * /etc/munin/plugin-conf.d/moodle.conf |
| 12 | b9f9e90a | ak4t0sh | * |
| 13 | * @example Example entry for configuration: |
||
| 14 | * [moodle*] |
||
| 15 | * env.type mysql |
||
| 16 | * env.db moodle |
||
| 17 | * env.user mysql_user |
||
| 18 | * env.pass mysql_pass |
||
| 19 | * env.host localhost |
||
| 20 | * env.port 3306 |
||
| 21 | * env.table_prefix mdl_ |
||
| 22 | * |
||
| 23 | * @author Arnaud Trouvé <ak4t0sh@free.fr> |
||
| 24 | * @version 1.0 2014 |
||
| 25 | * |
||
| 26 | */ |
||
| 27 | $dbh = null; |
||
| 28 | $db = getenv('db');
|
||
| 29 | $type = getenv('type');
|
||
| 30 | $host = getenv('host');
|
||
| 31 | $user = getenv('user');
|
||
| 32 | $pass = getenv('pass');
|
||
| 33 | $table_prefix = getenv('table_prefix');
|
||
| 34 | $port = getenv('port');
|
||
| 35 | if (!$port) |
||
| 36 | $port = 3306; |
||
| 37 | //$graph_period = getenv('graph_period');
|
||
| 38 | $graph_period = time() - 5*60; |
||
| 39 | |||
| 40 | if (count($argv) === 2 && $argv[1] === 'config') {
|
||
| 41 | echo "graph_title Moodle Logs\n"; |
||
| 42 | echo "graph_args --base 1000 --lower-limit 0\n"; |
||
| 43 | echo "graph_vlabel logs\n"; |
||
| 44 | eaf6c2d7 | dipohl | echo "graph_category cms\n"; |
| 45 | b9f9e90a | ak4t0sh | echo "graph_scale no\n"; |
| 46 | echo "graph_info Displays the number of new logs written\n"; |
||
| 47 | echo "logs.label logs\n"; |
||
| 48 | echo "logs.min 0\n"; |
||
| 49 | 79e9b2b9 | ak4t0sh | echo "logs.draw AREA"; |
| 50 | b9f9e90a | ak4t0sh | exit(0); |
| 51 | } |
||
| 52 | |||
| 53 | try {
|
||
| 54 | $dsn = $type . ':host=' . $host . ';port=' . $port . ';dbname=' . $db; |
||
| 55 | $dbh = new PDO($dsn, $user, $pass); |
||
| 56 | } catch (Exception $e) {
|
||
| 57 | echo "Connection failed\n"; |
||
| 58 | exit(1); |
||
| 59 | } |
||
| 60 | |||
| 61 | //Online users |
||
| 62 | $nb = 0; |
||
| 63 | if (($stmt = $dbh->query("SELECT count(id) FROM {$table_prefix}log WHERE time > $graph_period")) != false) {
|
||
| 64 | $nbusers = $stmt->fetchColumn(); |
||
| 65 | } |
||
| 66 | echo "logs.value $nb\n"; |
