root / plugins / prosody / prosody_ @ 7063330e
Historique | Voir | Annoter | Télécharger (9,83 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 |
|
| 29 |
def main(): |
| 30 |
try: |
| 31 |
mode = sys.argv[1] |
| 32 |
except IndexError: |
| 33 |
mode = "" |
| 34 |
wildcard = sys.argv[0].split("prosody_")[1].split("_")[0]
|
| 35 |
host = os.environ.get('host', 'localhost')
|
| 36 |
port = int(os.environ.get('port', 5582))
|
| 37 |
|
| 38 |
if mode == "suggest": |
| 39 |
print("c2s")
|
| 40 |
print("s2s")
|
| 41 |
print("presence")
|
| 42 |
print("uptime")
|
| 43 |
print("users")
|
| 44 |
sys.exit(0) |
| 45 |
|
| 46 |
if wildcard == "c2s": |
| 47 |
if mode == "config": |
| 48 |
print("graph_title Prosody C2S Connections")
|
| 49 |
print("graph_vlabel users")
|
| 50 |
print("graph_category chat")
|
| 51 |
|
| 52 |
print("all_client_connections.label client connections")
|
| 53 |
print("secure_client_connections.label secure client connections")
|
| 54 |
print("insecure_client_connections.label insecure client connections")
|
| 55 |
sys.exit(0) |
| 56 |
|
| 57 |
else: |
| 58 |
connection_count_re = re.compile(r"Total:\s(\d+)\s") |
| 59 |
telnet = telnetlib.Telnet(host, port) |
| 60 |
telnet.write("c2s:show_secure()\n")
|
| 61 |
telnet_response = telnet.read_until("secure client connections", 5)
|
| 62 |
parsed_info = connection_count_re.findall(telnet_response) |
| 63 |
secure_client_connections = int(parsed_info[0]) |
| 64 |
print("secure_client_connections.value %s" % secure_client_connections)
|
| 65 |
|
| 66 |
telnet.write("c2s:show_insecure()\n")
|
| 67 |
telnet_response = telnet.read_until("insecure client connections", 5)
|
| 68 |
parsed_info = connection_count_re.findall(telnet_response) |
| 69 |
insecure_client_connections = int(parsed_info[0]) |
| 70 |
print("insecure_client_connections.value %s" % insecure_client_connections)
|
| 71 |
all_client_connections = secure_client_connections + insecure_client_connections |
| 72 |
print("all_client_connections.value %s" % (all_client_connections))
|
| 73 |
telnet.write("quit\n")
|
| 74 |
|
| 75 |
elif wildcard == "s2s": |
| 76 |
if mode == "config": |
| 77 |
print("graph_title Prosody S2S Connections")
|
| 78 |
print("graph_vlabel servers")
|
| 79 |
print("graph_category chat")
|
| 80 |
|
| 81 |
print("outgoing_connections.label outgoing connections")
|
| 82 |
print("incoming_connections.label incoming connections")
|
| 83 |
sys.exit(0) |
| 84 |
|
| 85 |
else: |
| 86 |
server_connections_re = re.compile(r"(\d+) outgoing, (\d+)") |
| 87 |
telnet = telnetlib.Telnet(host, port) |
| 88 |
telnet.write("s2s:show()\n")
|
| 89 |
telnet_response = telnet.read_until("connections", 5)
|
| 90 |
parsed_info = server_connections_re.findall(telnet_response) |
| 91 |
print("outgoing_connections.value %s" % (parsed_info[0][0]))
|
| 92 |
print("incoming_connections.value %s" % (parsed_info[0][1]))
|
| 93 |
telnet.write("quit\n")
|
| 94 |
|
| 95 |
elif wildcard == "presence": |
| 96 |
if mode == "config": |
| 97 |
print("graph_title Prosody Client Presence")
|
| 98 |
print("graph_vlabel clients")
|
| 99 |
print("graph_category chat")
|
| 100 |
|
| 101 |
print("available.label Avaible Clients")
|
| 102 |
print("chat.label Ready for Chat Clients")
|
| 103 |
print("away.label Away Clients")
|
| 104 |
print("xa.label Extended Away Clients")
|
| 105 |
print("dnd.label Do Not Disturb Clients")
|
| 106 |
sys.exit(0) |
| 107 |
|
| 108 |
else: |
| 109 |
client_presence_re = re.compile(r"[-\]] (.*?)\(\d+\)") |
| 110 |
telnet = telnetlib.Telnet(host, port) |
| 111 |
telnet.write("c2s:show()\n")
|
| 112 |
telnet_response = telnet.read_until("clients", 5)
|
| 113 |
parsed_info = client_presence_re.findall(telnet_response) |
| 114 |
print("available.value %s" % parsed_info.count("available"))
|
| 115 |
print("chat.value %s" % (parsed_info.count("chat")))
|
| 116 |
print("away.value %s" % (parsed_info.count("away")))
|
| 117 |
print("xa.value %s" % (parsed_info.count("xa")))
|
| 118 |
print("dnd.value %s" % (parsed_info.count("dnd")))
|
| 119 |
telnet.write("quit\n")
|
| 120 |
|
| 121 |
elif wildcard == "uptime": |
| 122 |
if mode == "config": |
| 123 |
print("graph_title Prosody Uptime")
|
| 124 |
print("graph_args --base 1000 -l 0")
|
| 125 |
print("graph_scale no")
|
| 126 |
print("graph_vlabel uptime in days")
|
| 127 |
print("graph_category chat")
|
| 128 |
print("graph_order uptime")
|
| 129 |
print("uptime.draw AREA")
|
| 130 |
print("uptime.min U")
|
| 131 |
print("uptime.max U")
|
| 132 |
print("uptime.label uptime")
|
| 133 |
print("uptime.type GAUGE")
|
| 134 |
sys.exit(0) |
| 135 |
|
| 136 |
else: |
| 137 |
uptime_re = re.compile(r"\d+") |
| 138 |
telnet = telnetlib.Telnet(host, port) |
| 139 |
telnet.write("server:uptime()\n")
|
| 140 |
telnet_response = telnet.read_until("minutes (", 5)
|
| 141 |
parsed_info = uptime_re.findall(telnet_response) |
| 142 |
uptime_value = (float(parsed_info[0]) + float(parsed_info[1]) / 24 |
| 143 |
+ float(parsed_info[2]) / 60 / 24) |
| 144 |
print("uptime.value %s" % (uptime_value))
|
| 145 |
telnet.write("quit\n")
|
| 146 |
|
| 147 |
elif wildcard == "users": |
| 148 |
if mode == "config": |
| 149 |
print("graph_title Prosody Registered Users")
|
| 150 |
print("graph_vlabel users")
|
| 151 |
print("graph_category chat")
|
| 152 |
|
| 153 |
base_dir = os.environ.get('internal_storage_path', "/var/lib/prosody")
|
| 154 |
if os.path.isdir(base_dir): |
| 155 |
vhosts = listdirs(base_dir) |
| 156 |
for vhost in vhosts: |
| 157 |
account_dir = os.path.join(base_dir, vhost, "accounts") |
| 158 |
if os.path.isdir(account_dir): |
| 159 |
vhost = vhost.replace("%2e", ".")
|
| 160 |
munin_var = vhost.replace(".", "_")
|
| 161 |
if mode == "config": |
| 162 |
print("%s.label %s" % (munin_var, vhost))
|
| 163 |
else: |
| 164 |
accounts = len(list(listfiles(account_dir))) |
| 165 |
print("%s.value %s" % (munin_var, accounts))
|
| 166 |
|
| 167 |
|
| 168 |
def listdirs(folder): |
| 169 |
for x in os.listdir(folder): |
| 170 |
if os.path.isdir(os.path.join(folder, x)): |
| 171 |
yield x |
| 172 |
|
| 173 |
|
| 174 |
def listfiles(folder): |
| 175 |
for x in os.listdir(folder): |
| 176 |
if os.path.isfile(os.path.join(folder, x)): |
| 177 |
yield x |
| 178 |
|
| 179 |
|
| 180 |
if __name__ == '__main__': |
| 181 |
main() |
| 182 |
|
| 183 |
|
| 184 |
# Here starts the prosody_ plugin documentation, intended to be used with munindoc and in |
| 185 |
# plugin gallery. |
| 186 |
""" |
| 187 |
=head1 NAME |
| 188 |
|
| 189 |
prosody_ - Munin wildcard-plugin to monitor a L<Prosody|http://prosody.im> xmpp server. |
| 190 |
|
| 191 |
This wildcard plugin provides at the moment only the suffixes C<c2s>, C<s2s>, C<presence>, |
| 192 |
C<uptime> and C<users> suffixes. |
| 193 |
|
| 194 |
=head1 INSTALLATION |
| 195 |
|
| 196 |
It is very simple to install the plugin. |
| 197 |
|
| 198 |
=over 2 |
| 199 |
|
| 200 |
cd /usr/share/munin/plugins (or your munin plugins directory) |
| 201 |
wget https://github.com/jarus/munin-prosody/raw/master/prosody_ |
| 202 |
chmod 755 prosody_ |
| 203 |
|
| 204 |
ln -s /usr/share/munin/plugins/prosody_ /etc/munin/plugins/prosody_c2s |
| 205 |
ln -s /usr/share/munin/plugins/prosody_ /etc/munin/plugins/prosody_s2s |
| 206 |
ln -s /usr/share/munin/plugins/prosody_ /etc/munin/plugins/prosody_presence |
| 207 |
ln -s /usr/share/munin/plugins/prosody_ /etc/munin/plugins/prosody_uptime |
| 208 |
ln -s /usr/share/munin/plugins/prosody_ /etc/munin/plugins/prosody_users |
| 209 |
|
| 210 |
=back |
| 211 |
|
| 212 |
After the installation you need to restart your munin-node: |
| 213 |
|
| 214 |
=over 2 |
| 215 |
|
| 216 |
service munin-node restart |
| 217 |
|
| 218 |
=back |
| 219 |
|
| 220 |
=head1 CONFIGURATION |
| 221 |
|
| 222 |
When you want to change the default host (localhost) and port (5582) do it in a file named prosody |
| 223 |
placed in the directory /etc/munin/plugin-conf.d/ with a config like this: |
| 224 |
|
| 225 |
=over 2 |
| 226 |
|
| 227 |
[prosody_*] |
| 228 |
env.host example.com |
| 229 |
env.port 5582 |
| 230 |
|
| 231 |
=back |
| 232 |
|
| 233 |
If you want to get the number of registered users, add the following lines to |
| 234 |
/etc/munin/plugin-conf.d/prosody: |
| 235 |
|
| 236 |
=over 2 |
| 237 |
|
| 238 |
[prosody_users] |
| 239 |
user prosody |
| 240 |
group prosody |
| 241 |
|
| 242 |
=back |
| 243 |
|
| 244 |
=head1 VERSION |
| 245 |
|
| 246 |
Version 2.2 |
| 247 |
|
| 248 |
=head1 BUGS |
| 249 |
|
| 250 |
None known |
| 251 |
|
| 252 |
=head1 AUTHOR |
| 253 |
|
| 254 |
(C) 2010 Christoph Heer <Christoph.Heer@googlemail.com> |
| 255 |
|
| 256 |
=head1 LICENSE |
| 257 |
|
| 258 |
Permission is hereby granted, free of charge, to any person obtaining a |
| 259 |
copy of this software and associated documentation files (the \"Software\"), |
| 260 |
to deal in the Software without restriction, including without limitation |
| 261 |
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 262 |
and/or sell copies of the Software, and to permit persons to whom the |
| 263 |
Software is furnished to do so, subject to the following conditions: |
| 264 |
|
| 265 |
The above copyright notice and this permission notice shall be included in |
| 266 |
all copies or substantial portions of the Software. |
| 267 |
|
| 268 |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 269 |
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 270 |
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 271 |
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 272 |
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 273 |
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 274 |
DEALINGS IN THE SOFTWARE. |
| 275 |
|
| 276 |
|
| 277 |
=cut |
| 278 |
|
| 279 |
|
| 280 |
""" |
