root / plugins / other / prosody @ cdedc3af
Historique | Voir | Annoter | Télécharger (3,03 ko)
| 1 |
#!/usr/bin/env python |
|---|---|
| 2 |
# -*- coding: utf-8 -*- |
| 3 |
# Copyright (c) 2010 Christoph Heer (Christoph.Heer@googlemail.com) |
| 4 |
# |
| 5 |
# Permission is hereby granted, free of charge, to any person obtaining a |
| 6 |
# copy of this software and associated documentation files (the \"Software\"), |
| 7 |
# to deal in the Software without restriction, including without limitation |
| 8 |
# the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 9 |
# and/or sell copies of the Software, and to permit persons to whom the |
| 10 |
# Software is furnished to do so, subject to the following conditions: |
| 11 |
# |
| 12 |
# The above copyright notice and this permission notice shall be included in |
| 13 |
# all copies or substantial portions of the Software. |
| 14 |
# |
| 15 |
# THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 |
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 |
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 18 |
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 |
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 20 |
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 21 |
# DEALINGS IN THE SOFTWARE. |
| 22 |
|
| 23 |
import sys |
| 24 |
import os |
| 25 |
import telnetlib |
| 26 |
import re |
| 27 |
|
| 28 |
def main(): |
| 29 |
mode = "" |
| 30 |
try: mode = sys.argv[1] |
| 31 |
except Exception, IndexError: mode = "" |
| 32 |
wildcard = sys.argv[0].split("prosody_")[1].split("_")[0]
|
| 33 |
|
| 34 |
if wildcard == "c2s": |
| 35 |
if mode == "config": |
| 36 |
print "graph_title Prosody C2S Connections" |
| 37 |
print "graph_vlabel users" |
| 38 |
print "graph_category Prosody" |
| 39 |
|
| 40 |
print "all_client_connections.label client connections" |
| 41 |
print "secure_client_connections.label secure client connections" |
| 42 |
print "insecure_client_connections.label insecure client connections" |
| 43 |
sys.exit(0) |
| 44 |
|
| 45 |
else: |
| 46 |
Regex = re.compile(r"Total:\s(\d+)\s") |
| 47 |
telnet = telnetlib.Telnet('localhost', 5582)
|
| 48 |
telnet.write("c2s:show_secure()")
|
| 49 |
telnetResponse = telnet.read_until("secure client connections", 5)
|
| 50 |
ParsedInfo = Regex.findall(telnetResponse) |
| 51 |
scc = int(ParsedInfo[0]) |
| 52 |
print "secure_client_connections.value %s" % (scc) |
| 53 |
|
| 54 |
telnet.write("c2s:show_insecure()")
|
| 55 |
telnetResponse = telnet.read_until("insecure client connections", 5)
|
| 56 |
ParsedInfo = Regex.findall(telnetResponse) |
| 57 |
icc = int(ParsedInfo[0]) |
| 58 |
print "insecure_client_connections.value %s" % (icc) |
| 59 |
cc = scc + icc |
| 60 |
print "all_client_connections.value %s" % (cc) |
| 61 |
|
| 62 |
elif wildcard == "s2s": |
| 63 |
if mode == "config": |
| 64 |
print "graph_title Prosody S2S Connections" |
| 65 |
print "graph_vlabel servers" |
| 66 |
print "graph_category Prosody" |
| 67 |
|
| 68 |
print "outgoing_connections.label outgoing connections" |
| 69 |
print "incoming_connections.label incoming connections" |
| 70 |
sys.exit(0) |
| 71 |
|
| 72 |
else: |
| 73 |
Regex = re.compile(r"(\d+) outgoing, (\d+)") |
| 74 |
telnet = telnetlib.Telnet('localhost', 5582)
|
| 75 |
telnet.write("s2s:show()")
|
| 76 |
telnetResponse = telnet.read_until("connections", 5)
|
| 77 |
ParsedInfo = Regex.findall(telnetResponse) |
| 78 |
print "outgoing_connections.value %s" % (ParsedInfo[0][0]) |
| 79 |
print "incoming_connections.value %s" % (ParsedInfo[0][1]) |
| 80 |
|
| 81 |
if __name__ == '__main__': |
| 82 |
main() |
