mirror of
https://github.com/munin-monitoring/contrib.git
synced 2025-07-25 10:28:36 +00:00
implement online_users graph
This commit is contained in:
parent
ef4bcb874d
commit
31412baabd
1 changed files with 33 additions and 1 deletions
|
@ -21,11 +21,43 @@
|
|||
* @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;
|
||||
$port = 3306;
|
||||
//$graph_period = getenv('graph_period');
|
||||
$graph_period = time() - 5*60;
|
||||
|
||||
|
||||
if (count($argv) === 2 && $argv[1] === 'config') {
|
||||
echo "graph_title Moodle Online 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 sum of online users in your Moodle site\n";
|
||||
echo "users_online.label online users\n";
|
||||
echo "users_online.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
|
||||
$nbusers = 0;
|
||||
if (($stmt = $dbh->query("SELECT count(id) AS users FROM {$table_prefix}user WHERE lastaccess > $graph_period")) != false) {
|
||||
$nbusers = $stmt->fetchColumn();
|
||||
}
|
||||
echo "users_online.value $nbusers\n";
|
Loading…
Add table
Add a link
Reference in a new issue