Révision c653988d
Can monitor uptime and number of registered users
| plugins/other/prosody | ||
|---|---|---|
| 19 | 19 |
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 20 | 20 |
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 21 | 21 |
# DEALINGS IN THE SOFTWARE. |
| 22 |
# |
|
| 23 |
# |
|
| 24 |
# Changelog: |
|
| 25 |
# 2011-09-30: Christian Bendt (mail@m3d1c5.org) |
|
| 26 |
# Added "uptime" and "users" |
|
| 27 |
# To read the number of registered users, add the following lines |
|
| 28 |
# in /etc/munin/plugin-conf.d/munin-node on debian |
|
| 29 |
# [prosody_*] |
|
| 30 |
# user prosody |
|
| 31 |
# group prosody |
|
| 22 | 32 |
|
| 23 | 33 |
import sys |
| 24 | 34 |
import os |
| ... | ... | |
| 38 | 48 |
print "c2s" |
| 39 | 49 |
print "s2s" |
| 40 | 50 |
print "presence" |
| 51 |
print "uptime" |
|
| 52 |
print "users" |
|
| 41 | 53 |
sys.exit(0) |
| 42 | 54 |
|
| 43 | 55 |
if wildcard == "c2s": |
| ... | ... | |
| 117 | 129 |
print "away.value %s" % (parsed_info.count("away"))
|
| 118 | 130 |
print "xa.value %s" % (parsed_info.count("xa"))
|
| 119 | 131 |
print "dnd.value %s" % (parsed_info.count("dnd"))
|
| 132 |
|
|
| 133 |
elif wildcard == "uptime": |
|
| 134 |
if mode == "config": |
|
| 135 |
print "graph_title Prosody Uptime" |
|
| 136 |
print "graph_args --base 1000 -l 0" |
|
| 137 |
print "graph_scale no" |
|
| 138 |
print "graph_vlabel uptime in days" |
|
| 139 |
print "graph_category Prosody" |
|
| 140 |
print "graph_order uptime" |
|
| 141 |
print "uptime.draw AREA" |
|
| 142 |
print "uptime.min U" |
|
| 143 |
print "uptime.max U" |
|
| 144 |
print "uptime.label uptime" |
|
| 145 |
print "uptime.type GAUGE" |
|
| 146 |
sys.exit(0) |
|
| 147 |
|
|
| 148 |
else: |
|
| 149 |
uptime_re = re.compile(r"\d+") |
|
| 150 |
telnet = telnetlib.Telnet(host, port) |
|
| 151 |
telnet.write("server:uptime()")
|
|
| 152 |
telnet_response = telnet.read_until("minutes (", 5)
|
|
| 153 |
parsed_info = uptime_re.findall(telnet_response) |
|
| 154 |
uptime_value = float(parsed_info[0]) + float(parsed_info[1])/24 + float(parsed_info[2])/60/24 |
|
| 155 |
print "uptime.value %s" % (uptime_value) |
|
| 156 |
|
|
| 157 |
elif wildcard == "users": |
|
| 158 |
if mode == "config": |
|
| 159 |
print "graph_title Prosody Registered Users" |
|
| 160 |
print "graph_vlabel users" |
|
| 161 |
print "graph_category Prosody" |
|
| 162 |
|
|
| 163 |
basedir = "/var/lib/prosody" |
|
| 164 |
if os.path.exists(basedir): |
|
| 165 |
vhosts = listdirs(basedir) |
|
| 166 |
for vhost in vhosts: |
|
| 167 |
accountdir = basedir + os.sep + vhost + os.sep + "accounts" |
|
| 168 |
if os.path.exists(accountdir): |
|
| 169 |
accounts = listfiles(accountdir) |
|
| 170 |
headcount = 0 |
|
| 171 |
for account in accounts: |
|
| 172 |
headcount += 1 |
|
| 173 |
if mode == "config": |
|
| 174 |
print vhost.replace("%2e","_") + ".label %s" % (vhost.replace("%2e","."))
|
|
| 175 |
else: |
|
| 176 |
print vhost.replace("%2e","_") + ".value %s" % (headcount)
|
|
| 177 |
|
|
| 178 |
def listdirs(folder): |
|
| 179 |
return [d for d in os.listdir(folder) if os.path.isdir(os.path.join(folder, d))] |
|
| 180 |
|
|
| 181 |
def listfiles(folder): |
|
| 182 |
return [d for d in os.listdir(folder) if os.path.isfile(os.path.join(folder, d))] |
|
| 120 | 183 |
|
| 121 | 184 |
if __name__ == '__main__': |
| 122 | 185 |
main() |
Formats disponibles : Unified diff