mirror of
https://github.com/munin-monitoring/contrib.git
synced 2018-11-08 00:59:34 +01:00
186 lines
7.5 KiB
Python
Executable File
186 lines
7.5 KiB
Python
Executable File
#!/usr/bin/env python
|
|
# -*- coding: utf-8 -*-
|
|
# Copyright (c) 2010 Christoph Heer (Christoph.Heer@googlemail.com)
|
|
#
|
|
# 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, sublicense,
|
|
# and/or sell copies of the Software, and to permit persons to whom the
|
|
# Software is furnished to do so, subject to the following conditions:
|
|
#
|
|
# The above copyright notice and this permission notice shall be included in
|
|
# all copies or substantial portions of the Software.
|
|
#
|
|
# 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. IN NO EVENT SHALL
|
|
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
# DEALINGS IN THE SOFTWARE.
|
|
#
|
|
#
|
|
# Changelog:
|
|
# 2011-09-30: Christian Bendt (mail@m3d1c5.org)
|
|
# Added "uptime" and "users"
|
|
# To read the number of registered users, add the following lines
|
|
# in /etc/munin/plugin-conf.d/munin-node on debian
|
|
# [prosody_*]
|
|
# user prosody
|
|
# group prosody
|
|
|
|
import sys
|
|
import os
|
|
import telnetlib
|
|
import re
|
|
|
|
def main():
|
|
try:
|
|
mode = sys.argv[1]
|
|
except IndexError:
|
|
mode = ""
|
|
wildcard = sys.argv[0].split("prosody_")[1].split("_")[0]
|
|
host = os.environ.get('host', 'localhost')
|
|
port = int(os.environ.get('port', 5582))
|
|
|
|
if mode == "suggest":
|
|
print "c2s"
|
|
print "s2s"
|
|
print "presence"
|
|
print "uptime"
|
|
print "users"
|
|
sys.exit(0)
|
|
|
|
if wildcard == "c2s":
|
|
if mode == "config":
|
|
print "graph_title Prosody C2S Connections"
|
|
print "graph_vlabel users"
|
|
print "graph_category Prosody"
|
|
|
|
print "all_client_connections.label client connections"
|
|
print "secure_client_connections.label secure client connections"
|
|
print "insecure_client_connections.label insecure client " \
|
|
"connections"
|
|
sys.exit(0)
|
|
|
|
else:
|
|
connection_count_re = re.compile(r"Total:\s(\d+)\s")
|
|
telnet = telnetlib.Telnet(host, port)
|
|
telnet.write("c2s:show_secure()")
|
|
telnet_response = telnet.read_until("secure client connections",
|
|
5)
|
|
parsed_info = connection_count_re.findall(telnet_response)
|
|
secure_client_connections = int(parsed_info[0])
|
|
print "secure_client_connections.value %s" % \
|
|
(secure_client_connections)
|
|
|
|
telnet.write("c2s:show_insecure()")
|
|
telnet_response = telnet.read_until("insecure client connections",
|
|
5)
|
|
parsed_info = connection_count_re.findall(telnet_response)
|
|
insecure_client_connections = int(parsed_info[0])
|
|
print "insecure_client_connections.value %s" % \
|
|
(insecure_client_connections)
|
|
all_client_connections = secure_client_connections + \
|
|
insecure_client_connections
|
|
print "all_client_connections.value %s" % (all_client_connections)
|
|
|
|
elif wildcard == "s2s":
|
|
if mode == "config":
|
|
print "graph_title Prosody S2S Connections"
|
|
print "graph_vlabel servers"
|
|
print "graph_category Prosody"
|
|
|
|
print "outgoing_connections.label outgoing connections"
|
|
print "incoming_connections.label incoming connections"
|
|
sys.exit(0)
|
|
|
|
else:
|
|
server_connections_re = re.compile(r"(\d+) outgoing, (\d+)")
|
|
telnet = telnetlib.Telnet(host, port)
|
|
telnet.write("s2s:show()")
|
|
telnet_response = telnet.read_until("connections", 5)
|
|
parsed_info = server_connections_re.findall(telnet_response)
|
|
print "outgoing_connections.value %s" % (parsed_info[0][0])
|
|
print "incoming_connections.value %s" % (parsed_info[0][1])
|
|
|
|
elif wildcard == "presence":
|
|
if mode == "config":
|
|
print "graph_title Prosody Client Presence"
|
|
print "graph_vlabel clients"
|
|
print "graph_category Prosody"
|
|
|
|
print "available.label Avaible Clients"
|
|
print "chat.label Ready for Chat Clients"
|
|
print "away.label Away Clients"
|
|
print "xa.label Extended Away Clients"
|
|
print "dnd.label Do Not Disturb Clients"
|
|
sys.exit(0)
|
|
|
|
else:
|
|
client_presence_re = re.compile(r"- (.*?)\(\d+\)")
|
|
telnet = telnetlib.Telnet(host, port)
|
|
telnet.write("c2s:show()")
|
|
telnet_response = telnet.read_until("clients", 5)
|
|
parsed_info = client_presence_re.findall(telnet_response)
|
|
print "available.value %s" % (parsed_info.count("available"))
|
|
print "chat.value %s" % (parsed_info.count("chat"))
|
|
print "away.value %s" % (parsed_info.count("away"))
|
|
print "xa.value %s" % (parsed_info.count("xa"))
|
|
print "dnd.value %s" % (parsed_info.count("dnd"))
|
|
|
|
elif wildcard == "uptime":
|
|
if mode == "config":
|
|
print "graph_title Prosody Uptime"
|
|
print "graph_args --base 1000 -l 0"
|
|
print "graph_scale no"
|
|
print "graph_vlabel uptime in days"
|
|
print "graph_category Prosody"
|
|
print "graph_order uptime"
|
|
print "uptime.draw AREA"
|
|
print "uptime.min U"
|
|
print "uptime.max U"
|
|
print "uptime.label uptime"
|
|
print "uptime.type GAUGE"
|
|
sys.exit(0)
|
|
|
|
else:
|
|
uptime_re = re.compile(r"\d+")
|
|
telnet = telnetlib.Telnet(host, port)
|
|
telnet.write("server:uptime()")
|
|
telnet_response = telnet.read_until("minutes (", 5)
|
|
parsed_info = uptime_re.findall(telnet_response)
|
|
uptime_value = float(parsed_info[0]) + float(parsed_info[1])/24 + float(parsed_info[2])/60/24
|
|
print "uptime.value %s" % (uptime_value)
|
|
|
|
elif wildcard == "users":
|
|
if mode == "config":
|
|
print "graph_title Prosody Registered Users"
|
|
print "graph_vlabel users"
|
|
print "graph_category Prosody"
|
|
|
|
basedir = "/var/lib/prosody"
|
|
if os.path.exists(basedir):
|
|
vhosts = listdirs(basedir)
|
|
for vhost in vhosts:
|
|
accountdir = basedir + os.sep + vhost + os.sep + "accounts"
|
|
if os.path.exists(accountdir):
|
|
accounts = listfiles(accountdir)
|
|
headcount = 0
|
|
for account in accounts:
|
|
headcount += 1
|
|
if mode == "config":
|
|
print vhost.replace("%2e","_") + ".label %s" % (vhost.replace("%2e","."))
|
|
else:
|
|
print vhost.replace("%2e","_") + ".value %s" % (headcount)
|
|
|
|
def listdirs(folder):
|
|
return [d for d in os.listdir(folder) if os.path.isdir(os.path.join(folder, d))]
|
|
|
|
def listfiles(folder):
|
|
return [d for d in os.listdir(folder) if os.path.isfile(os.path.join(folder, d))]
|
|
|
|
if __name__ == '__main__':
|
|
main()
|