aboutsummaryrefslogtreecommitdiffstats
path: root/metrics.py
diff options
context:
space:
mode:
Diffstat (limited to 'metrics.py')
-rwxr-xr-xmetrics.py58
1 files changed, 22 insertions, 36 deletions
diff --git a/metrics.py b/metrics.py
index ad23033..bd8a3ea 100755
--- a/metrics.py
+++ b/metrics.py
@@ -2,23 +2,21 @@
# -*- coding: utf-8 -*-
import ipaddress
-from control import EjabberdCtl
+from calls import EjabberdApiCalls
# rfc6052: IPv6 Addressing of IPv4/IPv6 Translators
nat64 = ipaddress.ip_network("64:ff9b::/96")
-class EjabberdMetrics:
+class EjabberdMetrics(EjabberdApiCalls):
"""
class to fetch metrics per xmlrpc
"""
def __init__(self, url, login=None, api="rpc", muc_host: str = 'conference'):
# init ejabberd api
- self.api = EjabberdCtl(url, login, api)
- self._cmd = self.api.cmd
+ super().__init__(url, login, api)
# variables
- self._verstring = self.api.verstring
self.muc_host = muc_host
def _client(self, resource):
@@ -55,51 +53,39 @@ class EjabberdMetrics:
return 4
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):
# nodes
- self._nodes = self.api.fetch_nodes()
+ self._nodes = self.fetch_nodes()
# vhosts
- self._vhosts = self.api.fetch_vhosts()
+ self._vhosts = self.fetch_vhosts()
# registered
if not hasattr(self, "_registered"):
self._registered = {}
- self._registered[None] = self.api.fetch_registered()
+ self._registered[None] = self.fetch_registered_count()
# muc
if not hasattr(self, "_muc"):
self._muc = {}
- self._muc[None] = self.fetch_muc()
+ self._muc[None] = self.fetch_muc_count(muc_host=self.muc_host)
# registered + muc
for vhost in self._vhosts:
- self._registered[vhost] = self.api.fetch_registered(vhost)
- self._muc[vhost] = self.fetch_muc(vhost)
+ self._registered[vhost] = self.fetch_registered_count(vhost)
+ self._muc[vhost] = self.fetch_muc_count(vhost,muc_host=self.muc_host)
# online user
- self._onlineuser = self.api.fetch_onlineuser()
+ self._onlineuser = self.fetch_onlineuser()
# s2s
- self._s2s_in = self.api.fetch_s2s_in()
- self._s2s_out = self.api.fetch_s2s_out()
+ self._s2s_in = self.fetch_s2s_in()
+ self._s2s_out = self.fetch_s2s_out()
def get_online_by(self, by="node", parse=None, vhost=None, node=None):
parser = parse or (lambda a: a)
if not hasattr(self, "_onlineuser"):
- self._onlineuser = self.api.fetch_onlineuser()
+ self._onlineuser = self.fetch_onlineuser()
data = {}
for conn in self._onlineuser:
@@ -137,7 +123,7 @@ class EjabberdMetrics:
def get_online_client_by(self, by="ip", parse=None, vhost=None, node=None):
parser = parse or self._ipversion
if not hasattr(self, "_onlineuser"):
- self._onlineuser = self.api.fetch_onlineuser()
+ self._onlineuser = self.fetch_onlineuser()
data = {}
for conn in self._onlineuser:
@@ -166,29 +152,29 @@ class EjabberdMetrics:
if not hasattr(self, "_registered"):
self._registered = {}
if vhost not in self._registered:
- self._registered[vhost] = self.api.fetch_registered(vhost)
+ self._registered[vhost] = self.fetch_registered_count(vhost)
return self._registered[vhost]
def get_muc(self, vhost=None):
if not hasattr(self, "_muc"):
self._muc = {}
if vhost not in self._muc:
- self._muc[vhost] = self.fetch_muc(vhost)
+ self._muc[vhost] = self.fetch_muc_count(vhost, muc_host=self.muc_host)
return self._muc[vhost]
def get_vhosts(self):
if not hasattr(self, "_vhosts"):
- self._vhosts = self.api.fetch_vhosts()
+ self._vhosts = self.fetch_vhosts()
return self._vhosts
def get_s2s_in(self):
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
def get_s2s_out(self):
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
def get_vhost_metrics(self, vhost):
@@ -204,9 +190,9 @@ class EjabberdMetrics:
return data
- def get_nodes(self):
+ def _get_nodes(self):
if not hasattr(self, "_nodes"):
- self._nodes = self.api.fetch_nodes()
+ self._nodes = self.fetch_nodes()
return self._nodes
def get_node_metrics(self, node):
@@ -238,7 +224,7 @@ class EjabberdMetrics:
data["vhosts"] = vhosts
nodes = {}
- for node in self.get_nodes():
+ for node in self._get_nodes():
nodes[node] = self.get_node_metrics(node)
data["online_client_by_ipversion"] = self.get_online_client_by_ipversion()