improve control.py

This commit is contained in:
genofire 2020-06-10 12:48:18 +02:00
parent 6bb4308de2
commit dd30520c62
2 changed files with 19 additions and 19 deletions

View File

@ -73,7 +73,7 @@ class EjabberdCtl(EjabberdApi):
return result return result
return result["s2s_outgoing"] return result["s2s_outgoing"]
def fetch_registered(self, vhost=None): def fetch_registered_count(self, vhost=None):
if vhost is None: if vhost is None:
result = self.cmd("stats", {"name":"registeredusers"}) result = self.cmd("stats", {"name":"registeredusers"})
if "stat" in result: if "stat" in result:
@ -82,3 +82,15 @@ class EjabberdCtl(EjabberdApi):
result = self.cmd("stats_host", {"name":"registeredusers", "host": vhost}) result = self.cmd("stats_host", {"name":"registeredusers", "host": vhost})
if "stat" in result: if "stat" in result:
return result["stat"] return result["stat"]
def fetch_muc_count(self, vhost=None, muc_host="conference"):
host = "global"
if vhost is not None:
if self.verstring.major >= 19:
host = '.'.join([muc_host, vhost])
else:
host = vhost
result = self.cmd("muc_online_rooms", {"host": host})
if "rooms" in result:
return len(result["rooms"])
return len(result)

View File

@ -53,18 +53,6 @@ class EjabberdMetrics(EjabberdCtl):
return 4 return 4
return addr.version return addr.version
def fetch_muc(self, vhost=None):
host = "global"
if vhost is not None:
if self.verstring.major >= 19:
host = '.'.join([self.muc_host, vhost])
else:
host = vhost
result = self.cmd("muc_online_rooms", {"host": host})
if "rooms" in result:
return len(result["rooms"])
return len(result)
def update(self): def update(self):
# nodes # nodes
self._nodes = self.fetch_nodes() self._nodes = self.fetch_nodes()
@ -75,17 +63,17 @@ class EjabberdMetrics(EjabberdCtl):
# registered # registered
if not hasattr(self, "_registered"): if not hasattr(self, "_registered"):
self._registered = {} self._registered = {}
self._registered[None] = self.fetch_registered() self._registered[None] = self.fetch_registered_count()
# muc # muc
if not hasattr(self, "_muc"): if not hasattr(self, "_muc"):
self._muc = {} self._muc = {}
self._muc[None] = self.fetch_muc() self._muc[None] = self.fetch_muc_count()
# registered + muc # registered + muc
for vhost in self._vhosts: for vhost in self._vhosts:
self._registered[vhost] = self.fetch_registered(vhost) self._registered[vhost] = self.fetch_registered_count(vhost)
self._muc[vhost] = self.fetch_muc(vhost) self._muc[vhost] = self.fetch_muc_count(vhost)
# online user # online user
self._onlineuser = self.fetch_onlineuser() self._onlineuser = self.fetch_onlineuser()
@ -164,14 +152,14 @@ class EjabberdMetrics(EjabberdCtl):
if not hasattr(self, "_registered"): if not hasattr(self, "_registered"):
self._registered = {} self._registered = {}
if vhost not in self._registered: if vhost not in self._registered:
self._registered[vhost] = self.fetch_registered(vhost) self._registered[vhost] = self.fetch_registered_count(vhost)
return self._registered[vhost] return self._registered[vhost]
def get_muc(self, vhost=None): def get_muc(self, vhost=None):
if not hasattr(self, "_muc"): if not hasattr(self, "_muc"):
self._muc = {} self._muc = {}
if vhost not in self._muc: if vhost not in self._muc:
self._muc[vhost] = self.fetch_muc(vhost) self._muc[vhost] = self.fetch_muc_count(vhost)
return self._muc[vhost] return self._muc[vhost]
def get_vhosts(self): def get_vhosts(self):