update plugins
* add new config support to the Prometheus plugin * pep8 improvements
This commit is contained in:
parent
ee4cb50ba6
commit
54256587b1
|
@ -79,7 +79,7 @@ if __name__ == '__main__':
|
||||||
# load config
|
# load config
|
||||||
config = Config()
|
config = Config()
|
||||||
|
|
||||||
# credentials and parameter
|
# credentials and parameters
|
||||||
url = config.get('url', default='http://localhost:5280/api')
|
url = config.get('url', default='http://localhost:5280/api')
|
||||||
login = config.get('login', default=None)
|
login = config.get('login', default=None)
|
||||||
api = config.get('api', default='rest')
|
api = config.get('api', default='rest')
|
||||||
|
|
|
@ -1,14 +1,16 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
from ejabberdrpc import EjabberdMetrics
|
|
||||||
|
|
||||||
import time
|
|
||||||
import threading
|
|
||||||
import socket
|
import socket
|
||||||
|
import threading
|
||||||
|
import time
|
||||||
from http.server import BaseHTTPRequestHandler, HTTPServer
|
from http.server import BaseHTTPRequestHandler, HTTPServer
|
||||||
from socketserver import ThreadingMixIn
|
from socketserver import ThreadingMixIn
|
||||||
|
|
||||||
|
from config import Config
|
||||||
|
from ejabberdrpc import EjabberdMetrics
|
||||||
|
|
||||||
|
|
||||||
class _ThreadingSimpleServer(ThreadingMixIn, HTTPServer):
|
class _ThreadingSimpleServer(ThreadingMixIn, HTTPServer):
|
||||||
"""Thread per request HTTP server."""
|
"""Thread per request HTTP server."""
|
||||||
# Make worker threads "fire and forget". Beginning with Python 3.7 this
|
# Make worker threads "fire and forget". Beginning with Python 3.7 this
|
||||||
|
@ -65,10 +67,8 @@ class Prometheus():
|
||||||
for k, v in data.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})
|
output += self._parse_metric("ejabberd_online_client_ipversion", v, {"vhost": host, "node": node, "ipversion": str(k), "client": client})
|
||||||
|
|
||||||
|
|
||||||
return output
|
return output
|
||||||
|
|
||||||
|
|
||||||
def listen(self, port, addr='::'):
|
def listen(self, port, addr='::'):
|
||||||
"""Starts an HTTP server for prometheus metrics as a daemon thread"""
|
"""Starts an HTTP server for prometheus metrics as a daemon thread"""
|
||||||
class myHandler(BaseHTTPRequestHandler):
|
class myHandler(BaseHTTPRequestHandler):
|
||||||
|
@ -79,28 +79,24 @@ class Prometheus():
|
||||||
result = self._get_metrics()
|
result = self._get_metrics()
|
||||||
r.wfile.write(result.encode('utf-8'))
|
r.wfile.write(result.encode('utf-8'))
|
||||||
|
|
||||||
|
|
||||||
httpd = _ThreadingSimpleServer((addr, port), myHandler)
|
httpd = _ThreadingSimpleServer((addr, port), myHandler)
|
||||||
t = threading.Thread(target=httpd.serve_forever)
|
t = threading.Thread(target=httpd.serve_forever)
|
||||||
t.daemon = True
|
t.daemon = True
|
||||||
t.start()
|
t.start()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
import os
|
|
||||||
import json
|
|
||||||
|
|
||||||
# load config
|
# load config
|
||||||
path = os.path.dirname(__file__)
|
config = Config()
|
||||||
with open("/".join([path, "config.json"]), "r", encoding="utf-8") as f:
|
|
||||||
config = json.load(f)
|
|
||||||
|
|
||||||
|
# credentials and parameters
|
||||||
|
url = config.get('url', default='http://[::1]:5280/api')
|
||||||
|
login = config.get('login', default=None)
|
||||||
|
api = config.get('api', default='rest')
|
||||||
|
|
||||||
url = config['url'] if "url" in config else "http://[::1]:5280/api"
|
# config prometheus
|
||||||
login = config['login'] if "login" in config else None
|
prom_port = config.get('prometheus_port', default=8080)
|
||||||
api = config['api'] if "api" in config else "rest"
|
prom_refresh = config.get('prometheus_refresh', default=10)
|
||||||
|
|
||||||
prom_port = config['prometheus_port'] if "prometheus_port" in config else 8080
|
|
||||||
prom_refresh = config['prometheus_refresh'] if "prometheus_refresh" in config else 10
|
|
||||||
|
|
||||||
metrics = EjabberdMetrics(url, login, api)
|
metrics = EjabberdMetrics(url, login, api)
|
||||||
prom = Prometheus(metrics)
|
prom = Prometheus(metrics)
|
||||||
|
|
Loading…
Reference in New Issue