root / plugins / moodle / moodle_mod_chat @ a8d024ac
Historique | Voir | Annoter | Télécharger (1,91 ko)
| 1 |
#!/usr/bin/php |
|---|---|
| 2 |
<?php |
| 3 |
/** |
| 4 |
* Moodle module chat |
| 5 |
* Munin plugin to count users in chat sessions |
| 6 |
* |
| 7 |
* It's required to define a container entry for this plugin in your |
| 8 |
* /etc/munin/plugin-conf.d/moodle.conf |
| 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 = time() - 5*60; |
| 35 |
|
| 36 |
|
| 37 |
if (count($argv) === 2 && $argv[1] === 'config') {
|
| 38 |
echo "graph_title Moodle Chat Users\n"; |
| 39 |
echo "graph_args --base 1000 --lower-limit 0\n"; |
| 40 |
echo "graph_vlabel users\n"; |
| 41 |
echo "graph_category cms\n"; |
| 42 |
echo "graph_scale no\n"; |
| 43 |
echo "graph_info Displays the number of users connected and posting message in chat sessions\n"; |
| 44 |
echo "chat_users_connected.label users connected\n"; |
| 45 |
echo "chat_users_connected.min 0\n"; |
| 46 |
echo "chat_users_active.label users posting messages\n"; |
| 47 |
echo "chat_users_active.min 0\n"; |
| 48 |
exit(0); |
| 49 |
} |
| 50 |
|
| 51 |
try {
|
| 52 |
$dsn = $type . ':host=' . $host . ';port=' . $port . ';dbname=' . $db; |
| 53 |
$dbh = new PDO($dsn, $user, $pass); |
| 54 |
} catch (Exception $e) {
|
| 55 |
echo "Connection failed\n"; |
| 56 |
exit(1); |
| 57 |
} |
| 58 |
|
| 59 |
//Connected |
| 60 |
$nb=0; |
| 61 |
if (($stmt = $dbh->query("SELECT COUNT(DISTINCT userid) FROM {$table_prefix}chat_users WHERE lastping > $graph_period")) != false) {
|
| 62 |
$nb = $stmt->fetchColumn(); |
| 63 |
} |
| 64 |
echo "chat_users_connected.value $nb\n"; |
| 65 |
|
| 66 |
//Active |
| 67 |
$nb=0; |
| 68 |
if (($stmt = $dbh->query("SELECT COUNT(DISTINCT userid) FROM {$table_prefix}chat_users WHERE lastmessageping > $graph_period")) != false) {
|
| 69 |
$nb = $stmt->fetchColumn(); |
| 70 |
} |
| 71 |
echo "chat_users_active.value $nb\n"; |
