client by (ipversion)
This commit is contained in:
parent
4ceca3f87e
commit
47683773ff
|
@ -3,6 +3,10 @@
|
|||
from xmlrpc import client
|
||||
import ipaddress
|
||||
|
||||
# rfc6052: IPv6 Addressing of IPv4/IPv6 Translators
|
||||
nat64 = ipaddress.ip_network("64:ff9b::/96")
|
||||
|
||||
|
||||
class EjabberdMetrics():
|
||||
"""
|
||||
class to fetch metrics per xmlrpc
|
||||
|
@ -20,6 +24,31 @@ class EjabberdMetrics():
|
|||
except:
|
||||
return {}
|
||||
|
||||
def _client(self, resource):
|
||||
clientmap = {
|
||||
"Conv6ations for Sum7": ["Conversations with IPv6"],
|
||||
"Conversations": [],
|
||||
"Pix-Art Messenger": [],
|
||||
"jitsi": [],
|
||||
"dino": [],
|
||||
"poezio": [],
|
||||
}
|
||||
for client,names in clientmap.items():
|
||||
for c in names:
|
||||
if c in resource:
|
||||
return client
|
||||
if client in resource:
|
||||
return client
|
||||
return "other"
|
||||
def _ipversion(self, ip):
|
||||
addr = ipaddress.ip_address(ip)
|
||||
if addr.version == 6:
|
||||
if addr.ipv4_mapped:
|
||||
return 4
|
||||
if addr in nat64:
|
||||
return 4
|
||||
return addr.version
|
||||
|
||||
def fetch_onlineuser(self):
|
||||
data = None
|
||||
tmp = self._cmd("connected_users_info", {})
|
||||
|
@ -141,36 +170,38 @@ class EjabberdMetrics():
|
|||
return self.get_online_by("connection", vhost=vhost, node=node)
|
||||
|
||||
def get_online_by_client(self, vhost=None, node=None):
|
||||
def client(r):
|
||||
clientmap = {
|
||||
"Conv6ations for Sum7": ["Conversations with IPv6"],
|
||||
"Conversations": [],
|
||||
"Pix-Art Messenger": [],
|
||||
"jitsi": [],
|
||||
"dino": [],
|
||||
"poezio": [],
|
||||
}
|
||||
for client,names in clientmap.items():
|
||||
for c in names:
|
||||
if c in r:
|
||||
return client
|
||||
if client in r:
|
||||
return client
|
||||
return "other"
|
||||
return self.get_online_by("resource", parse=client, vhost=vhost, node=node)
|
||||
return self.get_online_by("resource", parse=self._client, vhost=vhost, node=node)
|
||||
|
||||
def get_online_by_ipversion(self, vhost=None, node=None):
|
||||
# rfc6052: IPv6 Addressing of IPv4/IPv6 Translators
|
||||
nat64 = ipaddress.ip_network("64:ff9b::/96")
|
||||
def ipversion(ip):
|
||||
addr = ipaddress.ip_address(ip)
|
||||
if addr.version == 6:
|
||||
if addr.ipv4_mapped:
|
||||
return 4
|
||||
if addr in nat64:
|
||||
return 4
|
||||
return addr.version
|
||||
return self.get_online_by("ip", parse=ipversion, vhost=vhost, node=node)
|
||||
return self.get_online_by("ip", parse=self._ipversion, vhost=vhost, node=node)
|
||||
|
||||
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.fetch_onlineuser()
|
||||
data = {}
|
||||
|
||||
for conn in self._onlineuser:
|
||||
client = "other"
|
||||
if "resource" in conn:
|
||||
client = self._client(conn["resource"])
|
||||
if client not in data:
|
||||
data[client] = {}
|
||||
if vhost is not None and vhost not in conn["jid"]:
|
||||
continue
|
||||
if node is not None and node != conn["node"]:
|
||||
continue
|
||||
if by not in conn:
|
||||
continue
|
||||
value = parser(conn[by])
|
||||
if value not in data[client]:
|
||||
data[client][value] = 1
|
||||
else:
|
||||
data[client][value] += 1
|
||||
return data
|
||||
|
||||
def get_online_client_by_ipversion(self, vhost=None, node=None):
|
||||
return self.get_online_client_by("ip", parse=self._ipversion, vhost=vhost, node=node)
|
||||
|
||||
def get_registered(self, vhost=None):
|
||||
if not hasattr(self, "_registered"):
|
||||
|
@ -248,6 +279,8 @@ class EjabberdMetrics():
|
|||
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()
|
||||
data["nodes"] = nodes
|
||||
|
||||
data["s2s_in"] = self.get_s2s_in()
|
||||
|
|
|
@ -43,7 +43,6 @@ class Prometheus():
|
|||
|
||||
output += self._parse_metric("ejabberd_node_s2s_in", self._metrics.get_s2s_in())
|
||||
output += self._parse_metric("ejabberd_node_s2s_out", self._metrics.get_s2s_out())
|
||||
|
||||
for host in self._metrics.get_vhosts():
|
||||
output += self._parse_metric("ejabberd_registered_vhosts", self._metrics.get_registered(host), {"vhost": host})
|
||||
muc = self._metrics.get_muc(host)
|
||||
|
@ -62,6 +61,10 @@ class Prometheus():
|
|||
output += self._parse_metric("ejabberd_online_client", v, {"vhost": host, "node": node, "client": k})
|
||||
for k, v in self._metrics.get_online_by_ipversion(node=node, vhost=host).items():
|
||||
output += self._parse_metric("ejabberd_online_ipversion", v, {"vhost": host, "node": node, "ipversion": str(k)})
|
||||
for client, data in self._metrics.get_online_client_by_ipversion(node=node,vhost=host).items():
|
||||
for k, v in data.items():
|
||||
output += self._parse_metric("ejabberd_online_client_ipversion", v, {"vhost": host, "node": node, "ipversion": str(k), "client": client})
|
||||
|
||||
|
||||
return output
|
||||
|
||||
|
|
Loading…
Reference in New Issue