metrics: use inherits of control/api
This commit is contained in:
parent
bfa47d1ae0
commit
6bb4308de2
38
metrics.py
38
metrics.py
|
@ -8,17 +8,15 @@ from control import EjabberdCtl
|
||||||
nat64 = ipaddress.ip_network("64:ff9b::/96")
|
nat64 = ipaddress.ip_network("64:ff9b::/96")
|
||||||
|
|
||||||
|
|
||||||
class EjabberdMetrics:
|
class EjabberdMetrics(EjabberdCtl):
|
||||||
"""
|
"""
|
||||||
class to fetch metrics per xmlrpc
|
class to fetch metrics per xmlrpc
|
||||||
"""
|
"""
|
||||||
def __init__(self, url, login=None, api="rpc", muc_host: str = 'conference'):
|
def __init__(self, url, login=None, api="rpc", muc_host: str = 'conference'):
|
||||||
# init ejabberd api
|
# init ejabberd api
|
||||||
self.api = EjabberdCtl(url, login, api)
|
super().__init__(url, login, api)
|
||||||
self._cmd = self.api.cmd
|
|
||||||
|
|
||||||
# variables
|
# variables
|
||||||
self._verstring = self.api.verstring
|
|
||||||
self.muc_host = muc_host
|
self.muc_host = muc_host
|
||||||
|
|
||||||
def _client(self, resource):
|
def _client(self, resource):
|
||||||
|
@ -58,26 +56,26 @@ class EjabberdMetrics:
|
||||||
def fetch_muc(self, vhost=None):
|
def fetch_muc(self, vhost=None):
|
||||||
host = "global"
|
host = "global"
|
||||||
if vhost is not None:
|
if vhost is not None:
|
||||||
if self._verstring.major >= 19:
|
if self.verstring.major >= 19:
|
||||||
host = '.'.join([self.muc_host, vhost])
|
host = '.'.join([self.muc_host, vhost])
|
||||||
else:
|
else:
|
||||||
host = vhost
|
host = vhost
|
||||||
result = self._cmd("muc_online_rooms", {"host": host})
|
result = self.cmd("muc_online_rooms", {"host": host})
|
||||||
if "rooms" in result:
|
if "rooms" in result:
|
||||||
return len(result["rooms"])
|
return len(result["rooms"])
|
||||||
return len(result)
|
return len(result)
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
# nodes
|
# nodes
|
||||||
self._nodes = self.api.fetch_nodes()
|
self._nodes = self.fetch_nodes()
|
||||||
|
|
||||||
# vhosts
|
# vhosts
|
||||||
self._vhosts = self.api.fetch_vhosts()
|
self._vhosts = self.fetch_vhosts()
|
||||||
|
|
||||||
# registered
|
# registered
|
||||||
if not hasattr(self, "_registered"):
|
if not hasattr(self, "_registered"):
|
||||||
self._registered = {}
|
self._registered = {}
|
||||||
self._registered[None] = self.api.fetch_registered()
|
self._registered[None] = self.fetch_registered()
|
||||||
|
|
||||||
# muc
|
# muc
|
||||||
if not hasattr(self, "_muc"):
|
if not hasattr(self, "_muc"):
|
||||||
|
@ -86,20 +84,20 @@ class EjabberdMetrics:
|
||||||
|
|
||||||
# registered + muc
|
# registered + muc
|
||||||
for vhost in self._vhosts:
|
for vhost in self._vhosts:
|
||||||
self._registered[vhost] = self.api.fetch_registered(vhost)
|
self._registered[vhost] = self.fetch_registered(vhost)
|
||||||
self._muc[vhost] = self.fetch_muc(vhost)
|
self._muc[vhost] = self.fetch_muc(vhost)
|
||||||
|
|
||||||
# online user
|
# online user
|
||||||
self._onlineuser = self.api.fetch_onlineuser()
|
self._onlineuser = self.fetch_onlineuser()
|
||||||
|
|
||||||
# s2s
|
# s2s
|
||||||
self._s2s_in = self.api.fetch_s2s_in()
|
self._s2s_in = self.fetch_s2s_in()
|
||||||
self._s2s_out = self.api.fetch_s2s_out()
|
self._s2s_out = self.fetch_s2s_out()
|
||||||
|
|
||||||
def get_online_by(self, by="node", parse=None, vhost=None, node=None):
|
def get_online_by(self, by="node", parse=None, vhost=None, node=None):
|
||||||
parser = parse or (lambda a: a)
|
parser = parse or (lambda a: a)
|
||||||
if not hasattr(self, "_onlineuser"):
|
if not hasattr(self, "_onlineuser"):
|
||||||
self._onlineuser = self.api.fetch_onlineuser()
|
self._onlineuser = self.fetch_onlineuser()
|
||||||
data = {}
|
data = {}
|
||||||
|
|
||||||
for conn in self._onlineuser:
|
for conn in self._onlineuser:
|
||||||
|
@ -137,7 +135,7 @@ class EjabberdMetrics:
|
||||||
def get_online_client_by(self, by="ip", parse=None, vhost=None, node=None):
|
def get_online_client_by(self, by="ip", parse=None, vhost=None, node=None):
|
||||||
parser = parse or self._ipversion
|
parser = parse or self._ipversion
|
||||||
if not hasattr(self, "_onlineuser"):
|
if not hasattr(self, "_onlineuser"):
|
||||||
self._onlineuser = self.api.fetch_onlineuser()
|
self._onlineuser = self.fetch_onlineuser()
|
||||||
data = {}
|
data = {}
|
||||||
|
|
||||||
for conn in self._onlineuser:
|
for conn in self._onlineuser:
|
||||||
|
@ -166,7 +164,7 @@ class EjabberdMetrics:
|
||||||
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.api.fetch_registered(vhost)
|
self._registered[vhost] = self.fetch_registered(vhost)
|
||||||
return self._registered[vhost]
|
return self._registered[vhost]
|
||||||
|
|
||||||
def get_muc(self, vhost=None):
|
def get_muc(self, vhost=None):
|
||||||
|
@ -178,17 +176,17 @@ class EjabberdMetrics:
|
||||||
|
|
||||||
def get_vhosts(self):
|
def get_vhosts(self):
|
||||||
if not hasattr(self, "_vhosts"):
|
if not hasattr(self, "_vhosts"):
|
||||||
self._vhosts = self.api.fetch_vhosts()
|
self._vhosts = self.fetch_vhosts()
|
||||||
return self._vhosts
|
return self._vhosts
|
||||||
|
|
||||||
def get_s2s_in(self):
|
def get_s2s_in(self):
|
||||||
if not hasattr(self, "_s2s_in"):
|
if not hasattr(self, "_s2s_in"):
|
||||||
self._s2s_in = self.api.fetch_s2s_in()
|
self._s2s_in = self.fetch_s2s_in()
|
||||||
return self._s2s_in
|
return self._s2s_in
|
||||||
|
|
||||||
def get_s2s_out(self):
|
def get_s2s_out(self):
|
||||||
if not hasattr(self, "_s2s_out"):
|
if not hasattr(self, "_s2s_out"):
|
||||||
self._s2s_out = self.api.fetch_s2s_out()
|
self._s2s_out = self.fetch_s2s_out()
|
||||||
return self._s2s_out
|
return self._s2s_out
|
||||||
|
|
||||||
def get_vhost_metrics(self, vhost):
|
def get_vhost_metrics(self, vhost):
|
||||||
|
@ -206,7 +204,7 @@ class EjabberdMetrics:
|
||||||
|
|
||||||
def get_nodes(self):
|
def get_nodes(self):
|
||||||
if not hasattr(self, "_nodes"):
|
if not hasattr(self, "_nodes"):
|
||||||
self._nodes = self.api.fetch_nodes()
|
self._nodes = self.fetch_nodes()
|
||||||
return self._nodes
|
return self._nodes
|
||||||
|
|
||||||
def get_node_metrics(self, node):
|
def get_node_metrics(self, node):
|
||||||
|
|
Loading…
Reference in New Issue