本文整理匯總了Python中prometheus_client.REGISTRY.get_sample_value方法的典型用法代碼示例。如果您正苦於以下問題:Python REGISTRY.get_sample_value方法的具體用法?Python REGISTRY.get_sample_value怎麽用?Python REGISTRY.get_sample_value使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類prometheus_client.REGISTRY
的用法示例。
在下文中一共展示了REGISTRY.get_sample_value方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_initial_metric_values
# 需要導入模塊: from prometheus_client import REGISTRY [as 別名]
# 或者: from prometheus_client.REGISTRY import get_sample_value [as 別名]
def test_initial_metric_values(self):
self._assert_task_states(celery.states.ALL_STATES, 0)
assert (
REGISTRY.get_sample_value(
"celery_workers", labels=dict(namespace=self.namespace)
)
== 0
)
assert (
REGISTRY.get_sample_value(
"celery_tasks_latency_seconds_count",
labels=dict(namespace=self.namespace, name=self.task, queue=self.queue),
)
== 0
)
assert (
REGISTRY.get_sample_value(
"celery_tasks_latency_seconds_sum",
labels=dict(namespace=self.namespace, name=self.task, queue=self.queue),
)
== 0
)
示例2: get_aggregated_sample_values
# 需要導入模塊: from prometheus_client import REGISTRY [as 別名]
# 或者: from prometheus_client.REGISTRY import get_sample_value [as 別名]
def get_aggregated_sample_values(registry, name, labels=None):
"""
Returns the aggregated value based on cases where all the labels specified
match. Returns 0 if no values are found.
The reason why REGISTRY.get_sample_value is not directly used is that the
library function performs an equality on all the labels instead of only the
labels provided.
"""
labels = labels or {}
total = 0
for metric in registry.collect():
for n, l, value in metric.samples:
if n == name:
# Ensure that all labels provided match
matching = all(k in l and v == l[k] for _, (k, v) in enumerate(labels.items()))
if matching:
total += value
return total
示例3: test_add_probability_filter_passed_no_nodes_metric
# 需要導入模塊: from prometheus_client import REGISTRY [as 別名]
# 或者: from prometheus_client.REGISTRY import get_sample_value [as 別名]
def test_add_probability_filter_passed_no_nodes_metric(prometheus_noop_scenario):
"""
Ensures that add_probability_filter_passed_no_nodes_metric is called when
the filter decides to pass no nodes based on a probability
"""
assert prometheus_noop_scenario.name == "test scenario"
random.seed(6) # make the tests deterministic
candidates = [make_dummy_object()]
before = REGISTRY.get_sample_value(PROBABILITY_FILTER_NOT_PASSED_METRIC_NAME)
assert before == 0
criterion = {"probabilityPassAll": 0.00000001}
prometheus_noop_scenario.filter_probability(candidates, criterion)
after = REGISTRY.get_sample_value(PROBABILITY_FILTER_NOT_PASSED_METRIC_NAME)
assert after == 1
示例4: test_workers_count
# 需要導入模塊: from prometheus_client import REGISTRY [as 別名]
# 或者: from prometheus_client.REGISTRY import get_sample_value [as 別名]
def test_workers_count(self):
assert REGISTRY.get_sample_value('celery_workers') == 0
with patch.object(self.app.control, 'ping') as mock_ping:
w = WorkerMonitoringThread(app=self.app)
mock_ping.return_value = []
w.update_workers_count()
assert REGISTRY.get_sample_value('celery_workers') == 0
mock_ping.return_value = [0] # 1 worker
w.update_workers_count()
assert REGISTRY.get_sample_value('celery_workers') == 1
mock_ping.return_value = [0, 0] # 2 workers
w.update_workers_count()
assert REGISTRY.get_sample_value('celery_workers') == 2
mock_ping.return_value = []
w.update_workers_count()
assert REGISTRY.get_sample_value('celery_workers') == 0
示例5: sample_count_fixture
# 需要導入模塊: from prometheus_client import REGISTRY [as 別名]
# 或者: from prometheus_client.REGISTRY import get_sample_value [as 別名]
def sample_count_fixture(graph_name):
def sample_count(node, field):
return REGISTRY.get_sample_value(
'graph_field_time_count',
dict(graph=graph_name, node=node, field=field),
)
return sample_count
示例6: test_get_except
# 需要導入模塊: from prometheus_client import REGISTRY [as 別名]
# 或者: from prometheus_client.REGISTRY import get_sample_value [as 別名]
def test_get_except(self, mock_get):
"""Test handling of request with ConnectionError."""
before = REGISTRY.get_sample_value("rbac_connection_errors_total")
rbac = RbacService()
url = f"{rbac.protocol}://{rbac.host}:{rbac.port}{rbac.path}"
with self.assertRaises(RbacConnectionError):
rbac._request_user_access(url, headers={})
after = REGISTRY.get_sample_value("rbac_connection_errors_total")
self.assertEqual(1, after - before)
mock_get.assert_called()
示例7: _assert_task_states
# 需要導入模塊: from prometheus_client import REGISTRY [as 別名]
# 或者: from prometheus_client.REGISTRY import get_sample_value [as 別名]
def _assert_task_states(self, states, cnt):
for state in states:
task_by_name_label = dict(
namespace=self.namespace, name=self.task, state=state, queue=self.queue
)
assert (
REGISTRY.get_sample_value(
"celery_tasks_total", labels=task_by_name_label
)
== cnt
)
示例8: test_add_filtered_to_empty_set_metric
# 需要導入模塊: from prometheus_client import REGISTRY [as 別名]
# 或者: from prometheus_client.REGISTRY import get_sample_value [as 別名]
def test_add_filtered_to_empty_set_metric(prometheus_noop_scenario):
before = REGISTRY.get_sample_value(FILTERED_TO_EMPTY_SET_METRIC_NAME)
assert before == 0
prometheus_noop_scenario.execute()
after = REGISTRY.get_sample_value(FILTERED_TO_EMPTY_SET_METRIC_NAME)
assert after == 1
示例9: test_initial_metric_values
# 需要導入模塊: from prometheus_client import REGISTRY [as 別名]
# 或者: from prometheus_client.REGISTRY import get_sample_value [as 別名]
def test_initial_metric_values(self):
self._assert_task_states(celery.states.ALL_STATES, 0)
assert REGISTRY.get_sample_value('celery_workers') == 0
assert REGISTRY.get_sample_value('celery_task_latency_count') == 0
assert REGISTRY.get_sample_value('celery_task_latency_sum') == 0
示例10: test_tasks_events
# 需要導入模塊: from prometheus_client import REGISTRY [as 別名]
# 或者: from prometheus_client.REGISTRY import get_sample_value [as 別名]
def test_tasks_events(self):
task_uuid = uuid()
hostname = 'myhost'
local_received = time()
latency_before_started = 123.45
runtime = 234.5
m = MonitorThread(app=self.app)
self._assert_task_states(celery.states.ALL_STATES, 0)
assert REGISTRY.get_sample_value('celery_task_latency_count') == 0
assert REGISTRY.get_sample_value('celery_task_latency_sum') == 0
m._process_event(Event(
'task-received', uuid=task_uuid, name=self.task,
args='()', kwargs='{}', retries=0, eta=None, hostname=hostname,
clock=0,
local_received=local_received))
self._assert_all_states({celery.states.RECEIVED})
m._process_event(Event(
'task-started', uuid=task_uuid, hostname=hostname,
clock=1, name=self.task,
local_received=local_received + latency_before_started))
self._assert_all_states({celery.states.STARTED})
m._process_event(Event(
'task-succeeded', uuid=task_uuid, result='42',
runtime=runtime, hostname=hostname, clock=2,
local_received=local_received + latency_before_started + runtime))
self._assert_all_states({celery.states.SUCCESS})
assert REGISTRY.get_sample_value('celery_task_latency_count') == 1
self.assertAlmostEqual(REGISTRY.get_sample_value(
'celery_task_latency_sum'), latency_before_started)
assert REGISTRY.get_sample_value(
'celery_tasks_runtime_seconds_count',
labels=dict(name=self.task)) == 1
assert REGISTRY.get_sample_value(
'celery_tasks_runtime_seconds_sum',
labels=dict(name=self.task)) == 234.5
示例11: test_can_measure_queue_length
# 需要導入模塊: from prometheus_client import REGISTRY [as 別名]
# 或者: from prometheus_client.REGISTRY import get_sample_value [as 別名]
def test_can_measure_queue_length(self):
celery_app = get_celery_app(queue='realqueue')
sample_task = SampleTask()
sample_task.app = celery_app
monitoring_thread_instance = QueueLengthMonitoringThread(celery_app, queue_list=['realqueue'])
sample_task.delay()
monitoring_thread_instance.measure_queues_length()
sample = REGISTRY.get_sample_value('celery_queue_length', {'queue_name':'realqueue'})
self.assertEqual(1.0, sample)
示例12: test_set_zero_on_queue_length_when_an_channel_layer_error_occurs_during_queue_read
# 需要導入模塊: from prometheus_client import REGISTRY [as 別名]
# 或者: from prometheus_client.REGISTRY import get_sample_value [as 別名]
def test_set_zero_on_queue_length_when_an_channel_layer_error_occurs_during_queue_read(self):
instance = QueueLengthMonitoringThread(app=self.app, queue_list=['noqueue'])
instance.measure_queues_length()
sample = REGISTRY.get_sample_value('celery_queue_length', {'queue_name':'noqueue'})
self.assertEqual(0.0, sample)
示例13: test_counter_inc
# 需要導入模塊: from prometheus_client import REGISTRY [as 別名]
# 或者: from prometheus_client.REGISTRY import get_sample_value [as 別名]
def test_counter_inc(self):
before = REGISTRY.get_sample_value('foos_total')
foo()
after = REGISTRY.get_sample_value('foos_total')
self.assertEqual(1, after - before)
示例14: test_prometheus_metrics_counter
# 需要導入模塊: from prometheus_client import REGISTRY [as 別名]
# 或者: from prometheus_client.REGISTRY import get_sample_value [as 別名]
def test_prometheus_metrics_counter():
metrics = PrometheusMetricsFactory(namespace='test')
counter1 = metrics.create_counter(name='jaeger:test_counter',
tags={'result': 'ok'})
counter1(1)
counter2 = metrics.create_counter(name='jaeger:test_counter',
tags={'result': 'ok'})
counter2(1)
after = REGISTRY.get_sample_value('test_jaeger:test_counter',
{'result': 'ok'})
assert 2 == after
示例15: test_prometheus_metrics_counter_without_tags
# 需要導入模塊: from prometheus_client import REGISTRY [as 別名]
# 或者: from prometheus_client.REGISTRY import get_sample_value [as 別名]
def test_prometheus_metrics_counter_without_tags():
metrics = PrometheusMetricsFactory()
counter = metrics.create_counter(name='jaeger:test_counter_no_tags')
counter(1)
after = REGISTRY.get_sample_value('jaeger:test_counter_no_tags')
assert 1 == after