1
0
Fork 0
mirror of https://github.com/munin-monitoring/contrib.git synced 2025-07-25 02:18:08 +00:00

Can monitor uptime and number of registered users

This commit is contained in:
Christian Bendt 2011-10-03 13:01:15 +02:00 committed by Steve Schnepp
parent ec351f99a6
commit c653988d0e

View file

@ -19,6 +19,16 @@
# 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
@ -38,6 +48,8 @@ def main():
print "c2s"
print "s2s"
print "presence"
print "uptime"
print "users"
sys.exit(0)
if wildcard == "c2s":
@ -117,6 +129,57 @@ def main():
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()