File: http.py

package info (click to toggle)
prometheus-trafficserver-exporter 0.3.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 348 kB
  • sloc: python: 457; makefile: 7
file content (24 lines) | stat: -rw-r--r-- 560 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import threading

from prometheus_client.exposition import MetricsHandler

try:
    from http.server import HTTPServer
except ImportError:
    # Py2
    from BaseHTTPServer import HTTPServer



def start_http_server(port, addr=""):
    """Starts a HTTP server for prometheus metrics as a daemon thread."""

    class PrometheusMetricsServer(threading.Thread):
        def run(self):
            httpd = HTTPServer((addr, port), MetricsHandler)
            httpd.serve_forever()

    t = PrometheusMetricsServer()
    t.daemon = True
    t.start()
    return t