Projet

Général

Profil

Révision 711726ab

ID711726ab8fe7ef788a00e423d554f9cc1cd5002a
Parent 24e77a26
Enfant f3d7d019

Ajouté par ak4t0sh il y a environ 11 ans

initial commit

Voir les différences:

plugins/moodle/moodle_users_online.php
1
#!/usr/bin/php
2
<?php
3
/**
4
 * Moodle Users Online
5
 * Munin plugin to count online users
6
 *
7
 * It's required to define a container entry for this plugin in your
8
 * /etc/munin/plugin-conf.d/munin-node (or a separate and dedicated file).
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
$db = getenv('db');
25
$type = getenv('type');
26
$host = getenv('host');
27
$user = getenv('user');
28
$pass = getenv('pass');
29
$port = getenv('port');
30
if (!$port)
31
    $port = 3306;
plugins/moodle/moodle_users_total.php
1
#!/usr/bin/php
2
<?php
3
/**
4
 * Moodle Users Total
5
 * Munin plugin to count total users
6
 *
7
 * It's required to define a container entry for this plugin in your
8
 * /etc/munin/plugin-conf.d/munin-node (or a separate and dedicated file).
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

  
25
$dbh = null;
26
$db = getenv('db');
27
$type = getenv('type');
28
$host = getenv('host');
29
$user = getenv('user');
30
$pass = getenv('pass');
31
$table_prefix = getenv('table_prefix');
32
$port = getenv('port');
33
if (!$port)
34
    $port = 3306;
35
$graph_period = getenv('graph_period');
36

  
37

  
38
if (count($argv) === 2 && $argv[1] === 'config') {
39
    echo "graph_title Moodle Total Users\n";
40
    echo "graph_args --base 1000 --lower-limit 0\n";
41
    echo "graph_vlabel Total Users Count / ${graph_period}\n";
42
    echo "graph_category Moodle\n";
43
    echo "graph_scale no\n";
44
    echo "graph_info Displays the sum of users, as well as active count, in your Moodle site\n";
45

  
46
    echo "users_total.label total users\n";
47
    echo "users_active.label active users\n";
48

  
49
    echo "users_total.min 0\n";
50
    echo "users_active.min 0\n";
51

  
52
    exit(0);
53
}
54

  
55
try {
56
    $dsn = $type . ':host=' . $host . ';port=' . $port . ';dbname=' . $db;
57
    $dbh = new PDO($dsn, $user, $pass);
58
} catch (Exception $e) {
59
    echo "Connection failed\n";
60
    exit(1);
61
}
62

  
63

  
64

  
65
//All users
66
$nbusers = 0;
67
if (($stmt = $dbh->query("SELECT COUNT(id) FROM {$table_prefix}user")) != false) {
68
    $nbusers = $stmt->fetchColumn();
69
}
70
echo "users_total.value $nbusers\n";
71

  
72
//Active users (not deleted or suspended)
73
$nbusers = 0;
74
if (($stmt = $dbh->query("SELECT COUNT(id) FROM {$table_prefix}user WHERE deleted=0 AND suspended=0")) != false) {
75
    $nbusers = $stmt->fetchColumn();
76
    echo "users_active.value $nbusers\n";
77
}

Formats disponibles : Unified diff