diff --git a/plugins/moodle/modules/moodle_mod_chat.php b/plugins/moodle/modules/moodle_mod_chat.php new file mode 100644 index 00000000..7db3fd8f --- /dev/null +++ b/plugins/moodle/modules/moodle_mod_chat.php @@ -0,0 +1,71 @@ +#!/usr/bin/php + + * @version 1.0 2014 + * + */ +$dbh = null; +$db = getenv('db'); +$type = getenv('type'); +$host = getenv('host'); +$user = getenv('user'); +$pass = getenv('pass'); +$table_prefix = getenv('table_prefix'); +$port = getenv('port'); +if (!$port) + $port = 3306; +$graph_period = time() - 5*60; + + +if (count($argv) === 2 && $argv[1] === 'config') { + echo "graph_title Moodle Chat Users\n"; + echo "graph_args --base 1000 --lower-limit 0\n"; + echo "graph_vlabel users\n"; + echo "graph_category Moodle\n"; + echo "graph_scale no\n"; + echo "graph_info Displays the number of users connected and posting message in chat sessions\n"; + echo "chat_users_connected.label users connected\n"; + echo "chat_users_connected.min 0\n"; + echo "chat_users_active.label users posting messages\n"; + echo "chat_users_active.min 0\n"; + exit(0); +} + +try { + $dsn = $type . ':host=' . $host . ';port=' . $port . ';dbname=' . $db; + $dbh = new PDO($dsn, $user, $pass); +} catch (Exception $e) { + echo "Connection failed\n"; + exit(1); +} + +//Connected +$nb=0; +if (($stmt = $dbh->query("SELECT COUNT(DISTINCT userid) FROM {$table_prefix}chat_users WHERE lastping > $graph_period")) != false) { + $nb = $stmt->fetchColumn(); +} +echo "chat_users_connected.value $nb\n"; + +//Active +$nb=0; +if (($stmt = $dbh->query("SELECT COUNT(DISTINCT userid) FROM {$table_prefix}chat_users WHERE lastmessageping > $graph_period")) != false) { + $nb = $stmt->fetchColumn(); +} +echo "chat_users_active.value $nb\n"; diff --git a/plugins/moodle/modules/moodle_mod_forum.php b/plugins/moodle/modules/moodle_mod_forum.php index 884e2789..363a6be8 100644 --- a/plugins/moodle/modules/moodle_mod_forum.php +++ b/plugins/moodle/modules/moodle_mod_forum.php @@ -5,7 +5,7 @@ * Munin plugin to count new posts on forums * * It's required to define a container entry for this plugin in your - * /etc/munin/plugin-conf.d/munin-node (or a separate and dedicated file). + * /etc/munin/plugin-conf.d/moodle.conf * * @example Example entry for configuration: * [moodle*] diff --git a/plugins/moodle/modules/moodle_mod_quiz.php b/plugins/moodle/modules/moodle_mod_quiz.php index 3a6f9705..6e270744 100644 --- a/plugins/moodle/modules/moodle_mod_quiz.php +++ b/plugins/moodle/modules/moodle_mod_quiz.php @@ -5,7 +5,7 @@ * Munin plugin to count new quiz attempts * * It's required to define a container entry for this plugin in your - * /etc/munin/plugin-conf.d/munin-node (or a separate and dedicated file). + * /etc/munin/plugin-conf.d/moodle.conf * * @example Example entry for configuration: * [moodle*] diff --git a/plugins/moodle/moodle_files.php b/plugins/moodle/moodle_files.php new file mode 100644 index 00000000..dedd897a --- /dev/null +++ b/plugins/moodle/moodle_files.php @@ -0,0 +1,135 @@ +#!/usr/bin/php + + * @version 1.0 2014 + * + */ +$dbh = null; +$db = getenv('db'); +$type = getenv('type'); +$host = getenv('host'); +$user = getenv('user'); +$pass = getenv('pass'); +$table_prefix = getenv('table_prefix'); +$port = getenv('port'); +if (!$port) + $port = 3306; + + +try { + $dsn = $type . ':host=' . $host . ';port=' . $port . ';dbname=' . $db; + $dbh = new PDO($dsn, $user, $pass); +} catch (Exception $e) { + echo "Connection failed\n"; + exit(1); +} + + +$data = array(); +if (($stmt = $dbh->query("SELECT COUNT(id) as nbfiles, mimetype, SUM(filesize) as totalfilesize FROM {$table_prefix}files WHERE filesize > 0 GROUP BY mimetype")) !== false) { + foreach($stmt->fetchAll(PDO::FETCH_OBJ) as $entry) { + $mimetype = preg_split('#/#', $entry->mimetype); + if (count($mimetype) > 0) { + if (!array_key_exists($mimetype[0], $data)) { + $data[$mimetype[0]] = new stdClass(); + $data[$mimetype[0]]->totalfiles = 0; + $data[$mimetype[0]]->filesize = 0; + } + $data[$mimetype[0]]->totalfiles += $entry->nbfiles; + $data[$mimetype[0]]->filesize += $entry->totalfilesize; + } + } + ksort($data); +} + +if (count($argv) === 2 && $argv[1] === 'config') { + echo "multigraph file_number\n"; + echo "graph_title Moodle Files Number\n"; + echo "graph_args --base 1000 --lower-limit 0\n"; + echo "graph_vlabel files\n"; + echo "graph_category Moodle\n"; + echo "graph_scale no\n"; + echo "graph_total total\n"; + echo "graph_info Displays the total number of moodle users files and repartition by type\n"; + + $draw = "AREA"; + foreach (array_keys($data) as $mimetype) { + echo $mimetype."_number.label $mimetype\n"; + echo $mimetype."_number.min 0\n"; + echo $mimetype."_number.draw $draw\n"; + $draw = "STACK"; + } + echo "multigraph file_size\n"; + echo "graph_title Moodle Files Size\n"; + echo "graph_args --base 1024 --lower-limit 0\n"; + echo "graph_vlabel size\n"; + echo "graph_category Moodle\n"; + echo "graph_scale no\n"; + echo "graph_total total\n"; + echo "graph_info Displays the total size of moodle users files and repartition by type\n"; + + $draw = "AREA"; + foreach (array_keys($data) as $mimetype) { + echo $mimetype."_size.label $mimetype\n"; + echo $mimetype."_size.min 0\n"; + echo $mimetype."_size.draw $draw\n"; + $draw = "STACK"; + } + exit(0); +} + +echo "multigraph file_number\n"; +echo "graph_title Moodle Files Number\n"; +echo "graph_args --base 1000 --lower-limit 0\n"; +echo "graph_vlabel files\n"; +echo "graph_category Moodle\n"; +echo "graph_scale no\n"; +echo "graph_total total\n"; +echo "graph_info Displays the total number of moodle users files and repartition by type\n"; + +$draw = "AREA"; +foreach (array_keys($data) as $mimetype) { + echo $mimetype."_number.label $mimetype\n"; + echo $mimetype."_number.min 0\n"; + echo $mimetype."_number.draw $draw\n"; + $draw = "STACK"; +} +foreach ($data as $mimetype => $entry) { + echo $mimetype."_number.value ".$entry->totalfiles."\n"; +} +echo "multigraph file_size\n"; +echo "graph_title Moodle Files Size\n"; +echo "graph_args --base 1024 --lower-limit 0\n"; +echo "graph_vlabel size\n"; +echo "graph_category Moodle\n"; +echo "graph_scale no\n"; +echo "graph_total total\n"; +echo "graph_info Displays the total size of moodle users files and repartition by type\n"; + +$draw = "AREA"; +foreach (array_keys($data) as $mimetype) { + echo $mimetype."_size.label $mimetype\n"; + echo $mimetype."_size.min 0\n"; + echo $mimetype."_size.draw $draw\n"; + $draw = "STACK"; +} +foreach ($data as $mimetype => $entry) { + echo $mimetype."_size.value ".$entry->filesize."\n"; +} diff --git a/plugins/moodle/moodle_logs.php b/plugins/moodle/moodle_logs.php index 4c979717..e25df714 100644 --- a/plugins/moodle/moodle_logs.php +++ b/plugins/moodle/moodle_logs.php @@ -5,7 +5,7 @@ * Munin plugin to count logs entries * * It's required to define a container entry for this plugin in your - * /etc/munin/plugin-conf.d/munin-node (or a separate and dedicated file). + * /etc/munin/plugin-conf.d/moodle.conf * * @example Example entry for configuration: * [moodle*] diff --git a/plugins/moodle/moodle_modules_total.php b/plugins/moodle/moodle_modules_total.php index a3e7be1d..60d813eb 100644 --- a/plugins/moodle/moodle_modules_total.php +++ b/plugins/moodle/moodle_modules_total.php @@ -5,7 +5,7 @@ * Munin plugin to count total modules instances * * It's required to define a container entry for this plugin in your - * /etc/munin/plugin-conf.d/munin-node (or a separate and dedicated file). + * /etc/munin/plugin-conf.d/moodle.conf * * @example Example entry for configuration: * [moodle*] diff --git a/plugins/moodle/moodle_users_online.php b/plugins/moodle/moodle_users_online.php index b7de9fd3..bac9ff1f 100644 --- a/plugins/moodle/moodle_users_online.php +++ b/plugins/moodle/moodle_users_online.php @@ -5,7 +5,7 @@ * Munin plugin to count online users * * It's required to define a container entry for this plugin in your - * /etc/munin/plugin-conf.d/munin-node (or a separate and dedicated file). + * /etc/munin/plugin-conf.d/moodle.conf * * @example Example entry for configuration: * [moodle*] diff --git a/plugins/moodle/moodle_users_total.php b/plugins/moodle/moodle_users_total.php index aa0231d5..166036f3 100644 --- a/plugins/moodle/moodle_users_total.php +++ b/plugins/moodle/moodle_users_total.php @@ -5,7 +5,7 @@ * Munin plugin to count total users * * It's required to define a container entry for this plugin in your - * /etc/munin/plugin-conf.d/munin-node (or a separate and dedicated file). + * /etc/munin/plugin-conf.d/moodle.conf * * @example Example entry for configuration: * [moodle*]