本文整理汇总了Python中prometheus_client.CONTENT_TYPE_LATEST属性的典型用法代码示例。如果您正苦于以下问题:Python prometheus_client.CONTENT_TYPE_LATEST属性的具体用法?Python prometheus_client.CONTENT_TYPE_LATEST怎么用?Python prometheus_client.CONTENT_TYPE_LATEST使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类prometheus_client
的用法示例。
在下文中一共展示了prometheus_client.CONTENT_TYPE_LATEST属性的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: metrics
# 需要导入模块: import prometheus_client [as 别名]
# 或者: from prometheus_client import CONTENT_TYPE_LATEST [as 别名]
def metrics(request: Request) -> Response:
if "prometheus_multiproc_dir" in os.environ:
registry = CollectorRegistry()
MultiProcessCollector(registry)
else:
registry = REGISTRY
return Response(generate_latest(registry), media_type=CONTENT_TYPE_LATEST)
示例2: metrics
# 需要导入模块: import prometheus_client [as 别名]
# 或者: from prometheus_client import CONTENT_TYPE_LATEST [as 别名]
def metrics():
registry = CollectorRegistry()
multiprocess.MultiProcessCollector(registry)
data = generate_latest(registry)
return Response(data, mimetype=CONTENT_TYPE_LATEST)
示例3: ExportToDjangoView
# 需要导入模块: import prometheus_client [as 别名]
# 或者: from prometheus_client import CONTENT_TYPE_LATEST [as 别名]
def ExportToDjangoView(request):
"""Exports /metrics as a Django view.
You can use django_prometheus.urls to map /metrics to this view.
"""
if "prometheus_multiproc_dir" in os.environ:
registry = prometheus_client.CollectorRegistry()
multiprocess.MultiProcessCollector(registry)
else:
registry = prometheus_client.REGISTRY
metrics_page = prometheus_client.generate_latest(registry)
return HttpResponse(
metrics_page, content_type=prometheus_client.CONTENT_TYPE_LATEST
)
示例4: register_endpoint
# 需要导入模块: import prometheus_client [as 别名]
# 或者: from prometheus_client import CONTENT_TYPE_LATEST [as 别名]
def register_endpoint(self, path, app=None):
"""
Register the metrics endpoint on the Flask application.
:param path: the path of the endpoint
:param app: the Flask application to register the endpoint on
(by default it is the application registered with this class)
"""
if is_running_from_reloader() and not os.environ.get('DEBUG_METRICS'):
return
if app is None:
app = self.app or current_app
@app.route(path)
@self.do_not_track()
def prometheus_metrics():
# import these here so they don't clash with our own multiprocess module
from prometheus_client import multiprocess, CollectorRegistry
if 'prometheus_multiproc_dir' in os.environ:
registry = CollectorRegistry()
else:
registry = self.registry
if 'name[]' in request.args:
registry = registry.restricted_registry(request.args.getlist('name[]'))
if 'prometheus_multiproc_dir' in os.environ:
multiprocess.MultiProcessCollector(registry)
headers = {'Content-Type': CONTENT_TYPE_LATEST}
return generate_latest(registry), 200, headers
示例5: get
# 需要导入模块: import prometheus_client [as 别名]
# 或者: from prometheus_client import CONTENT_TYPE_LATEST [as 别名]
def get(self):
self.set_header("Content-Type", CONTENT_TYPE_LATEST)
self.write(generate_latest(REGISTRY))
示例6: get
# 需要导入模块: import prometheus_client [as 别名]
# 或者: from prometheus_client import CONTENT_TYPE_LATEST [as 别名]
def get(self, request, *args, **kwargs):
bearer_token = settings['apps']['zentral.contrib.inventory'].get('prometheus_bearer_token')
if bearer_token and request.META.get('HTTP_AUTHORIZATION') == "Bearer {}".format(bearer_token):
content = ""
registry = self.get_registry()
if registry is not None:
content = generate_latest(registry)
return HttpResponse(content, content_type=CONTENT_TYPE_LATEST)
else:
return HttpResponseForbidden()
示例7: do_GET
# 需要导入模块: import prometheus_client [as 别名]
# 或者: from prometheus_client import CONTENT_TYPE_LATEST [as 别名]
def do_GET(self):
url = urlparse.urlparse(self.path)
if url.path == '/metrics':
try:
collectors = [COLLECTORS[collector]() for collector in get_collectors(config.get('enabled_collectors'))]
log.debug("Collecting stats..")
output = ''
for collector in collectors:
output += collector.get_stats()
if data_gatherer:
output += data_gatherer.get_stats()
self.send_response(200)
self.send_header('Content-Type', CONTENT_TYPE_LATEST)
self.end_headers()
self.wfile.write(output)
except Exception:
self.send_response(500)
self.end_headers()
self.wfile.write(traceback.format_exc())
elif url.path == '/':
self.send_response(200)
self.end_headers()
self.wfile.write("""<html>
<head><title>OpenStack Exporter</title></head>
<body>
<h1>OpenStack Exporter</h1>
<p>Visit <code>/metrics</code> to use.</p>
</body>
</html>""")
else:
self.send_response(404)
self.end_headers()
示例8: get
# 需要导入模块: import prometheus_client [as 别名]
# 或者: from prometheus_client import CONTENT_TYPE_LATEST [as 别名]
def get(self, request, *args, **kwargs):
return HttpResponse(
prometheus_client.generate_latest(self.registry),
content_type=prometheus_client.CONTENT_TYPE_LATEST,
)
示例9: make_wsgi_app
# 需要导入模块: import prometheus_client [as 别名]
# 或者: from prometheus_client import CONTENT_TYPE_LATEST [as 别名]
def make_wsgi_app(registry):
"""Create a WSGI app which serves the metrics from a registry."""
def prometheus_app(environ, start_response):
query_str = environ.get('QUERY_STRING', '')
params = parse_qs(query_str)
reg = registry
if 'name[]' in params:
reg = reg.restricted_registry(params['name[]'])
output = generate_latest(reg)
status = str('200 OK')
headers = [(str('Content-type'), CONTENT_TYPE_LATEST)]
start_response(status, headers)
return [output]
return prometheus_app
示例10: metrics
# 需要导入模块: import prometheus_client [as 别名]
# 或者: from prometheus_client import CONTENT_TYPE_LATEST [as 别名]
def metrics():
try:
content = generate_latest(REGISTRY)
return content, 200, {'Content-Type': CONTENT_TYPE_LATEST}
except Exception as error:
logging.exception("Any exception occured during scraping")
abort(Response("Scrape failed: {}".format(error), status=502))
示例11: do_GET
# 需要导入模块: import prometheus_client [as 别名]
# 或者: from prometheus_client import CONTENT_TYPE_LATEST [as 别名]
def do_GET(self):
url = urlparse.urlparse(self.path)
if url.path == '/metrics':
output = ''
for collector in collectors:
try:
stats = collector.get_stats()
if stats is not None:
output = output + stats
except BaseException:
logger.warning(
"Could not get stats for collector {}".format(
collector.get_cache_key()))
self.send_response(200)
self.send_header('Content-Type', CONTENT_TYPE_LATEST)
self.end_headers()
self.wfile.write(output)
elif url.path == '/':
self.send_response(200)
self.end_headers()
self.wfile.write("""<html>
<head><title>OpenStack Exporter</title></head>
<body>
<h1>OpenStack Exporter</h1>
<p>Visit <code>/metrics</code> to use.</p>
</body>
</html>""")
else:
self.send_response(404)
self.end_headers()
示例12: metrics
# 需要导入模块: import prometheus_client [as 别名]
# 或者: from prometheus_client import CONTENT_TYPE_LATEST [as 别名]
def metrics():
registry = CollectorRegistry()
_register_collectors(registry)
try:
content = generate_latest(registry)
return content, 200, {'Content-Type': CONTENT_TYPE_LATEST}
except Exception as e:
abort(Response("Scrape failed: {}".format(e), status=502))
示例13: do_GET
# 需要导入模块: import prometheus_client [as 别名]
# 或者: from prometheus_client import CONTENT_TYPE_LATEST [as 别名]
def do_GET(self):
try:
scrapes_total.inc()
response = generate_latest(REGISTRY) + generate_latest(exporter_registry)
status = 200
except Exception:
logger.exception('Fetch failed')
response = ''
status = 500
self.send_response(status)
self.send_header('Content-Type', CONTENT_TYPE_LATEST)
self.end_headers()
self.wfile.write(response)
示例14: get
# 需要导入模块: import prometheus_client [as 别名]
# 或者: from prometheus_client import CONTENT_TYPE_LATEST [as 别名]
def get(self):
return Response(prometheus_client.generate_latest(), mimetype=prometheus_client.CONTENT_TYPE_LATEST)