-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmoodle_
248 lines (203 loc) · 8.07 KB
/
moodle_
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
#!/usr/bin/perl
#
# Copyright (C) 2012 Ruslan Kabalin, Lancaster University, UK
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; version 2 dated June,
# 1991.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301 USA.
=head1 NAME
moodle_ - Plugin for generating various Moodle stats (Moodle 2.3 and above)
=head1 CONFIGURATION
Configuration is done through libpq environment variables, for example PGUSER,
PGHOST, etc. But generally it is easier if you run the plugin on the database
server as postgres user. For more information, see L<Munin::Plugin::Pgsql> and
L<http://munin-monitoring.org/wiki/plugin-conf.d>.
In order to make this plugin work, you need to specify the name of the moodle
database via symlink to the plugin, i.e. moodle_<databasename>. For more
information see L<http://munin-monitoring.org/wiki/WildcardPlugins>.
Plugin configuration variables:
env.updatetime - you may configure the period for which the time-based data is
calculated (e.g. used in the number of logged-in users reporting or
assignments submissions). By default the value of 300 sec is used (5 min
Munin default update interval).
env.mdlprefix - if you use different from 'mdl_' (mdl_tablename) prefix in
database tables, pass the correct one using this parameter.
env.modturnitintool - if you have Turnitintool module installed, you may add
it to assignment monitoring by setting this variable to 1. Disabled by
default.
=head1 SEE ALSO
L<Munin::Plugin::Pgsql>
L<http://munin-monitoring.org/wiki/plugin-conf.d>
=head1 MAGIC MARKERS
#%# family=auto
#%# capabilities=autoconf suggest
=head1 AUTHOR
Copyright (C) 2012 Ruslan Kabalin, Lancaster University, UK
=head1 COPYRIGHT/License.
Copyright (C) 2012 Ruslan Kabalin, Lancaster University, UK
All rights reserved. This program is free software; you can
redistribute it and/or modify it under the terms of the GNU General
Public License as published by the Free Software Foundation; version 2
dated June, 1991.
=cut
use strict;
use warnings;
use Munin::Plugin;
use Munin::Plugin::Pgsql;
use POSIX;
need_multigraph();
# Initial settings
my $updatetime = 300;
$updatetime = $ENV{"updatetime"} if (defined $ENV{"updatetime"});
my $mdlprefix = 'mdl_';
$mdlprefix = $ENV{"mdlprefix"} if (defined $ENV{"mdlprefix"});
my $modturnitintool = 0;
$modturnitintool = $ENV{"modturnitintool"} if (defined $ENV{"modturnitintool"});
my $timefrom = 100 * floor((time()-$updatetime) / 100);
# Number of logged-in users
print "multigraph mdlusers\n";
my $pg = Munin::Plugin::Pgsql->new(
basename => 'moodle_',
paramdatabase => 1,
category => 'Moodle',
title => 'Moodle users',
info => 'Number of logged-in users',
vlabel => 'Users',
extraconfig => 'graph_scale no',
pivotquery => 1,
basequery => "SELECT count(id) AS users FROM ${mdlprefix}user WHERE lastaccess > $timefrom",
configquery => "VALUES ('users', 'Users')",
graphdraw => 'AREA',
);
$pg->Process();
# Number of unique logged-in users since
print "\n";
print "multigraph uniquemdluserssince\n";
$pg = Munin::Plugin::Pgsql->new(
basename => 'moodle_',
paramdatabase => 1,
category => 'Moodle',
title => 'Unique Moodle users since...',
info => 'Number of unique logged-in users seen since a given time',
vlabel => 'Users',
pivotquery => 1,
basequery => "SELECT
(SELECT count('x') FROM ${mdlprefix}user WHERE lastaccess > extract(epoch from date_trunc('day', now()))) AS day,
(SELECT count('x') FROM ${mdlprefix}user WHERE lastaccess > extract(epoch from date_trunc('week', now()))) AS week,
(SELECT count('x') FROM ${mdlprefix}user WHERE lastaccess > extract(epoch from date_trunc('month', now()))) AS month
;",
configquery => "VALUES
('day', 'Since midnight'),
('week', 'Since monday'),
('month', 'Since start of month')
",
graphdraw => 'LINE1',
);
$pg->Process();
# Number of unique logged-in users over period
print "\n";
print "multigraph uniquemdlusersoverperiod\n";
$pg = Munin::Plugin::Pgsql->new(
basename => 'moodle_',
paramdatabase => 1,
category => 'Moodle',
title => 'Unique Moodle users over period',
info => 'Number of unique logged-in users seen over a fixed period',
vlabel => 'Users',
pivotquery => 1,
basequery => "SELECT
(SELECT count('x') FROM ${mdlprefix}user WHERE lastaccess > extract(epoch from now() - INTERVAL '1 day'))AS day,
(SELECT count('x') FROM ${mdlprefix}user WHERE lastaccess > extract(epoch from now() - INTERVAL '1 week')) AS week,
(SELECT count('x') FROM ${mdlprefix}user WHERE lastaccess > extract(epoch from now() - INTERVAL '1 month')) AS month
;",
configquery => "VALUES
('day', 'In the past 24 hours'),
('week', 'In the past week'),
('month', 'In the past month')
",
graphdraw => 'LINE1',
);
$pg->Process();
# The total size of moodle users files
print "\n";
print "multigraph mdlfiles\n";
$pg = Munin::Plugin::Pgsql->new(
basename => 'moodle_',
paramdatabase => 1,
category => 'Moodle',
title => 'Moodle disk usage',
info => 'The total size of moodle users files',
vlabel => 'Size',
extraconfig => "total.cdef audio,document,application,video,image,text,+,+,+,+,+\ntotal.label Total",
basequery => "SELECT iq.mimetype, SUM(iq.filesize) FROM
(SELECT filesize, regexp_replace(mimetype, '/.+\$', '') AS mimetype FROM ${mdlprefix}files
WHERE filesize > 0 GROUP BY filesize, regexp_replace(mimetype, '/.+\$', ''), contenthash) iq
GROUP BY iq.mimetype",
configquery => "VALUES ('audio', 'Audio'),
('document', 'Document'), ('application', 'Application'), ('video',
'Video'), ('image', 'Image'), ('text', 'Text')",
graphdraw => 'AREA',
base => 1024,
stack => 1,
);
$pg->Process();
# The total number of users in active chat sessions
print "\n";
print "multigraph mdlchats\n";
$pg = Munin::Plugin::Pgsql->new(
basename => 'moodle_',
paramdatabase => 1,
category => 'Moodle',
title => 'Moodle chatting users',
info => 'The total number of users in active chat sessions',
vlabel => 'Users',
extraconfig => 'graph_scale no',
basequery => "SELECT 'chatusers', COUNT(DISTINCT userid) FROM
${mdlprefix}chat_users WHERE lastping > $timefrom
UNION ALL
SELECT 'activechatusers', COUNT(DISTINCT userid) FROM
${mdlprefix}chat_users WHERE lastmessageping > $timefrom",
configquery => "VALUES ('chatusers','Users connected'),('activechatusers','Users posting messages')",
);
$pg->Process();
# The number of assignment submissions
print "\n";
print "multigraph mdlassign\n";
my $basequery = "SELECT 'assign', COUNT(id)
FROM ${mdlprefix}assign_submission WHERE timemodified > $timefrom AND
status = 'submitted'";
my $configquery = "VALUES ('assign','Assignments submitted')";
# Add extra graph is turnitin is enabled
if ($modturnitintool) {
$basequery .= "\nUNION ALL
SELECT 'turnitin', COUNT(id)
FROM ${mdlprefix}turnitintool_submissions
WHERE submission_modified > $timefrom AND submission_status LIKE '%successfully%'";
$configquery .= ", ('turnitin', 'Turnitin assignments submitted')";
}
$pg = Munin::Plugin::Pgsql->new(
basename => 'moodle_',
paramdatabase => 1,
category => 'Moodle',
title => 'Moodle assignment submissions',
info => 'The mumber of submissions',
vlabel => 'Submissions',
extraconfig => 'graph_scale no',
basequery => $basequery,
configquery => $configquery,
graphdraw => 'AREA',
stack => 1,
);
$pg->Process();
exit(0);