當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。