aboutsummaryrefslogtreecommitdiffstats
path: root/prometheus.py
diff options
context:
space:
mode:
authornico <nico@magicbroccoli.de>2020-06-26 00:55:49 +0200
committernico <nico@magicbroccoli.de>2020-06-26 00:55:49 +0200
commit7296375924350e1e7794cae3f0bf3469a0c01933 (patch)
tree567b4f568c9400bfb5795c2f708cf6fb8b74d301 /prometheus.py
parent86562276d40988033d4cbadda413a8639c97724c (diff)
pep8 and import ajustments
* optimzed import statements * pep8 alignment changes, mostly missing whitespaces, newlines or redundant brackets
Diffstat (limited to 'prometheus.py')
-rwxr-xr-xprometheus.py38
1 files changed, 18 insertions, 20 deletions
diff --git a/prometheus.py b/prometheus.py
index d2ffcf5..da0d24c 100755
--- a/prometheus.py
+++ b/prometheus.py
@@ -1,19 +1,16 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
-import subprocess
import logging
-from time import time
-from collections import defaultdict
from http.server import BaseHTTPRequestHandler, HTTPServer
from socket import AF_INET6
+from time import time
from urllib.parse import parse_qs, urlparse
+
from prometheus_client import (
CollectorRegistry, Gauge, generate_latest, CONTENT_TYPE_LATEST
)
-
-
from config import Config
from metrics import EjabberdMetrics
@@ -42,7 +39,8 @@ class DynamicMetricsHandler(BaseHTTPRequestHandler):
{"generator": registry_generator})
return DynMetricsHandler
-class Prometheus():
+
+class Prometheus:
def __init__(self, metrics):
self.ttl = 10
self._last_update = 0
@@ -64,35 +62,35 @@ class Prometheus():
registered_vhosts = Gauge('ejabberd_registered_vhosts', 'count of user per vhost', labelnames_vhost, registry=registry)
muc = Gauge('ejabberd_muc', 'count of muc\'s per vhost', labelnames_vhost, registry=registry)
- online_vhost_node = Gauge('ejabberd_online_vhost_node', 'count of client connections', ["vhost","node"], registry=registry)
+ online_vhost_node = Gauge('ejabberd_online_vhost_node', 'count of client connections', ["vhost", "node"], registry=registry)
- online_status = Gauge('ejabberd_online_status', 'count of client connections', ["vhost","node","status"], registry=registry)
- online_connection = Gauge('ejabberd_online_connection', 'count of client connections', ["vhost","node","connection"], registry=registry)
- online_client = Gauge('ejabberd_online_client', 'count of client software', ["vhost","node","client"], registry=registry)
- online_ipversion = Gauge('ejabberd_online_ipversion', 'count of client software', ["vhost","node","ipversion"], registry=registry)
- online_client_ipversion = Gauge('ejabberd_online_client_ipversion', 'count of client software', ["vhost","node","client","ipversion"], registry=registry)
+ online_status = Gauge('ejabberd_online_status', 'count of client connections', ["vhost", "node", "status"], registry=registry)
+ online_connection = Gauge('ejabberd_online_connection', 'count of client connections', ["vhost", "node", "connection"], registry=registry)
+ online_client = Gauge('ejabberd_online_client', 'count of client software', ["vhost", "node", "client"], registry=registry)
+ online_ipversion = Gauge('ejabberd_online_ipversion', 'count of client software', ["vhost", "node", "ipversion"], registry=registry)
+ online_client_ipversion = Gauge('ejabberd_online_client_ipversion', 'count of client software', ["vhost", "node", "client", "ipversion"], registry=registry)
for host in self._metrics.get_vhosts():
- labels_vhost = (host)
+ labels_vhost = host
registered_vhosts.labels(labels_vhost).set(self._metrics.get_registered(host))
muc.labels(labels_vhost).set(self._metrics.get_muc(host))
for k, v in self._metrics.get_online_by_node(vhost=host).items():
- online_vhost_node.labels(host,k).set(v)
+ online_vhost_node.labels(host, k).set(v)
for node in self._metrics.get_nodes():
for k, v in self._metrics.get_online_by_status(node=node, vhost=host).items():
- online_status.labels(host,node,k).set(v)
+ online_status.labels(host, node, k).set(v)
for k, v in self._metrics.get_online_by_connection(node=node, vhost=host).items():
- online_connection.labels(host,node,k).set(v)
+ online_connection.labels(host, node, k).set(v)
for k, v in self._metrics.get_online_by_client(node=node, vhost=host).items():
- online_client.labels(host,node,k).set(v)
+ online_client.labels(host, node, k).set(v)
for k, v in self._metrics.get_online_by_ipversion(node=node, vhost=host).items():
- online_ipversion.labels(host,node,k).set(v)
- for client, data in self._metrics.get_online_client_by_ipversion(node=node,vhost=host).items():
+ online_ipversion.labels(host, node, k).set(v)
+ for client, data in self._metrics.get_online_client_by_ipversion(node=node, vhost=host).items():
for k, v in data.items():
- online_client_ipversion.labels(host,node,client,str(k)).set(v)
+ online_client_ipversion.labels(host, node, client, str(k)).set(v)
return registry