From b9f9e90ab0ff9a33d7862020c0732d15f3b39a3f Mon Sep 17 00:00:00 2001 From: ak4t0sh Date: Mon, 22 Sep 2014 23:44:51 +0200 Subject: [PATCH] add graph for new log entries --- plugins/moodle/moodle_logs.php | 62 ++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 plugins/moodle/moodle_logs.php diff --git a/plugins/moodle/moodle_logs.php b/plugins/moodle/moodle_logs.php new file mode 100644 index 00000000..28bef09a --- /dev/null +++ b/plugins/moodle/moodle_logs.php @@ -0,0 +1,62 @@ +#!/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 = getenv('graph_period'); +$graph_period = time() - 5*60; + +if (count($argv) === 2 && $argv[1] === 'config') { + echo "graph_title Moodle Logs\n"; + echo "graph_args --base 1000 --lower-limit 0\n"; + echo "graph_vlabel logs\n"; + echo "graph_category Moodle\n"; + echo "graph_scale no\n"; + echo "graph_info Displays the number of new logs written\n"; + echo "logs.label logs\n"; + echo "logs.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); +} + +//Online users +$nb = 0; +if (($stmt = $dbh->query("SELECT count(id) FROM {$table_prefix}log WHERE time > $graph_period")) != false) { + $nbusers = $stmt->fetchColumn(); +} +echo "logs.value $nb\n";