2012-09-05 14:18:39 +02:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- coding: utf-8
|
|
|
|
#
|
|
|
|
# munin-murmur.py - "murmur stats (User/Bans/Uptime/Channels)" script for munin.
|
|
|
|
# Copyright (c) 2012, Natenom / natenom@natenom.name
|
|
|
|
|
2013-09-16 16:53:06 +02:00
|
|
|
import os
|
|
|
|
|
2013-09-16 16:40:15 +02:00
|
|
|
# Path to Murmur.ice
|
|
|
|
iceslice = os.environ.get('iceslice', '/usr/share/slice/Murmur.ice')
|
2012-09-05 14:18:39 +02:00
|
|
|
|
2013-09-16 16:40:15 +02:00
|
|
|
# Includepath for Ice, this is default for Debian
|
|
|
|
iceincludepath = os.environ.get('iceincludepath', '/usr/share/Ice/slice')
|
2012-09-06 09:28:36 +02:00
|
|
|
|
2013-09-16 16:40:15 +02:00
|
|
|
# Murmur-Port (not needed to work, only for display purposes)
|
|
|
|
serverport = int(os.environ.get('serverport', '64738'))
|
2012-09-05 14:18:39 +02:00
|
|
|
|
2013-09-16 16:40:15 +02:00
|
|
|
# Port where ice listen
|
|
|
|
iceport = int(os.environ.get('iceport', '6502'))
|
2012-09-05 14:18:39 +02:00
|
|
|
|
2013-09-16 16:40:15 +02:00
|
|
|
# Ice Password to get read access.
|
|
|
|
# If there is no such var in your murmur.ini, this can have any value.
|
|
|
|
# You can use the values of icesecret, icesecretread or icesecretwrite in your murmur.ini
|
|
|
|
icesecret = os.environ.get('icesecret', 'secureme')
|
2012-09-06 09:02:00 +02:00
|
|
|
|
2013-09-16 16:40:15 +02:00
|
|
|
# MessageSizeMax; increase this value, if you get a MemoryLimitException.
|
2012-09-05 14:18:39 +02:00
|
|
|
# Also check this value in murmur.ini of your Mumble-Server.
|
|
|
|
# This value is being interpreted in kibiBytes.
|
2013-09-16 16:40:15 +02:00
|
|
|
messagesizemax = os.environ.get('messagesizemax', '65535')
|
2012-09-05 14:18:39 +02:00
|
|
|
|
2013-09-16 17:01:52 +02:00
|
|
|
import Ice, sys
|
2012-09-06 09:28:36 +02:00
|
|
|
Ice.loadSlice("--all -I%s %s" % (iceincludepath, iceslice))
|
2012-09-05 14:18:39 +02:00
|
|
|
|
|
|
|
props = Ice.createProperties([])
|
|
|
|
props.setProperty("Ice.MessageSizeMax", str(messagesizemax))
|
2012-09-06 09:02:00 +02:00
|
|
|
props.setProperty("Ice.ImplicitContext", "Shared")
|
2012-09-05 14:18:39 +02:00
|
|
|
id = Ice.InitializationData()
|
|
|
|
id.properties = props
|
|
|
|
|
|
|
|
ice = Ice.initialize(id)
|
2012-09-06 18:47:07 +02:00
|
|
|
ice.getImplicitContext().put("secret", icesecret)
|
2012-09-05 14:18:39 +02:00
|
|
|
|
|
|
|
import Murmur
|
|
|
|
|
|
|
|
if (sys.argv[1:]):
|
|
|
|
if (sys.argv[1] == "config"):
|
|
|
|
print 'graph_title Murmur (Port %s)' % (serverport)
|
|
|
|
print 'graph_vlabel Count'
|
|
|
|
print 'users.label Users (All)'
|
2013-09-16 16:49:31 +02:00
|
|
|
print 'usersauth.label Users (Authenticated)'
|
2012-09-05 14:18:39 +02:00
|
|
|
print 'usersnotauth.label Users (Not authenticated)'
|
|
|
|
print 'uptime.label Uptime in days'
|
2013-09-16 16:49:31 +02:00
|
|
|
print 'channelcount.label Number of channels'
|
|
|
|
print 'bancount.label Number of bans'
|
2012-09-05 14:18:39 +02:00
|
|
|
sys.exit(0)
|
|
|
|
|
|
|
|
meta = Murmur.MetaPrx.checkedCast(ice.stringToProxy("Meta:tcp -h 127.0.0.1 -p %s" % (iceport)))
|
2012-09-06 09:02:00 +02:00
|
|
|
try:
|
2013-09-16 16:49:31 +02:00
|
|
|
server = meta.getServer(1)
|
2012-09-06 09:02:00 +02:00
|
|
|
except Murmur.InvalidSecretException:
|
2013-09-16 16:40:15 +02:00
|
|
|
print 'Given icesecret password is wrong.'
|
2012-09-06 09:02:00 +02:00
|
|
|
ice.shutdown()
|
|
|
|
sys.exit(1)
|
2012-09-05 14:18:39 +02:00
|
|
|
|
2013-09-16 16:49:31 +02:00
|
|
|
# count users
|
|
|
|
usersnotauth = 0
|
|
|
|
usersauth = 0
|
|
|
|
users = server.getUsers()
|
2012-09-05 14:18:39 +02:00
|
|
|
for key in users.keys():
|
|
|
|
if (users[key].userid == -1):
|
2013-09-16 16:49:31 +02:00
|
|
|
usersnotauth += 1
|
|
|
|
else:
|
|
|
|
usersauth += 1
|
2012-09-05 14:18:39 +02:00
|
|
|
|
|
|
|
print "users.value %i" % (len(users))
|
2013-09-16 16:49:31 +02:00
|
|
|
print "usersauth.value %i" % (usersauth)
|
|
|
|
print "usersnotauth.value %i" % (usersnotauth)
|
2012-09-05 14:18:39 +02:00
|
|
|
print "uptime.value %.2f" % (float(meta.getUptime())/60/60/24)
|
2013-09-16 16:49:31 +02:00
|
|
|
print "channelcount.value %i" % (len(server.getChannels()))
|
2012-09-05 14:18:39 +02:00
|
|
|
print "bancount.value %i" % (len(server.getBans()))
|
|
|
|
|
|
|
|
ice.shutdown()
|