Révision 98106443
Plugin prosody_: fix style issues
| plugins/prosody/prosody_ | ||
|---|---|---|
| 25 | 25 |
import telnetlib |
| 26 | 26 |
import re |
| 27 | 27 |
|
| 28 |
|
|
| 28 | 29 |
def main(): |
| 29 | 30 |
try: |
| 30 | 31 |
mode = sys.argv[1] |
| ... | ... | |
| 35 | 36 |
port = int(os.environ.get('port', 5582))
|
| 36 | 37 |
|
| 37 | 38 |
if mode == "suggest": |
| 38 |
print "c2s"
|
|
| 39 |
print "s2s"
|
|
| 40 |
print "presence"
|
|
| 41 |
print "uptime"
|
|
| 42 |
print "users"
|
|
| 39 |
print("c2s")
|
|
| 40 |
print("s2s")
|
|
| 41 |
print("presence")
|
|
| 42 |
print("uptime")
|
|
| 43 |
print("users")
|
|
| 43 | 44 |
sys.exit(0) |
| 44 | 45 |
|
| 45 | 46 |
if wildcard == "c2s": |
| 46 | 47 |
if mode == "config": |
| 47 |
print "graph_title Prosody C2S Connections" |
|
| 48 |
print "graph_vlabel users" |
|
| 49 |
print "graph_category chat" |
|
| 50 |
|
|
| 51 |
print "all_client_connections.label client connections" |
|
| 52 |
print "secure_client_connections.label secure client connections" |
|
| 53 |
print "insecure_client_connections.label insecure client " \ |
|
| 54 |
"connections" |
|
| 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 | 55 |
sys.exit(0) |
| 56 | 56 |
|
| 57 | 57 |
else: |
| 58 | 58 |
connection_count_re = re.compile(r"Total:\s(\d+)\s") |
| 59 | 59 |
telnet = telnetlib.Telnet(host, port) |
| 60 | 60 |
telnet.write("c2s:show_secure()\n")
|
| 61 |
telnet_response = telnet.read_until("secure client connections",
|
|
| 62 |
5) |
|
| 61 |
telnet_response = telnet.read_until("secure client connections", 5)
|
|
| 63 | 62 |
parsed_info = connection_count_re.findall(telnet_response) |
| 64 | 63 |
secure_client_connections = int(parsed_info[0]) |
| 65 |
print "secure_client_connections.value %s" % \ |
|
| 66 |
(secure_client_connections) |
|
| 64 |
print("secure_client_connections.value %s" % secure_client_connections)
|
|
| 67 | 65 |
|
| 68 | 66 |
telnet.write("c2s:show_insecure()\n")
|
| 69 |
telnet_response = telnet.read_until("insecure client connections",
|
|
| 70 |
5) |
|
| 67 |
telnet_response = telnet.read_until("insecure client connections", 5)
|
|
| 71 | 68 |
parsed_info = connection_count_re.findall(telnet_response) |
| 72 | 69 |
insecure_client_connections = int(parsed_info[0]) |
| 73 |
print "insecure_client_connections.value %s" % \ |
|
| 74 |
(insecure_client_connections) |
|
| 75 |
all_client_connections = secure_client_connections + \ |
|
| 76 |
insecure_client_connections |
|
| 77 |
print "all_client_connections.value %s" % (all_client_connections) |
|
| 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))
|
|
| 78 | 73 |
telnet.write("quit\n")
|
| 79 | 74 |
|
| 80 | 75 |
elif wildcard == "s2s": |
| 81 | 76 |
if mode == "config": |
| 82 |
print "graph_title Prosody S2S Connections"
|
|
| 83 |
print "graph_vlabel servers"
|
|
| 84 |
print "graph_category chat"
|
|
| 77 |
print("graph_title Prosody S2S Connections")
|
|
| 78 |
print("graph_vlabel servers")
|
|
| 79 |
print("graph_category chat")
|
|
| 85 | 80 |
|
| 86 |
print "outgoing_connections.label outgoing connections"
|
|
| 87 |
print "incoming_connections.label incoming connections"
|
|
| 81 |
print("outgoing_connections.label outgoing connections")
|
|
| 82 |
print("incoming_connections.label incoming connections")
|
|
| 88 | 83 |
sys.exit(0) |
| 89 | 84 |
|
| 90 | 85 |
else: |
| ... | ... | |
| 93 | 88 |
telnet.write("s2s:show()\n")
|
| 94 | 89 |
telnet_response = telnet.read_until("connections", 5)
|
| 95 | 90 |
parsed_info = server_connections_re.findall(telnet_response) |
| 96 |
print "outgoing_connections.value %s" % (parsed_info[0][0])
|
|
| 97 |
print "incoming_connections.value %s" % (parsed_info[0][1])
|
|
| 91 |
print("outgoing_connections.value %s" % (parsed_info[0][0]))
|
|
| 92 |
print("incoming_connections.value %s" % (parsed_info[0][1]))
|
|
| 98 | 93 |
telnet.write("quit\n")
|
| 99 | 94 |
|
| 100 | 95 |
elif wildcard == "presence": |
| 101 | 96 |
if mode == "config": |
| 102 |
print "graph_title Prosody Client Presence"
|
|
| 103 |
print "graph_vlabel clients"
|
|
| 104 |
print "graph_category chat"
|
|
| 105 |
|
|
| 106 |
print "available.label Avaible Clients"
|
|
| 107 |
print "chat.label Ready for Chat Clients"
|
|
| 108 |
print "away.label Away Clients"
|
|
| 109 |
print "xa.label Extended Away Clients"
|
|
| 110 |
print "dnd.label Do Not Disturb Clients"
|
|
| 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")
|
|
| 111 | 106 |
sys.exit(0) |
| 112 | 107 |
|
| 113 | 108 |
else: |
| ... | ... | |
| 116 | 111 |
telnet.write("c2s:show()\n")
|
| 117 | 112 |
telnet_response = telnet.read_until("clients", 5)
|
| 118 | 113 |
parsed_info = client_presence_re.findall(telnet_response) |
| 119 |
print "available.value %s" % (parsed_info.count("available"))
|
|
| 120 |
print "chat.value %s" % (parsed_info.count("chat"))
|
|
| 121 |
print "away.value %s" % (parsed_info.count("away"))
|
|
| 122 |
print "xa.value %s" % (parsed_info.count("xa"))
|
|
| 123 |
print "dnd.value %s" % (parsed_info.count("dnd"))
|
|
| 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")))
|
|
| 124 | 119 |
telnet.write("quit\n")
|
| 125 | 120 |
|
| 126 | 121 |
elif wildcard == "uptime": |
| 127 | 122 |
if mode == "config": |
| 128 |
print "graph_title Prosody Uptime"
|
|
| 129 |
print "graph_args --base 1000 -l 0"
|
|
| 130 |
print "graph_scale no"
|
|
| 131 |
print "graph_vlabel uptime in days"
|
|
| 132 |
print "graph_category chat"
|
|
| 133 |
print "graph_order uptime"
|
|
| 134 |
print "uptime.draw AREA"
|
|
| 135 |
print "uptime.min U"
|
|
| 136 |
print "uptime.max U"
|
|
| 137 |
print "uptime.label uptime"
|
|
| 138 |
print "uptime.type GAUGE"
|
|
| 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")
|
|
| 139 | 134 |
sys.exit(0) |
| 140 | 135 |
|
| 141 | 136 |
else: |
| ... | ... | |
| 144 | 139 |
telnet.write("server:uptime()\n")
|
| 145 | 140 |
telnet_response = telnet.read_until("minutes (", 5)
|
| 146 | 141 |
parsed_info = uptime_re.findall(telnet_response) |
| 147 |
uptime_value = float(parsed_info[0]) + float(parsed_info[1])/24 +\
|
|
| 148 |
float(parsed_info[2])/60/24
|
|
| 149 |
print "uptime.value %s" % (uptime_value)
|
|
| 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))
|
|
| 150 | 145 |
telnet.write("quit\n")
|
| 151 | 146 |
|
| 152 | 147 |
elif wildcard == "users": |
| 153 | 148 |
if mode == "config": |
| 154 |
print "graph_title Prosody Registered Users"
|
|
| 155 |
print "graph_vlabel users"
|
|
| 156 |
print "graph_category chat"
|
|
| 149 |
print("graph_title Prosody Registered Users")
|
|
| 150 |
print("graph_vlabel users")
|
|
| 151 |
print("graph_category chat")
|
|
| 157 | 152 |
|
| 158 | 153 |
base_dir = os.environ.get('internal_storage_path', "/var/lib/prosody")
|
| 159 | 154 |
if os.path.isdir(base_dir): |
| ... | ... | |
| 161 | 156 |
for vhost in vhosts: |
| 162 | 157 |
account_dir = os.path.join(base_dir, vhost, "accounts") |
| 163 | 158 |
if os.path.isdir(account_dir): |
| 164 |
vhost = vhost.replace("%2e",".")
|
|
| 165 |
munin_var = vhost.replace(".","_")
|
|
| 159 |
vhost = vhost.replace("%2e", ".")
|
|
| 160 |
munin_var = vhost.replace(".", "_")
|
|
| 166 | 161 |
if mode == "config": |
| 167 |
print "%s.label %s" % (munin_var, vhost)
|
|
| 162 |
print("%s.label %s" % (munin_var, vhost))
|
|
| 168 | 163 |
else: |
| 169 | 164 |
accounts = len(list(listfiles(account_dir))) |
| 170 |
print "%s.value %s" % (munin_var, accounts) |
|
| 165 |
print("%s.value %s" % (munin_var, accounts))
|
|
| 166 |
|
|
| 171 | 167 |
|
| 172 | 168 |
def listdirs(folder): |
| 173 | 169 |
for x in os.listdir(folder): |
| 174 | 170 |
if os.path.isdir(os.path.join(folder, x)): |
| 175 | 171 |
yield x |
| 176 | 172 |
|
| 173 |
|
|
| 177 | 174 |
def listfiles(folder): |
| 178 | 175 |
for x in os.listdir(folder): |
| 179 | 176 |
if os.path.isfile(os.path.join(folder, x)): |
| 180 | 177 |
yield x |
| 181 | 178 |
|
| 179 |
|
|
| 182 | 180 |
if __name__ == '__main__': |
| 183 | 181 |
main() |
| 184 | 182 |
|
| 185 | 183 |
|
| 186 |
### Here starts the prosody_ plugin documentation, intended to be used with munindoc and in plugin gallery |
|
| 184 |
# Here starts the prosody_ plugin documentation, intended to be used with munindoc and in |
|
| 185 |
# plugin gallery. |
|
| 187 | 186 |
""" |
| 188 | 187 |
=head1 NAME |
| 189 | 188 |
|
| 190 | 189 |
prosody_ - Munin wildcard-plugin to monitor a L<Prosody|http://prosody.im> xmpp server. |
| 191 | 190 |
|
| 192 |
This wildcard plugin provides at the moment only the suffixes C<c2s>, C<s2s>, C<presence>, C<uptime> and C<users> suffixes. |
|
| 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 | 193 |
|
| 194 | 194 |
=head1 INSTALLATION |
| 195 | 195 |
|
| ... | ... | |
| 219 | 219 |
|
| 220 | 220 |
=head1 CONFIGURATION |
| 221 | 221 |
|
| 222 |
When you want to change the default host (localhost) and port (5582) do it in a file named prosody
|
|
| 222 |
When you want to change the default host (localhost) and port (5582) do it in a file named prosody |
|
| 223 | 223 |
placed in the directory /etc/munin/plugin-conf.d/ with a config like this: |
| 224 | 224 |
|
| 225 | 225 |
=over 2 |
| ... | ... | |
| 230 | 230 |
|
| 231 | 231 |
=back |
| 232 | 232 |
|
| 233 |
If you want to get the number of registered users, add the following lines to /etc/munin/plugin-conf.d/prosody: |
|
| 233 |
If you want to get the number of registered users, add the following lines to |
|
| 234 |
/etc/munin/plugin-conf.d/prosody: |
|
| 234 | 235 |
|
| 235 | 236 |
=over 2 |
| 236 | 237 |
|
Formats disponibles : Unified diff