本文整理汇总了Python中prometheus_client.generate_latest方法的典型用法代码示例。如果您正苦于以下问题:Python prometheus_client.generate_latest方法的具体用法?Python prometheus_client.generate_latest怎么用?Python prometheus_client.generate_latest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类prometheus_client
的用法示例。
在下文中一共展示了prometheus_client.generate_latest方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_stats
# 需要导入模块: import prometheus_client [as 别名]
# 或者: from prometheus_client import generate_latest [as 别名]
def get_stats(self):
registry = CollectorRegistry()
labels = ['region', 'host', 'service', 'state']
cinder_services_stats_cache = self.get_cache_data()
for cinder_services_stat in cinder_services_stats_cache:
stat_gauge = Gauge(
self.gauge_name_sanitize(
cinder_services_stat['stat_name']),
'Openstack Cinder Service statistic',
labels,
registry=registry)
label_values = [self.osclient.region,
cinder_services_stat.get('host', ''),
cinder_services_stat.get('service', ''),
cinder_services_stat.get('state', '')]
stat_gauge.labels(
*
label_values).set(
cinder_services_stat['stat_value'])
return generate_latest(registry)
示例2: test_reports_metrics
# 需要导入模块: import prometheus_client [as 别名]
# 或者: from prometheus_client import generate_latest [as 别名]
def test_reports_metrics(self):
"""
``MetricsResource`` serves the metrics from the provided registry.
"""
c = Counter('cc', 'A counter', registry=self.registry)
c.inc()
root = Resource()
root.putChild(b'metrics', MetricsResource(registry=self.registry))
server = reactor.listenTCP(0, Site(root))
self.addCleanup(server.stopListening)
agent = Agent(reactor)
port = server.getHost().port
url = "http://localhost:{port}/metrics".format(port=port)
d = agent.request(b"GET", url.encode("ascii"))
d.addCallback(readBody)
d.addCallback(self.assertEqual, generate_latest(self.registry))
return d
示例3: get_stats
# 需要导入模块: import prometheus_client [as 别名]
# 或者: from prometheus_client import generate_latest [as 别名]
def get_stats(self):
registry = CollectorRegistry()
labels = ['region', 'host', 'service', 'state']
services_stats_cache = self.get_cache_data()
for services_stat in services_stats_cache:
stat_gauge = Gauge(
self.gauge_name_sanitize(
services_stat['stat_name']),
'Openstack Nova Service statistic',
labels,
registry=registry)
label_values = [self.osclient.region,
services_stat.get('host', ''),
services_stat.get('service', ''),
services_stat.get('state', '')]
stat_gauge.labels(*label_values).set(services_stat['stat_value'])
return generate_latest(registry)
示例4: get_stats
# 需要导入模块: import prometheus_client [as 别名]
# 或者: from prometheus_client import generate_latest [as 别名]
def get_stats(self):
registry = CollectorRegistry()
labels = ['region', 'url', 'service']
check_api_data_cache = self.get_cache_data()
for check_api_data in check_api_data_cache:
label_values = [
check_api_data['region'],
check_api_data['url'],
check_api_data['service']]
gague_name = self.gauge_name_sanitize(
"check_{}_api".format(check_api_data['service']))
check_gauge = Gauge(
gague_name,
'Openstack API check. fail = 0, ok = 1 and unknown = 2',
labels,
registry=registry)
check_gauge.labels(*label_values).set(check_api_data['status'])
return generate_latest(registry)
示例5: get_stats
# 需要导入模块: import prometheus_client [as 别名]
# 或者: from prometheus_client import generate_latest [as 别名]
def get_stats(self):
registry = CollectorRegistry()
labels = ['region', 'host', 'service', 'state']
neutron_agent_stats_cache = self.get_cache_data()
for neutron_agent_stat in neutron_agent_stats_cache:
stat_gauge = Gauge(
self.gauge_name_sanitize(
neutron_agent_stat['stat_name']),
'Openstack Neutron agent statistic',
labels,
registry=registry)
label_values = [self.osclient.region,
neutron_agent_stat.get('host', ''),
neutron_agent_stat.get('service', ''),
neutron_agent_stat.get('state', '')]
stat_gauge.labels(
*
label_values).set(
neutron_agent_stat['stat_value'])
return generate_latest(registry)
示例6: test_single_machine
# 需要导入模块: import prometheus_client [as 别名]
# 或者: from prometheus_client import generate_latest [as 别名]
def test_single_machine(enable_login):
responses.add(
method='GET',
url='https://management.azure.com/subscriptions/SUBSCRIPTION_ID/providers/Microsoft.Compute/virtualMachines?api-version=2017-03-30',
match_querystring=True,
json={'value': [
{
'id': '/subscriptions/SUBSCRIPTION_ID/resourceGroups/RESOURCE_GROUP/providers/Microsoft.Compute/virtualMachines/NAME',
'location': 'WESTEUROPE',
'properties': {'hardwareProfile': {'vmSize': 'SIZE'}}
}
]})
registry = CollectorRegistry()
c = AzureAllocatedVMCollector('app_id', 'app_secret', 'tenant_id', ['SUBSCRIPTION_ID'], 'SERIES_NAME')
registry.register(c)
result = generate_latest(registry).decode('utf8').split('\n')
assert 'SERIES_NAME{location="WESTEUROPE",resource_group="RESOURCE_GROUP",subscription="SUBSCRIPTION_ID",vm_size="SIZE"} 1.0' in result
示例7: test_extract_metrics
# 需要导入模块: import prometheus_client [as 别名]
# 或者: from prometheus_client import generate_latest [as 别名]
def test_extract_metrics(api_url, enrollment):
responses.add(
method='GET',
url=api_url,
match_querystring=True,
json=sample_data
)
registry = CollectorRegistry()
c = AzureEABillingCollector('costs', enrollment, 'ab123xy', 10)
registry.register(c)
result = generate_latest(registry).decode('utf8').split('\n')
assert len(result) == 5
expected_0 = 'costs{AccountName="platform",DepartmentName="engineering",MeterCategory="virtual network",MeterName="hours",MeterSubCategory="gateway hour",ResourceGroup="",SubscriptionName="production"} 0.0'
expected_1 = 'costs{AccountName="platform",DepartmentName="engineering",MeterCategory="windows azure storage",MeterName="standard io - page blob/disk (gb)",MeterSubCategory="locally redundant",ResourceGroup="my-group",SubscriptionName="production"} 1.0'
assert result[2] == expected_0
assert result[3] == expected_1
示例8: root
# 需要导入模块: import prometheus_client [as 别名]
# 或者: from prometheus_client import generate_latest [as 别名]
def root():
# check access
ip_whitelist = ip_network(current_app.config.get('PROMETHEUS_WHITELIST'))
if ip_address(request.remote_addr) not in ip_whitelist:
_jwt_required(current_app.config['JWT_DEFAULT_REALM'])
MU = MetricUpdater()
registry = CollectorRegistry()
multiprocess.MultiProcessCollector(registry)
data = generate_latest(registry)
response = make_response(data)
response.headers['Content-Type'] = CONTENT_TYPE_LATEST
response.headers['Content-Length'] = str(len(data))
logger.info('Kqueen metrics updating')
MU.update_metrics()
return response
示例9: poll_mock
# 需要导入模块: import prometheus_client [as 别名]
# 或者: from prometheus_client import generate_latest [as 别名]
def poll_mock():
registry = CollectorRegistry()
g1 = Gauge('metric1', 'processor usage', ['matched_label', 'node', 'flavor'], registry=registry)
g1.labels(matched_label="foobar", node="host1", flavor="test").set(99.9)
g2 = Gauge('metric2', 'memory usage', ['matched_label', 'node', 'timestamp'], registry=registry)
g2.labels(matched_label="foobar", node="host2", timestamp="123").set(12.2)
c1 = Counter('counter1', 'hits', ['node'], registry=registry)
c1.labels(node="host2").inc(42)
g3 = Gauge('metric3', 'memory usage', ['matched_label', 'node', 'timestamp'], registry=registry)
g3.labels(matched_label="foobar", node="host2", timestamp="456").set(float('inf'))
poll_mock_patch = mock.patch(
'requests.get',
return_value=mock.MagicMock(
status_code=200,
iter_lines=lambda **kwargs: ensure_unicode(generate_latest(registry)).split("\n"),
headers={'Content-Type': "text/plain"},
),
)
with poll_mock_patch:
yield
示例10: metrics
# 需要导入模块: import prometheus_client [as 别名]
# 或者: from prometheus_client import generate_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)
示例11: metrics
# 需要导入模块: import prometheus_client [as 别名]
# 或者: from prometheus_client import generate_latest [as 别名]
def metrics():
registry = CollectorRegistry()
multiprocess.MultiProcessCollector(registry)
data = generate_latest(registry)
return Response(data, mimetype=CONTENT_TYPE_LATEST)
示例12: ExportToDjangoView
# 需要导入模块: import prometheus_client [as 别名]
# 或者: from prometheus_client import generate_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
)
示例13: server_stats
# 需要导入模块: import prometheus_client [as 别名]
# 或者: from prometheus_client import generate_latest [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
示例14: metrics
# 需要导入模块: import prometheus_client [as 别名]
# 或者: from prometheus_client import generate_latest [as 别名]
def metrics():
return generate_latest()
示例15: on_metrics
# 需要导入模块: import prometheus_client [as 别名]
# 或者: from prometheus_client import generate_latest [as 别名]
def on_metrics(self):
"""
Request handler for /metrics route
"""
response = Response(generate_latest())
response.headers['content-type'] = CONTENT_TYPE_LATEST
return response