当前位置: 首页>>代码示例>>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;未经允许,请勿转载。