Initial commit
All checks were successful
Run linters on applied template / Python 3.13 lint and build (push) Successful in 1m0s
All checks were successful
Run linters on applied template / Python 3.13 lint and build (push) Successful in 1m0s
This is a FastAPI backend microservice template used with `copier` utility. Features of applied template are: - Configuration file processing logic - Metrics and tracing (both optional) configuration available - Debug endpoints - Database migration commands, prepared Alembic environment - Database usage example in ping_db endpoint - gitea sanity check pipeline
This commit is contained in:
22
{{project_slug}}/observability/metrics_server.py
Normal file
22
{{project_slug}}/observability/metrics_server.py
Normal file
@@ -0,0 +1,22 @@
|
||||
"""Prometheus server configuration class is defined here."""
|
||||
|
||||
from threading import Thread
|
||||
from wsgiref.simple_server import WSGIServer
|
||||
|
||||
from prometheus_client import start_http_server
|
||||
|
||||
|
||||
class PrometheusServer: # pylint: disable=too-few-public-methods
|
||||
|
||||
def __init__(self, port: int = 9464, host: str = "0.0.0.0"):
|
||||
self._host = host
|
||||
self._port = port
|
||||
self._server: WSGIServer
|
||||
self._thread: Thread
|
||||
|
||||
self._server, self._thread = start_http_server(self._port)
|
||||
|
||||
def shutdown(self):
|
||||
if self._server is not None:
|
||||
self._server.shutdown()
|
||||
self._server = None
|
||||
Reference in New Issue
Block a user