root / plugins / moodle / moodle_logs.php @ b9f9e90a
Historique | Voir | Annoter | Télécharger (1,53 ko)
| 1 | b9f9e90a | ak4t0sh | #!/usr/bin/php |
|---|---|---|---|
| 2 | <?php
|
||
| 3 | /**
|
||
| 4 | * Moodle Logs
|
||
| 5 | * Munin plugin to count logs entries
|
||
| 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 | $dbh = null; |
||
| 25 | $db = getenv('db'); |
||
| 26 | $type = getenv('type'); |
||
| 27 | $host = getenv('host'); |
||
| 28 | $user = getenv('user'); |
||
| 29 | $pass = getenv('pass'); |
||
| 30 | $table_prefix = getenv('table_prefix'); |
||
| 31 | $port = getenv('port'); |
||
| 32 | if (!$port) |
||
| 33 | $port = 3306; |
||
| 34 | //$graph_period = getenv('graph_period');
|
||
| 35 | $graph_period = time() - 5*60; |
||
| 36 | |||
| 37 | if (count($argv) === 2 && $argv[1] === 'config') { |
||
| 38 | echo "graph_title Moodle Logs\n"; |
||
| 39 | echo "graph_args --base 1000 --lower-limit 0\n"; |
||
| 40 | echo "graph_vlabel logs\n"; |
||
| 41 | echo "graph_category Moodle\n"; |
||
| 42 | echo "graph_scale no\n"; |
||
| 43 | echo "graph_info Displays the number of new logs written\n"; |
||
| 44 | echo "logs.label logs\n"; |
||
| 45 | echo "logs.min 0\n"; |
||
| 46 | exit(0); |
||
| 47 | } |
||
| 48 | |||
| 49 | try {
|
||
| 50 | $dsn = $type . ':host=' . $host . ';port=' . $port . ';dbname=' . $db; |
||
| 51 | $dbh = new PDO($dsn, $user, $pass); |
||
| 52 | } catch (Exception $e) { |
||
| 53 | echo "Connection failed\n"; |
||
| 54 | exit(1); |
||
| 55 | } |
||
| 56 | |||
| 57 | //Online users
|
||
| 58 | $nb = 0; |
||
| 59 | if (($stmt = $dbh->query("SELECT count(id) FROM {$table_prefix}log WHERE time > $graph_period")) != false) { |
||
| 60 | $nbusers = $stmt->fetchColumn(); |
||
| 61 | } |
||
| 62 | echo "logs.value $nb\n"; |
