本文整理汇总了Python中prometheus_client.start_http_server方法的典型用法代码示例。如果您正苦于以下问题:Python prometheus_client.start_http_server方法的具体用法?Python prometheus_client.start_http_server怎么用?Python prometheus_client.start_http_server使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类prometheus_client
的用法示例。
在下文中一共展示了prometheus_client.start_http_server方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: SetupPrometheusEndpointOnPort
# 需要导入模块: import prometheus_client [as 别名]
# 或者: from prometheus_client import start_http_server [as 别名]
def SetupPrometheusEndpointOnPort(port, addr=""):
"""Exports Prometheus metrics on an HTTPServer running in its own thread.
The server runs on the given port and is by default listenning on
all interfaces. This HTTPServer is fully independent of Django and
its stack. This offers the advantage that even if Django becomes
unable to respond, the HTTPServer will continue to function and
export metrics. However, this also means that the features
offered by Django (like middlewares or WSGI) can't be used.
Now here's the really weird part. When Django runs with the
auto-reloader enabled (which is the default, you can disable it
with `manage.py runserver --noreload`), it forks and executes
manage.py twice. That's wasteful but usually OK. It starts being a
problem when you try to open a port, like we do. We can detect
that we're running under an autoreloader through the presence of
the RUN_MAIN environment variable, so we abort if we're trying to
export under an autoreloader and trying to open a port.
"""
assert os.environ.get("RUN_MAIN") != "true", (
"The thread-based exporter can't be safely used when django's "
"autoreloader is active. Use the URL exporter, or start django "
"with --noreload. See documentation/exports.md."
)
prometheus_client.start_http_server(port, addr=addr)
示例2: __init__
# 需要导入模块: import prometheus_client [as 别名]
# 或者: from prometheus_client import start_http_server [as 别名]
def __init__(self, data_manager, config):
self.config = config
self.data_manager = data_manager
self.http_server = prometheus_client.start_http_server(
self.config.prometheus_port,
addr=self.config.prometheus_addr
)
self.updated_containers_counter = prometheus_client.Counter(
'containers_updated',
'Count of containers updated',
['socket', 'container']
)
self.monitored_containers_gauge = prometheus_client.Gauge(
'containers_being_monitored',
'Gauge of containers being monitored',
['socket']
)
self.updated_all_containers_gauge = prometheus_client.Gauge(
'all_containers_updated',
'Count of total updated',
['socket']
)
self.logger = getLogger()
示例3: main
# 需要导入模块: import prometheus_client [as 别名]
# 或者: from prometheus_client import start_http_server [as 别名]
def main():
"""Main function."""
init()
threading.Thread(
name = 'watch_governors',
target = watch_governors
).start()
threading.Thread(
name = 'watch_runners',
target = watch_runners
).start()
threading.Thread(
name = 'watch_runner_pods',
target = watch_runner_pods
).start()
threading.Thread(
name = 'watch_peering',
target = watch_peering
).start()
threading.Thread(
name = 'main',
target = main_loop
).start()
prometheus_client.start_http_server(8000)
http_server = gevent.pywsgi.WSGIServer(('', 5000), api)
http_server.serve_forever()
示例4: _prepare_website
# 需要导入模块: import prometheus_client [as 别名]
# 或者: from prometheus_client import start_http_server [as 别名]
def _prepare_website(self, context: Context) -> None:
if self.config["appservice.public.enabled"]:
public_website = PublicBridgeWebsite(self.loop)
self.az.app.add_subapp(self.config["appservice.public.prefix"], public_website.app)
context.public_website = public_website
if self.config["appservice.provisioning.enabled"]:
provisioning_api = ProvisioningAPI(context)
self.az.app.add_subapp(self.config["appservice.provisioning.prefix"],
provisioning_api.app)
context.provisioning_api = provisioning_api
if self.config["metrics.enabled"]:
if prometheus:
prometheus.start_http_server(self.config["metrics.listen_port"])
else:
self.log.warning("Metrics are enabled in the config, "
"but prometheus_client is not installed.")
示例5: main
# 需要导入模块: import prometheus_client [as 别名]
# 或者: from prometheus_client import start_http_server [as 别名]
def main(brokers: str, es_clusters: str, topics: List[str], group_id: str, prometheus_port: int):
clusters = make_es_clusters(es_clusters)
indices_map_memo = cast(Callable[[], Mapping[str, Elasticsearch]], ttl_memoize(indices_map, clusters=clusters))
def client_for_index(name: str) -> Elasticsearch:
return indices_map_memo()[name]
prometheus_client.start_http_server(prometheus_port)
bulk_daemon.run(brokers, client_for_index, topics, group_id)
示例6: run
# 需要导入模块: import prometheus_client [as 别名]
# 或者: from prometheus_client import start_http_server [as 别名]
def run(self) -> None:
prometheus_client.start_http_server(self.prometheus_port)
try:
while True:
# If we are seeing production traffic do nothing and sit around.
self.load_monitor.wait_until_below_threshold()
# No production traffic, go ahead and subscribe to kafka
self.consume(self.iter_records())
finally:
self.producer.close()
self.ack_all_producer.close()
示例7: start
# 需要导入模块: import prometheus_client [as 别名]
# 或者: from prometheus_client import start_http_server [as 别名]
def start(bot):
port = 6000 + bot.cluster
prom.start_http_server(port)
bot.loop.create_task(update_stats(bot))
bot.loop.create_task(update_latency(bot))
示例8: _start_httpd
# 需要导入模块: import prometheus_client [as 别名]
# 或者: from prometheus_client import start_http_server [as 别名]
def _start_httpd(self): # pragma: no cover
"""
Starts the exposing HTTPD using the addr provided in a separate
thread.
"""
host, port = self._listen_address.split(":")
logging.info("Starting HTTPD on {}:{}".format(host, port))
prometheus_client.start_http_server(int(port), host)
示例9: start_httpd
# 需要导入模块: import prometheus_client [as 别名]
# 或者: from prometheus_client import start_http_server [as 别名]
def start_httpd(addr): # pragma: no cover
"""
Starts the exposing HTTPD using the addr provided in a separate
thread.
"""
host, port = addr.split(':')
logging.info('Starting HTTPD on {}:{}'.format(host, port))
prometheus_client.start_http_server(int(port), host)