本文整理汇总了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)),
),
)
示例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
)
示例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()))
示例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())
示例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,
),
)
示例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
)
示例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
示例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()
示例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)
示例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))
示例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
示例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
示例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
示例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)