mirror of
https://github.com/internetarchive/brozzler.git
synced 2025-02-23 08:09:48 -05:00
make http_sd_registry optional
This commit is contained in:
parent
1d84e72ce7
commit
c82858a9f6
@ -1,15 +1,17 @@
|
||||
from typing import Optional
|
||||
|
||||
"""
|
||||
from http_sd_registry.client import (
|
||||
Client,
|
||||
Env,
|
||||
Registration,
|
||||
Scheme,
|
||||
format_self_target,
|
||||
)
|
||||
from http_sd_registry.config import ClientConfig
|
||||
"""
|
||||
try:
|
||||
from http_sd_registry.client import (
|
||||
Client,
|
||||
Env,
|
||||
Registration,
|
||||
Scheme,
|
||||
format_self_target,
|
||||
)
|
||||
from http_sd_registry.config import ClientConfig
|
||||
except ImportError:
|
||||
http_sd_registry = None
|
||||
|
||||
from prometheus_client import Counter, Gauge, Histogram, start_http_server
|
||||
|
||||
# fmt: off
|
||||
@ -27,22 +29,22 @@ brozzler_ydl_download_attempts= Counter("brozzler_ydl_download_attempts", "count
|
||||
brozzler_ydl_download_successes= Counter("brozzler_ydl_download_successes", "count of downloads completed by brozzler yt-dlp", labelnames=["host"])
|
||||
# fmt: on
|
||||
|
||||
if http_sd_registry:
|
||||
def register_prom_metrics(
|
||||
registry_url: Optional[str] = None, metrics_port: int = 8888, env: Env = Env.qa
|
||||
):
|
||||
# Start metrics endpoint for scraping
|
||||
start_http_server(metrics_port)
|
||||
|
||||
def register_prom_metrics(
|
||||
registry_url: Optional[str] = None, metrics_port: int = 8888, env: Env = Env.qa
|
||||
):
|
||||
# Start metrics endpoint for scraping
|
||||
start_http_server(metrics_port)
|
||||
if registry_url is None:
|
||||
return
|
||||
|
||||
if registry_url is None:
|
||||
return
|
||||
|
||||
config = ClientConfig(server_url_base=registry_url)
|
||||
client = Client(config)
|
||||
target = format_self_target(scrape_port=metrics_port)
|
||||
registration = Registration(
|
||||
target=target,
|
||||
env=env,
|
||||
scheme=Scheme.http,
|
||||
)
|
||||
client.keep_registered_threaded(registration)
|
||||
config = ClientConfig(server_url_base=registry_url)
|
||||
client = Client(config)
|
||||
target = format_self_target(scrape_port=metrics_port)
|
||||
registration = Registration(
|
||||
target=target,
|
||||
env=env,
|
||||
scheme=Scheme.http,
|
||||
)
|
||||
client.keep_registered_threaded(registration)
|
||||
|
Loading…
x
Reference in New Issue
Block a user