当前位置: 首页>>代码示例>>Python>>正文


Python prometheus_client.CONTENT_TYPE_LATEST属性代码示例

本文整理汇总了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) 
开发者ID:perdy,项目名称:starlette-prometheus,代码行数:10,代码来源:view.py

示例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) 
开发者ID:jonashaag,项目名称:prometheus-multiprocessing-example,代码行数:7,代码来源:yourapp.py

示例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
    ) 
开发者ID:korfuri,项目名称:django-prometheus,代码行数:16,代码来源:exports.py

示例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 
开发者ID:rycus86,项目名称:prometheus_flask_exporter,代码行数:36,代码来源:__init__.py

示例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)) 
开发者ID:jupyterhub,项目名称:binderhub,代码行数:5,代码来源:metrics.py

示例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() 
开发者ID:zentralopensource,项目名称:zentral,代码行数:12,代码来源:prometheus.py

示例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() 
开发者ID:CanonicalLtd,项目名称:prometheus-openstack-exporter,代码行数:35,代码来源:prometheus_openstack_exporter.py

示例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,
        ) 
开发者ID:line,项目名称:promgen,代码行数:7,代码来源:views.py

示例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 
开发者ID:faucetsdn,项目名称:faucet,代码行数:17,代码来源:prom_client.py

示例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)) 
开发者ID:blue-yonder,项目名称:postgraas_server,代码行数:9,代码来源:prometheus_app.py

示例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() 
开发者ID:att-comdev,项目名称:prometheus-openstack-exporter,代码行数:32,代码来源:main.py

示例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)) 
开发者ID:blue-yonder,项目名称:azure-cost-mon,代码行数:11,代码来源:views.py

示例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) 
开发者ID:MyBook,项目名称:zabbix-exporter,代码行数:15,代码来源:core.py

示例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) 
开发者ID:pletessier,项目名称:taranis,代码行数:4,代码来源:metrics.py


注:本文中的prometheus_client.CONTENT_TYPE_LATEST属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。