本文整理汇总了Python中prometheus_client.multiprocess.MultiProcessCollector方法的典型用法代码示例。如果您正苦于以下问题:Python multiprocess.MultiProcessCollector方法的具体用法?Python multiprocess.MultiProcessCollector怎么用?Python multiprocess.MultiProcessCollector使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类prometheus_client.multiprocess
的用法示例。
在下文中一共展示了multiprocess.MultiProcessCollector方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: root
# 需要导入模块: from prometheus_client import multiprocess [as 别名]
# 或者: from prometheus_client.multiprocess import MultiProcessCollector [as 别名]
def root():
# check access
ip_whitelist = ip_network(current_app.config.get('PROMETHEUS_WHITELIST'))
if ip_address(request.remote_addr) not in ip_whitelist:
_jwt_required(current_app.config['JWT_DEFAULT_REALM'])
MU = MetricUpdater()
registry = CollectorRegistry()
multiprocess.MultiProcessCollector(registry)
data = generate_latest(registry)
response = make_response(data)
response.headers['Content-Type'] = CONTENT_TYPE_LATEST
response.headers['Content-Length'] = str(len(data))
logger.info('Kqueen metrics updating')
MU.update_metrics()
return response
示例2: generate_latest
# 需要导入模块: from prometheus_client import multiprocess [as 别名]
# 或者: from prometheus_client.multiprocess import MultiProcessCollector [as 别名]
def generate_latest(self):
"""Generate a bytestring with metric values."""
if self.registry is None:
return
registry = self.registry
if registry is prom_cli.REGISTRY:
# when using the global registry, setup up multiprocess
# support. In this case, a separate registry needs to be used
# for generating the samples.
registry = prom_cli.CollectorRegistry()
from prometheus_client import multiprocess
multiprocess.MultiProcessCollector(registry)
for handler in self._update_handlers:
handler(self)
return prom_cli.generate_latest(registry)
示例3: metrics
# 需要导入模块: from prometheus_client import multiprocess [as 别名]
# 或者: from prometheus_client.multiprocess import MultiProcessCollector [as 别名]
def metrics():
registry = CollectorRegistry()
multiprocess.MultiProcessCollector(registry)
data = generate_latest(registry)
return Response(data, mimetype=CONTENT_TYPE_LATEST)
示例4: ExportToDjangoView
# 需要导入模块: from prometheus_client import multiprocess [as 别名]
# 或者: from prometheus_client.multiprocess import MultiProcessCollector [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
)
示例5: register_endpoint
# 需要导入模块: from prometheus_client import multiprocess [as 别名]
# 或者: from prometheus_client.multiprocess import MultiProcessCollector [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
示例6: app
# 需要导入模块: from prometheus_client import multiprocess [as 别名]
# 或者: from prometheus_client.multiprocess import MultiProcessCollector [as 别名]
def app(environ, start_fn):
REQUESTS.inc()
if environ['PATH_INFO'] == '/metrics':
registry = CollectorRegistry()
multiprocess.MultiProcessCollector(registry)
metrics_app = make_wsgi_app(registry)
return metrics_app(environ, start_fn)
start_fn('200 OK', [])
return [b'Hello World']