Actions
Munin scripts¶
Report ideas¶
In terms of administration of multiple Chamilo portals or unique very large portals, the following reports might be useful
- active users on each portal
- number of registered users on each portal
- number of registered teachers on each portal
- number of courses
- number of non-closed courses
- total number of users-courses registrations
- total space used by one portal
- number of connections to portal
Scripts¶
To enable any of these scripts:- make sure it runs by executing it on the command line (from anywhere): php5 script.php
- place a link to it from the /etc/munin/plugins/ directory
Active users on each portal¶
#!/usr/bin/php5
<?php
// This first section is to allow the script to show a documentation page with munindoc
$doc = <<<CUT
=head1 NAME
chamilo_active_users - Munin plugin to monitor the number of live connections on Chamilo portals.
=head1 APPLICABLE SYSTEMS
Chamilo 1.* web application.
=head1 CONFIGURATION
The plugin needs access to the root web directory /var/www (or any other path
given in $bd) in order to scan for Chamilo installations. It also offers a way to
define subdirs if your Chamilo portals are generally stored under two folder
levels inside /var/www/. The plugin also needs the possibility to execute PHP
on the command line (php-cli package) and to connect to a MySQL database
(php5-mysql package).
=head1 INTERPRETATION
The plugin shows the number of active users at any given time for any
Chamilo portal found in the given path, indicating the URL of the
corresponding portal.
=head1 MAGIC MARKERS
#%# family=auto
#%# capabilities=autoconf
=head1 BUGS
None known of
=head1 VERSION
0.2
=head1 AUTHOR
Yannick Warnier <yannick.warnier@beeznest.com>
=head1 LICENSE
AGPLv3
=cut
CUT;
ini_set('error_reporting','E_ALL & ~E_WARNING & ~E_NOTICE');
$bd = '/var/www'; // set to your web root
$sub = '/www'; // set to any suffix you have after the virtual host directory
$last_connect_minutes = 5; // set to any max timespan within which you want to measure connections
// call the function defined below to get the connections for all portals
$connections = get_connections($bd, $sub, $last_connect_minutes);
// check for the config param
if ( !empty($argv[1]) && $argv[1] == 'config') {
// Global Munin attributes, see http://munin-monitoring.org/wiki/protocol-config
echo "graph_title Chamilo active users\n";
echo "graph_args --lower-limit 0\n";
echo "graph_category chamilo\n";
echo "graph_info This graph shows the number of connected users on Chamilo portals over time.\n";
echo "graph_vlabel Users in last $last_connect_minutes min\n";
echo "graph_scale off\n";
// Define information for each portal
foreach ($connections as $portal => $num) {
echo "portal$portal.label Host $portal\n";
echo "portal$portal.type DERIVE\n";
//echo "portal$portal.max 500\n"; //useless
echo "portal$portal.min 0\n";
echo "portal$portal.warning 50\n";
echo "portal$portal.critical 250\n";
echo "portal$portal.draw LINE2\n";
}
exit;
}
// if it was not a config call, then show the *values* for each portal
if (is_array($connections) && count($connections)>0) {
foreach ($connections as $portal => $num) {
echo "portal$portal.value $num\n";
}
} else {
exit -1;
}
/**
* Gets the number of active users on all the portals that can be found
* inside the given documents root
* @param string Document root
* @param string Suffix (if any)
* @param int Number of minutes during which a user is considered active after his last action
*/
function get_connections($bd='/var/www', $sub='', $last_connect_minutes=5) {
$match_count=0;
$connections = array();
$last_connect_minutes = intval($last_connect_minutes);
$list = scandir($bd);
// Browse all directories
foreach ($list as $dir) {
// Skip system directories
if (substr($dir,0,1)=='.' or $dir == 'lost+found') continue;
// Check for the existence of configuration.php (represents an active Chamilo install)
if (is_file($bd.'/'.$dir.$sub.'/main/inc/conf/configuration.php')) {
// Get the database connection information from there
$inc = include_once($bd.'/'.$dir.$sub.'/main/inc/conf/configuration.php');
$dbh = mysql_connect($_configuration['db_host'],$_configuration['db_user'],$_configuration['db_password']);
if ($inc!==false && $dbh!==false) {
$db = $_configuration['statistics_database'];
$current_date=date('Y-m-d H:i:s',time());
$track_online_table = $db.'.track_e_online';
$query = "SELECT count(login_user_id) ".
" FROM ".$track_online_table .
" WHERE DATE_ADD(login_date, ".
" INTERVAL $last_connect_minutes MINUTE) >= '".$current_date."' ";
$res = mysql_query($query);
if ( $res === false ) {
$num = 0;
//echo " There was a query error for the following portal\n";
} else {
$row = mysql_fetch_row($res);
$num = $row[0];
}
//echo sprintf("[%7d]",$num)." users connected to ".$_configuration['root_web']." last $last_connect_minutes'\n";
$connections[str_replace('.','_',substr($_configuration['root_web'],7,-1))] = $num;
$match_count += $num;
mysql_close($dbh);
} else {
//echo "$bd/$dir$sub:could not open configuration.php or database:\n";
}
}
}
return $connections;
}
Other references¶
- This link doesn't provide any public code, but it has some common ideas: http://docs.moodle.org/19/es/Monitorizaci%C3%B3n_de_Moodle_con_Munin
Updated by Yannick Warnier about 9 years ago ยท 1 revisions