當前位置: 首頁>>代碼示例>>Python>>正文


Python prometheus_client.REGISTRY屬性代碼示例

本文整理匯總了Python中prometheus_client.REGISTRY屬性的典型用法代碼示例。如果您正苦於以下問題:Python prometheus_client.REGISTRY屬性的具體用法?Python prometheus_client.REGISTRY怎麽用?Python prometheus_client.REGISTRY使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在prometheus_client的用法示例。


在下文中一共展示了prometheus_client.REGISTRY屬性的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: assertMetricEquals

# 需要導入模塊: import prometheus_client [as 別名]
# 或者: from prometheus_client import REGISTRY [as 別名]
def assertMetricEquals(
        self, expected_value, metric_name, registry=REGISTRY, **labels
    ):
        """Asserts that metric_name{**labels} == expected_value."""
        value = self.getMetric(metric_name, registry=registry, **labels)
        self.assertEqual(
            expected_value,
            value,
            METRIC_EQUALS_ERR_EXPLANATION
            % (
                metric_name,
                self.formatLabels(labels),
                value,
                expected_value,
                metric_name,
                self.formatVector(self.getMetricVector(metric_name)),
            ),
        ) 
開發者ID:korfuri,項目名稱:django-prometheus,代碼行數:20,代碼來源:testutils.py

示例2: getMetric

# 需要導入模塊: import prometheus_client [as 別名]
# 或者: from prometheus_client import REGISTRY [as 別名]
def getMetric(self, metric_name, registry=REGISTRY, **labels):
        """Gets a single metric."""
        return self.getMetricFromFrozenRegistry(
            metric_name, registry.collect(), **labels
        ) 
開發者ID:korfuri,項目名稱:django-prometheus,代碼行數:7,代碼來源:testutils.py

示例3: saveRegistry

# 需要導入模塊: import prometheus_client [as 別名]
# 或者: from prometheus_client import REGISTRY [as 別名]
def saveRegistry(self, registry=REGISTRY):
        """Freezes a registry. This lets a user test changes to a metric
        instead of testing the absolute value. A typical use case looks like:

          registry = self.saveRegistry()
          doStuff()
          self.assertMetricDiff(registry, 1, 'stuff_done_total')
        """
        return copy.deepcopy(list(registry.collect())) 
開發者ID:korfuri,項目名稱:django-prometheus,代碼行數:11,代碼來源:testutils.py

示例4: getMetricVector

# 需要導入模塊: import prometheus_client [as 別名]
# 或者: from prometheus_client import REGISTRY [as 別名]
def getMetricVector(self, metric_name, registry=REGISTRY):
        """Returns the values for all labels of a given metric.

        The result is returned as a list of (labels, value) tuples,
        where `labels` is a dict.

        This is quite a hack since it relies on the internal
        representation of the prometheus_client, and it should
        probably be provided as a function there instead.
        """
        return self.getMetricVectorFromFrozenRegistry(metric_name, registry.collect()) 
開發者ID:korfuri,項目名稱:django-prometheus,代碼行數:13,代碼來源:testutils.py

示例5: assertMetricDiff

# 需要導入模塊: import prometheus_client [as 別名]
# 或者: from prometheus_client import REGISTRY [as 別名]
def assertMetricDiff(
        self, frozen_registry, expected_diff, metric_name, registry=REGISTRY, **labels
    ):
        """Asserts that metric_name{**labels} changed by expected_diff between
        the frozen registry and now. A frozen registry can be obtained
        by calling saveRegistry, typically at the beginning of a test
        case.
        """
        saved_value = self.getMetricFromFrozenRegistry(
            metric_name, frozen_registry, **labels
        )
        current_value = self.getMetric(metric_name, registry=registry, **labels)
        self.assertFalse(
            current_value is None,
            METRIC_DIFF_ERR_NONE_EXPLANATION
            % (metric_name, self.formatLabels(labels), saved_value, current_value),
        )
        diff = current_value - (saved_value or 0.0)
        self.assertEqual(
            expected_diff,
            diff,
            METRIC_DIFF_ERR_EXPLANATION
            % (
                metric_name,
                self.formatLabels(labels),
                diff,
                expected_diff,
                saved_value,
                current_value,
            ),
        ) 
開發者ID:korfuri,項目名稱:django-prometheus,代碼行數:33,代碼來源:testutils.py

示例6: ExportToDjangoView

# 需要導入模塊: import prometheus_client [as 別名]
# 或者: from prometheus_client import REGISTRY [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

示例7: server_stats

# 需要導入模塊: import prometheus_client [as 別名]
# 或者: from prometheus_client import REGISTRY [as 別名]
def server_stats(request):
    """
    Return a web response with the plain text version of the metrics.

    :rtype: :class:`aiohttp.web.Response`
    """
    rsp = web.Response(body=generate_latest(REGISTRY))
    # This is set separately because aiohttp complains about `;` in
    # content_type thinking it means there's also a charset.
    # cf. https://github.com/aio-libs/aiohttp/issues/2197
    rsp.content_type = CONTENT_TYPE_LATEST
    return rsp 
開發者ID:hynek,項目名稱:prometheus-async,代碼行數:14,代碼來源:web.py

示例8: app

# 需要導入模塊: import prometheus_client [as 別名]
# 或者: from prometheus_client import REGISTRY [as 別名]
def app() -> Flask:
    app = create_app('myapp.config.TestConfig')
    prometheus_client.REGISTRY = prometheus_client.CollectorRegistry(auto_describe=True)
    myapp_extensions.metrics = GunicornInternalPrometheusMetrics.for_app_factory(group_by="endpoint")
    ctx = app.app_context()
    ctx.push()
    yield app
    ctx.pop() 
開發者ID:rycus86,項目名稱:prometheus_flask_exporter,代碼行數:10,代碼來源:test_example.py

示例9: setUp

# 需要導入模塊: import prometheus_client [as 別名]
# 或者: from prometheus_client import REGISTRY [as 別名]
def setUp(self):
        self.app = Flask(__name__)
        self.app.testing = True
        self.client = self.app.test_client()

        # reset the underlying Prometheus registry
        prometheus_client.REGISTRY = prometheus_client.CollectorRegistry(auto_describe=True) 
開發者ID:rycus86,項目名稱:prometheus_flask_exporter,代碼行數:9,代碼來源:unittest_helper.py

示例10: get

# 需要導入模塊: import prometheus_client [as 別名]
# 或者: from prometheus_client import REGISTRY [as 別名]
def get(self):
        self.set_header("Content-Type", CONTENT_TYPE_LATEST)
        self.write(generate_latest(REGISTRY)) 
開發者ID:jupyterhub,項目名稱:binderhub,代碼行數:5,代碼來源:metrics.py

示例11: run

# 需要導入模塊: import prometheus_client [as 別名]
# 或者: from prometheus_client import REGISTRY [as 別名]
def run(self):
        agg_url = self._app.config.get("PROMETHEUS_PUSHGATEWAY_URL")
        while True:
            # Practically disable this worker, if there is no pushgateway.
            if agg_url is None or os.getenv("TEST", "false").lower() == "true":
                time.sleep(ONE_DAY_IN_SECONDS)
                continue

            time.sleep(PROMETHEUS_PUSH_INTERVAL_SECONDS)
            try:
                push_to_gateway(
                    agg_url,
                    job=self._app.config.get("PROMETHEUS_NAMESPACE", "quay"),
                    registry=REGISTRY,
                    grouping_key=process_grouping_key(),
                )
                logger.debug(
                    "pushed registry to pushgateway at %s with grouping key %s",
                    agg_url,
                    process_grouping_key(),
                )
            except urllib.error.URLError:
                # There are many scenarios when the gateway might not be running.
                # These could be testing scenarios or simply processes racing to start.
                # Rather than try to guess all of them, keep it simple and let it fail.
                if os.getenv("DEBUGLOG", "false").lower() == "true":
                    logger.exception(
                        "failed to push registry to pushgateway at %s with grouping key %s",
                        agg_url,
                        process_grouping_key(),
                    )
                else:
                    pass 
開發者ID:quay,項目名稱:quay,代碼行數:35,代碼來源:prometheus.py

示例12: get_prometheus_registry

# 需要導入模塊: import prometheus_client [as 別名]
# 或者: from prometheus_client import REGISTRY [as 別名]
def get_prometheus_registry(self):
        if not self._collector_registry and prometheus_client:
            self._collector_registry = prometheus_client.REGISTRY
        return self._collector_registry 
開發者ID:openstack,項目名稱:openstacksdk,代碼行數:6,代碼來源:cloud_region.py

示例13: __init__

# 需要導入模塊: import prometheus_client [as 別名]
# 或者: from prometheus_client import REGISTRY [as 別名]
def __init__(self, registry=None):
        """Constructor."""
        registry = registry or prometheus_client.REGISTRY
        # Here registry is explicit to allow us to mess with it in the tests.
        self.gourde = gourde.Gourde(__name__, registry=registry)
        self.app = self.gourde.app
        self.accessor = None
        self.args = None 
開發者ID:criteo,項目名稱:biggraphite,代碼行數:10,代碼來源:app.py

示例14: do_GET

# 需要導入模塊: import prometheus_client [as 別名]
# 或者: from prometheus_client import REGISTRY [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


注:本文中的prometheus_client.REGISTRY屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。