mirror of
https://github.com/internetarchive/brozzler.git
synced 2025-02-23 16:19:49 -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 typing import Optional
|
||||||
|
|
||||||
"""
|
try:
|
||||||
from http_sd_registry.client import (
|
from http_sd_registry.client import (
|
||||||
Client,
|
Client,
|
||||||
Env,
|
Env,
|
||||||
Registration,
|
Registration,
|
||||||
Scheme,
|
Scheme,
|
||||||
format_self_target,
|
format_self_target,
|
||||||
)
|
)
|
||||||
from http_sd_registry.config import ClientConfig
|
from http_sd_registry.config import ClientConfig
|
||||||
"""
|
except ImportError:
|
||||||
|
http_sd_registry = None
|
||||||
|
|
||||||
from prometheus_client import Counter, Gauge, Histogram, start_http_server
|
from prometheus_client import Counter, Gauge, Histogram, start_http_server
|
||||||
|
|
||||||
# fmt: off
|
# 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"])
|
brozzler_ydl_download_successes= Counter("brozzler_ydl_download_successes", "count of downloads completed by brozzler yt-dlp", labelnames=["host"])
|
||||||
# fmt: on
|
# 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(
|
if registry_url is None:
|
||||||
registry_url: Optional[str] = None, metrics_port: int = 8888, env: Env = Env.qa
|
return
|
||||||
):
|
|
||||||
# Start metrics endpoint for scraping
|
|
||||||
start_http_server(metrics_port)
|
|
||||||
|
|
||||||
if registry_url is None:
|
config = ClientConfig(server_url_base=registry_url)
|
||||||
return
|
client = Client(config)
|
||||||
|
target = format_self_target(scrape_port=metrics_port)
|
||||||
config = ClientConfig(server_url_base=registry_url)
|
registration = Registration(
|
||||||
client = Client(config)
|
target=target,
|
||||||
target = format_self_target(scrape_port=metrics_port)
|
env=env,
|
||||||
registration = Registration(
|
scheme=Scheme.http,
|
||||||
target=target,
|
)
|
||||||
env=env,
|
client.keep_registered_threaded(registration)
|
||||||
scheme=Scheme.http,
|
|
||||||
)
|
|
||||||
client.keep_registered_threaded(registration)
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user