2
0
mirror of https://github.com/munin-monitoring/contrib.git synced 2018-11-08 00:59:34 +01:00

Munin ILIAS plugin: First release

This commit is contained in:
Felix Pahlow 2018-03-19 12:19:28 +01:00 committed by Felix (ITZ)
parent 051ee8eae7
commit 167c204db2
2 changed files with 201 additions and 66 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

267
plugins/ilias/ilias_ Normal file → Executable file
View File

@ -1,119 +1,254 @@
#!/usr/bin/env python
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# The Plugin needs the following configuration settings
#[ilias_*]
#env.ildbuser ilias
#env.ildbpassword youriliaspasword
#env.ildb ilias
"""
: << =cut
#%# family=auto
#%# capabilities=autoconf suggest
=head1 NAME
ilias - Munin plugin to monitor L<ILIAS|https://ilias.de/> open source
learning management system
=head1 DESCRIPTION
Reads session and user statistcs from any ILIAS MySQLdb database.
https://ilias.de/ | http://gallery.munin-monitoring.org/contrib/cms-index.html
This plugin requires python3 and python3-mysqldb.
There is a check for the the filename suffix _ (from the symlink) in place
to decide which value to output. Symlink the file for each value you want
displayed
example:
ln -s /usr/local/munin_plugins/ilias_ /etc/munin/plugins/ilias_sessions
In order to get precise results, please ensure your MySQL server has the same
time as your ILIAS application server. Timezone does not matter.
=head1 CONFIGURATION
The plugin needs the following configuration settings e.g. in
/etc/munin/plugin-conf.d/ilias.conf
[ilias_*]
env.ildbuser ilias
env.ildbpassword youriliaspasword
env.ildb ilias
env.ildbhost localhost
env.ildbport 3306
=head1 AUTHOR
Copyright 2016 Pascal Seeland <per-pascal.grube@tik.uni-stuttgart.de>
Copyright 2018 L<Felix Pahlow|https://wohlpa.de/>
(L<email|mailto:felix.pahlow@itz.uni-halle.de>)
=head1 LICENSE
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, and/or sell copies of the
Software, and to permit persons to whom the Software is furnished to do so,
provided that the above copyright notice(s) and this permission notice
appear in all copies of the Software and that both the above copyright
notice(s) and this permission notice appear in supporting documentation.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN THIS NOTICE BE
LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR
ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
Except as contained in this notice, the name of a copyright holder shall not
be used in advertising or otherwise to promote the sale, use or other
dealings in this Software without prior written authorization of the
copyright holder.
=head1 CONTRIBUTE
Find this plugin on L<GitHub
|https://github.com/munin-monitoring/contrib/tree/master/plugins/ilias>
=head1 MAGIC MARKERS
#%# family=auto
#%# capabilities=autoconf suggest
=head1 VERSION
1.0
=head1 CHANGELOG
=head2 1.0 - 2018/03/19
first release
=cut
"""
import os
import sys
import MySQLdb
import _mysql
import pkgutil
class ILIAS():
title = "ILIAS session"
args = "--base 1000 -l 0"
vlabel = "ilias"
category = "ilias"
pluginname = sys.argv[0].split('_')[1]
def __init__(self):
self.con = None
self.user = os.environ.get('ildbuser', 'root')
self.pw = os.environ.get('ildbpassword', '')
self.ildb = os.environ.get('ildb','ilias')
self.ildb = os.environ.get('ildb', 'ilias')
self.ildbhost = os.environ.get('ildbhost', 'localhost')
self.ildbport = int(os.environ.get('ildbport', 3306))
def db_modules_available(self):
return pkgutil.find_loader("MySQLdb")
def get_connection(self):
import MySQLdb
return MySQLdb.connect(host=self.ildbhost,
port=self.ildbport,
user=self.user,
passwd=self.pw,
db=self.ildb)
def connectdb(self):
self.con = MySQLdb.connect("localhost", self.user, self.pw,self.ildb)
self.pluginname = sys.argv[0].split('_')[1]
self.con = self.get_connection()
def config_sessions(self):
def config_sessions(self):
print("graph_title ILIAS Session")
print("graph_info Number of active ILIAS user sessions")
print("graph_vlabel ilsessions")
print("graph_category ILIAS")
print("graph_category cms")
print("ilsessions.label ilSessions")
print("ilsessions.min 0")
print("ilsessions.draw AREA")
def execute_sessions(self):
cursor = self.con.cursor()
cursor.execute("select count(user_id) from usr_session where `expires` > UNIX_TIMESTAMP( NOW( ) ) AND user_id != 0")
cursor.execute(
"SELECT COUNT( user_id ) "
"FROM usr_session "
"WHERE `expires` > UNIX_TIMESTAMP( NOW( ) ) AND user_id != 0"
)
usrs = cursor.fetchone()[0]
print("ilsessions %s"%(usrs))
print("ilsessions.value %s" % (usrs))
def config_5minavg(self):
print("graph_title ILIAS 5 avg")
print("graph_info ILIAS sessions created or "
"updated during the last 5 minutes")
print("graph_vlabel il5minavg")
print("graph_category cms")
print("il5minavg.label 5 min Count")
print("il5minavg.min 0")
print("il5minavg.draw AREA")
def config_10minavg(self):
print("graph_title ILIAS 10 avg")
print("graph_vlabel il10minavg")
print("graph_category ILIAS")
print("il10minavg.label 10 min Count")
def execute_10minavg(self):
def execute_5minavg(self):
cursor = self.con.cursor()
cursor.execute("select count(user_id) from usr_session where 10 * 60 > UNIX_TIMESTAMP( NOW( ) ) - ctime AND user_id != 0")
cursor.execute(
"SELECT COUNT( user_id ) "
"FROM usr_session "
"WHERE 5 * 60 > UNIX_TIMESTAMP( NOW( ) ) - ctime AND user_id != 0"
)
usrs = cursor.fetchone()[0]
print("il10minavg %s"%(usrs))
print("il5minavg.value %s" % (usrs))
def config_60minavg(self):
def config_60minavg(self):
print("graph_title ILIAS 60 avg")
print("graph_info ILIAS sessions created or "
"updated during the last 60 minutes")
print("graph_vlabel il60minavg")
print("graph_category ILIAS")
print("graph_category cms")
print("il60minavg.label 60 min Count")
print("il60minavg.min 0")
print("il60minavg.draw AREA")
def execute_60minavg(self):
cursor = self.con.cursor()
cursor.execute("select count(user_id) from usr_session where 60 * 60 > UNIX_TIMESTAMP( NOW( ) ) - ctime AND user_id != 0")
cursor.execute(
"SELECT COUNT( user_id ) "
"FROM usr_session "
"WHERE 60 * 60 > UNIX_TIMESTAMP( NOW( ) ) - ctime AND user_id != 0"
)
usrs = cursor.fetchone()[0]
print("il60minavg %s"%(usrs))
print("il60minavg.value %s" % (usrs))
def config_total1day(self):
def config_total1day(self):
print("graph_title Users in 24h")
print("graph_info ILIAS users logging in during last 24h")
print("graph_vlabel iltotal1day")
print("graph_category ILIAS")
print("graph_category cms")
print("iltotal1day.label User/24h")
print("iltotal1day.min 0")
print("iltotal1day.draw AREA")
def execute_total1day(self):
cursor = self.con.cursor()
cursor.execute("select count(usr_id) FROM `usr_data` WHERE last_login >= DATE_SUB( NOW( ) , INTERVAL 1 DAY )")
cursor.execute(
"SELECT COUNT( usr_id ) "
"FROM `usr_data` "
"WHERE last_login >= DATE_SUB( NOW( ) , INTERVAL 1 DAY )")
usrs = cursor.fetchone()[0]
print("iltotal1day %s"%(usrs))
print("iltotal1day.value %s" % (usrs))
def run(self):
cmd = ((len(sys.argv) > 1) and sys.argv[1] or None) or "execute"
cmd = ((len(sys.argv) > 1) and sys.argv[1]) or "execute"
function = None
if cmd == "execute":
function = "execute"
elif cmd == "config":
if cmd == "config":
function = "config"
if function != None:
self.connectdb()
try:
func = getattr(self, "%s_%s"%(function,self.pluginname))
except AttributeError:
print 'function not found "%s" (%s)' % ("config_%s"%self.pluginname, "self")
elif cmd == "suggest":
print("sessions")
print("5minavg")
print("60minavg")
print("total1day")
elif cmd == "autoconf":
if not self.db_modules_available():
print("no (Please install the MySQLdb python3 module)")
else:
func()
try:
con = self.get_connection()
cursor = con.cursor()
cursor.execute("SELECT COUNT( component ) "
"FROM il_pluginslot")
con.close()
except _mysql.Error as e:
print("no (Error %d: %s - Database configuration missing?)"
% (e.args[0], e.args[1]))
else:
print("yes")
else:
function = "execute"
if function is not None:
if not self.db_modules_available():
print("U (Please install the MySQLdb python3 module)")
else:
self.connectdb()
try:
func = getattr(self, "%s_%s" % (function, self.pluginname))
except AttributeError:
print('function not found "%s" (%s)' %
("config_%s" % self.pluginname, "self"))
else:
func()
if self.con:
self.con.close()
if cmd == "suggest":
print ("sessions")
print ("10minavg")
print ("60minavg")
print ("total1day")
if cmd == "autoconf":
try:
con = MySQLdb.connect("localhost", self.user, self.pw,self.ildb)
cursor = con.cursor()
cursor.execute("SELECT count(component) FROM il_pluginslot")
except _mysql.Error, e:
print "no (Error %d: %s)" % (e.args[0], e.args[1])
else:
print "yes"
sys.exit(0)
if __name__ == "__main__":
ILIAS().run()