本文整理汇总了Python中monasca_tempest_tests.tests.api.helpers.create_metric函数的典型用法代码示例。如果您正苦于以下问题:Python create_metric函数的具体用法?Python create_metric怎么用?Python create_metric使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了create_metric函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: _create_metrics_for_match_by_sub_expressions_list
def _create_metrics_for_match_by_sub_expressions_list(self, num,
alarm_definition_id):
# create some metrics
metric1 = helpers.create_metric(
name='cpu.idle_perc',
dimensions={'service': 'monitoring',
'hostname': 'mini-mon',
'device': '/dev/sda1'})
metric2 = helpers.create_metric(
name='cpu.idle_perc',
dimensions={'service': 'monitoring',
'hostname': 'devstack',
'device': '/dev/sda1'})
metric3 = helpers.create_metric(
name='cpu.idle_perc',
dimensions={'service': 'monitoring',
'hostname': 'mini-mon',
'device': 'tmpfs'})
metric4 = helpers.create_metric(
name='cpu.idle_perc',
dimensions={'service': 'monitoring',
'hostname': 'devstack',
'device': 'tmpfs'})
self.monasca_client.create_metrics(metric1)
self.monasca_client.create_metrics(metric2)
self.monasca_client.create_metrics(metric3)
self.monasca_client.create_metrics(metric4)
self._waiting_for_alarms(num, alarm_definition_id)
开发者ID:skydiator,项目名称:monasca-api,代码行数:28,代码来源:test_alarms.py
示例2: test_create_metrics
def test_create_metrics(self):
metrics = [
helpers.create_metric(),
helpers.create_metric()
]
resp, body = self.monasca_client.create_metrics(metrics)
self.assertEqual(204, resp.status)
开发者ID:achoi0330,项目名称:avos_test,代码行数:7,代码来源:test_metrics.py
示例3: test_list_metrics_with_offset_limit
def test_list_metrics_with_offset_limit(self):
name = data_utils.rand_name()
key1 = data_utils.rand_name()
key2 = data_utils.rand_name()
metrics = [
helpers.create_metric(name=name, dimensions={
key1: 'value-1', key2: 'value-1'}),
helpers.create_metric(name=name, dimensions={
key1: 'value-2', key2: 'value-2'}),
helpers.create_metric(name=name, dimensions={
key1: 'value-3', key2: 'value-3'}),
helpers.create_metric(name=name, dimensions={
key1: 'value-4', key2: 'value-4'})
]
self.monasca_client.create_metrics(metrics)
query_param = '?name=' + name
for i in xrange(constants.MAX_RETRIES):
resp, response_body = self.monasca_client.list_metrics(query_param)
elements = response_body['elements']
if elements and len(elements) == 4:
break
time.sleep(constants.RETRY_WAIT_SECS)
if i == constants.MAX_RETRIES - 1:
error_msg = ("Failed test_list_metrics_with_offset_limit: "
"timeout on waiting for metrics: 4 metrics "
"are needed. Current number of elements = "
"{}").format(len(elements))
self.fail(error_msg)
first_element = elements[0]
query_parms = '?name=' + name + '&limit=4'
resp, response_body = self.monasca_client.list_metrics(query_parms)
self.assertEqual(200, resp.status)
elements = response_body['elements']
self.assertEqual(4, len(elements))
self.assertEqual(first_element, elements[0])
for metric_index in xrange(len(elements) - 1):
metric = elements[metric_index]
max_limit = 3 - metric_index
for limit in xrange(1, max_limit):
first_index = metric_index + 1
last_index = first_index + limit
expected_elements = elements[first_index:last_index]
query_parms = '?name=' + name + '&offset=' + \
str(metric['id']) + '&limit=' + \
str(limit)
resp, response_body = self.\
monasca_client.list_metrics(query_parms)
self.assertEqual(200, resp.status)
new_elements = response_body['elements']
self.assertEqual(limit, len(new_elements))
for i in xrange(len(expected_elements)):
self.assertEqual(expected_elements[i], new_elements[i])
开发者ID:jobrs,项目名称:monasca-api,代码行数:58,代码来源:test_metrics.py
示例4: test_create_metrics
def test_create_metrics(self):
name = data_utils.rand_name('name')
key = data_utils.rand_name('key')
value = data_utils.rand_name('value')
timestamp = int(round(time.time() * 1000))
time_iso = helpers.timestamp_to_iso(timestamp)
end_timestamp = int(round(timestamp + 3600 * 24 * 1000))
end_time_iso = helpers.timestamp_to_iso(end_timestamp)
value_meta_key1 = data_utils.rand_name('meta_key')
value_meta_value1 = data_utils.rand_name('meta_value')
value_meta_key2 = data_utils.rand_name('value_meta_key')
value_meta_value2 = data_utils.rand_name('value_meta_value')
metrics = [
helpers.create_metric(name=name,
dimensions={key: value},
timestamp=timestamp,
value=1.23,
value_meta={
value_meta_key1: value_meta_value1
}),
helpers.create_metric(name=name,
dimensions={key: value},
timestamp=timestamp + 6000,
value=4.56,
value_meta={
value_meta_key2: value_meta_value2
})
]
resp, response_body = self.monasca_client.create_metrics(metrics)
self.assertEqual(204, resp.status)
query_param = '?name=' + name + '&start_time=' + str(time_iso) + \
'&end_time=' + str(end_time_iso)
for i in xrange(constants.MAX_RETRIES):
resp, response_body = self.monasca_client.\
list_measurements(query_param)
self.assertEqual(200, resp.status)
elements = response_body['elements']
for element in elements:
if str(element['name']) == name \
and len(element['measurements']) == 2:
self._verify_list_measurements_element(element, key, value)
first_measurement = element['measurements'][0]
second_measurement = element['measurements'][1]
self._verify_list_measurements_measurement(
first_measurement, metrics[0], value_meta_key1,
value_meta_value1)
self._verify_list_measurements_measurement(
second_measurement, metrics[1], value_meta_key2,
value_meta_value2)
return
time.sleep(constants.RETRY_WAIT_SECS)
if i == constants.MAX_RETRIES - 1:
error_msg = "Failed test_create_metrics: " \
"timeout on waiting for metrics: at least " \
"one metric is needed. Current number of " \
"metrics = 0"
self.fail(error_msg)
开发者ID:jobrs,项目名称:monasca-api,代码行数:57,代码来源:test_metrics.py
示例5: test_verify_deterministic_alarm
def test_verify_deterministic_alarm(self):
metric_name = data_utils.rand_name('log.fancy')
metric_dimensions = {'service': 'monitoring',
'hostname': 'mini-mon'}
name = data_utils.rand_name('alarm_definition')
expression = ('count(%s{service=monitoring},deterministic) > 10'
% metric_name)
match_by = ['hostname', 'device']
description = 'deterministic'
alarm_definition = helpers.create_alarm_definition(
name=name, description=description,
expression=expression, match_by=match_by)
resp, response_body = self.monasca_client.create_alarm_definitions(
alarm_definition)
alarm_definition_id = response_body['id']
query_param = '?alarm_definition_id=' + str(alarm_definition_id)
# 1. ensure alarm was not created
resp, response_body = self.monasca_client.list_alarms(query_param)
self._verify_list_alarms_elements(resp, response_body, 0)
# 2. put some metrics here to create it, should be in ok
metrics_count = 5
for it in range(0, metrics_count):
metric = helpers.create_metric(name=metric_name,
value=1.0,
dimensions=metric_dimensions)
self.monasca_client.create_metrics(metric)
self._wait_for_alarms(1, alarm_definition_id)
resp, response_body = self.monasca_client.list_alarms(query_param)
self._verify_list_alarms_elements(resp, response_body, 1)
element = response_body['elements'][0]
self.assertEqual('OK', element['state'])
# 3. exceed threshold
metrics_count = 20
for it in range(0, metrics_count):
metric = helpers.create_metric(name=metric_name,
value=1.0,
dimensions=metric_dimensions)
self.monasca_client.create_metrics(metric)
self._wait_for_alarms(1, alarm_definition_id)
resp, response_body = self.monasca_client.list_alarms(query_param)
self._verify_list_alarms_elements(resp, response_body, 1)
element = response_body['elements'][0]
self.assertEqual('ALARM', element['state'])
开发者ID:bigluster,项目名称:monasca-api,代码行数:56,代码来源:test_alarms.py
示例6: resource_setup
def resource_setup(cls):
super(TestDimensions, cls).resource_setup()
metric_name1 = data_utils.rand_name()
name1 = "name_1"
name2 = "name_2"
value1 = "value_1"
value2 = "value_2"
timestamp = int(round(time.time() * 1000))
time_iso = helpers.timestamp_to_iso(timestamp)
metric1 = helpers.create_metric(name=metric_name1,
dimensions={name1: value1,
name2: value2
})
cls.monasca_client.create_metrics(metric1)
metric1 = helpers.create_metric(name=metric_name1,
dimensions={name1: value2})
cls.monasca_client.create_metrics(metric1)
metric_name2 = data_utils.rand_name()
name3 = "name_3"
value3 = "value_3"
metric2 = helpers.create_metric(name=metric_name2,
dimensions={name3: value3})
cls.monasca_client.create_metrics(metric2)
metric_name3 = data_utils.rand_name()
metric3 = helpers.create_metric(name=metric_name3,
dimensions={name1: value3})
cls.monasca_client.create_metrics(metric3)
cls._test_metric1 = metric1
cls._test_metric2 = metric2
cls._test_metric_names = {metric_name1, metric_name2, metric_name3}
cls._dim_names_metric1 = [name1, name2]
cls._dim_names_metric2 = [name3]
cls._dim_names = cls._dim_names_metric1 + cls._dim_names_metric2
cls._dim_values_for_metric1 = [value1, value2]
cls._dim_values = [value1, value2, value3]
param = '?start_time=' + time_iso
returned_name_set = set()
for i in xrange(constants.MAX_RETRIES):
resp, response_body = cls.monasca_client.list_metrics(
param)
elements = response_body['elements']
for element in elements:
returned_name_set.add(str(element['name']))
if cls._test_metric_names.issubset(returned_name_set):
return
time.sleep(constants.RETRY_WAIT_SECS)
assert False, 'Unable to initialize metrics'
开发者ID:jobrs,项目名称:monasca-api,代码行数:55,代码来源:test_dimensions.py
示例7: test_list_metrics_with_offset_limit
def test_list_metrics_with_offset_limit(self):
name = data_utils.rand_name()
key1 = data_utils.rand_name()
key2 = data_utils.rand_name()
metrics = [
helpers.create_metric(name=name, dimensions={
key1: 'value-1', key2: 'value-1'}),
helpers.create_metric(name=name, dimensions={
key1: 'value-2', key2: 'value-2'}),
helpers.create_metric(name=name, dimensions={
key1: 'value-3', key2: 'value-3'}),
helpers.create_metric(name=name, dimensions={
key1: 'value-4', key2: 'value-4'})
]
resp, body = self.monasca_client.create_metrics(metrics)
time.sleep(WAIT_TIME)
query_parms = '?name=' + name
resp, response_body = self.monasca_client.list_metrics(query_parms)
self.assertEqual(200, resp.status)
elements = response_body['elements']
first_element = elements[0]
last_element = elements[3]
query_parms = '?name=' + name + '&limit=4'
resp, response_body = self.monasca_client.list_metrics(query_parms)
self.assertEqual(200, resp.status)
elements = response_body['elements']
self.assertEqual(4, len(elements))
self.assertEqual(first_element, elements[0])
for limit in xrange(1, 5):
next_element = elements[limit - 1]
while True:
query_parms = '?name=' + name + '&offset=' +\
str(next_element['id']) + '&limit=' + str(limit)
resp, response_body = self.monasca_client.list_metrics(
query_parms)
self.assertEqual(200, resp.status)
new_elements = response_body['elements']
if len(new_elements) > limit - 1:
self.assertEqual(limit, len(new_elements))
next_element = new_elements[limit - 1]
elif len(new_elements) > 0 and len(new_elements) <= limit - 1:
self.assertEqual(last_element, new_elements[0])
break
else:
self.assertEqual(last_element, next_element)
break
开发者ID:achoi0330,项目名称:avos_test,代码行数:54,代码来源:test_metrics.py
示例8: test_create_metric_with_invalid_chars_in_dimensions
def test_create_metric_with_invalid_chars_in_dimensions(self):
for invalid_char in constants.INVALID_CHARS:
metric = helpers.create_metric('name-1', {'key-1': invalid_char})
self.assertRaises(exceptions.UnprocessableEntity,
self.monasca_client.create_metrics,
metric)
for invalid_char in constants.INVALID_CHARS:
metric = helpers.create_metric('name-1', {invalid_char: 'value-1'})
self.assertRaises(exceptions.UnprocessableEntity,
self.monasca_client.create_metrics,
metric)
开发者ID:achoi0330,项目名称:avos_test,代码行数:11,代码来源:test_metrics.py
示例9: _create_metrics_for_match_by
def _create_metrics_for_match_by(self, num, alarm_definition_id):
metric1 = helpers.create_metric(
name='cpu.idle_perc',
dimensions={'service': 'monitoring',
'hostname': 'mini-mon'})
metric2 = helpers.create_metric(
name='cpu.idle_perc',
dimensions={'service': 'monitoring',
'hostname': 'devstack'})
self.monasca_client.create_metrics(metric1)
self.monasca_client.create_metrics(metric2)
self._waiting_for_alarms(num, alarm_definition_id)
开发者ID:skydiator,项目名称:monasca-api,代码行数:12,代码来源:test_alarms.py
示例10: _create_metrics_with_different_dimensions
def _create_metrics_with_different_dimensions(self, same_name=True):
name1 = data_utils.rand_name('name1')
name2 = name1 if same_name else data_utils.rand_name('name2')
name3 = name1 if same_name else data_utils.rand_name('name3')
key_service = data_utils.rand_name('service')
values = [data_utils.rand_name('value1'),
data_utils.rand_name('value2')]
metrics = [helpers.create_metric(name1, {key_service: values[0]}),
helpers.create_metric(name2, {key_service: values[1]}),
helpers.create_metric(name3, {'key3': 'value3'})]
resp, response_body = self.monasca_client.create_metrics(metrics)
self.assertEqual(204, resp.status)
return metrics, name1, key_service, values
开发者ID:jobrs,项目名称:monasca-api,代码行数:13,代码来源:test_metrics.py
示例11: test_list_metrics_with_tenant
def test_list_metrics_with_tenant(self):
name = data_utils.rand_name('name')
key = data_utils.rand_name('key')
value = data_utils.rand_name('value')
tenant = self.tenants_client.create_tenant(
name=data_utils.rand_name('test_tenant'))['tenant']
# Delete the tenant at the end of the test
self.addCleanup(self.tenants_client.delete_tenant, tenant['id'])
metric = helpers.create_metric(name=name,
dimensions={key: value})
resp, response_body = self.monasca_client.create_metrics(
metric, tenant_id=tenant['id'])
self.assertEqual(204, resp.status)
query_param = '?tenant_id=' + str(tenant['id'])
for i in xrange(constants.MAX_RETRIES):
resp, response_body = self.monasca_client.list_metrics(query_param)
self.assertEqual(200, resp.status)
elements = response_body['elements']
for element in elements:
if str(element['name']) == name:
self._verify_list_metrics_element(element, test_key=key,
test_value=value)
return
time.sleep(constants.RETRY_WAIT_SECS)
if i == constants.MAX_RETRIES - 1:
error_msg = "Failed test_list_metrics_with_tenant: " \
"timeout on waiting for metrics: at least " \
"one metric is needed. Current number of " \
"metrics = 0"
self.fail(error_msg)
开发者ID:jobrs,项目名称:monasca-api,代码行数:30,代码来源:test_metrics.py
示例12: test_create_metric_with_value_meta_name_exceeds_max_length
def test_create_metric_with_value_meta_name_exceeds_max_length(self):
long_value_meta_name = "x" * (constants.MAX_VALUE_META_NAME_LENGTH + 1)
value_meta_dict = {long_value_meta_name: "value_meta_value"}
metric = helpers.create_metric(name='name', value_meta=value_meta_dict)
self.assertRaises(exceptions.UnprocessableEntity,
self.monasca_client.create_metrics,
metric)
开发者ID:jobrs,项目名称:monasca-api,代码行数:7,代码来源:test_metrics.py
示例13: test_list_alarms_by_multiple_metric_dimensions
def test_list_alarms_by_multiple_metric_dimensions(self):
metric = helpers.create_metric(
name=data_utils.rand_name("multi-dimension"),
dimensions={data_utils.rand_name("key-1"): data_utils.rand_name("value-1"),
data_utils.rand_name("key-2"): data_utils.rand_name("value-2")},
value=20
)
dimension_strings = [key + '=' + value for key, value in metric['dimensions'].items()]
alarm_def = helpers.create_alarm_definition(
name=data_utils.rand_name("multi-dimensions"),
expression=metric['name'] + "{" + ','.join(dimension_strings) + '} > 15'
)
resp, response_body = self.monasca_client.create_alarm_definitions(alarm_def)
self.assertEqual(201, resp.status)
alarm_def_id = response_body['id']
resp, response_body = self.monasca_client.create_metrics(metric)
self.assertEqual(204, resp.status)
self._wait_for_alarms(1, alarm_def_id)
query_dimensions = [key + ':' + value for key, value in metric['dimensions'].items()]
query_parms="?metric_dimensions=" + ','.join(query_dimensions)
resp, response_body = self.monasca_client.list_alarms(query_parms)
self._verify_list_alarms_elements(resp, response_body,
expect_num_elements=1)
element = response_body['elements'][0]
metric = element['metrics'][0]
self._verify_metric_in_alarm(metric, metric)
self.assertEqual(alarm_def_id,
element['alarm_definition']['id'])
开发者ID:Missxiaoguo,项目名称:monasca-api,代码行数:32,代码来源:test_alarms.py
示例14: test_create_metric_with_empty_key_in_dimensions
def test_create_metric_with_empty_key_in_dimensions(self):
name = data_utils.rand_name('name')
metric = helpers.create_metric(name=name,
dimensions={'': 'value'})
self.assertRaises(exceptions.UnprocessableEntity,
self.monasca_client.create_metrics,
metric)
开发者ID:jobrs,项目名称:monasca-api,代码行数:7,代码来源:test_metrics.py
示例15: resource_setup
def resource_setup(cls):
super(TestMetricsNames, cls).resource_setup()
name = data_utils.rand_name()
key = data_utils.rand_name()
value = data_utils.rand_name()
cls._param = key + ':' + value
metric = helpers.create_metric(name=name,
dimensions={key: value})
cls._test_metric = metric
cls.monasca_client.create_metrics(metric)
start_time = str(timeutils.iso8601_from_timestamp(
metric['timestamp'] / 1000.0))
query_params = '?name=' + str(cls._test_metric['name']) +\
'&start_time=' + start_time
for i in xrange(constants.MAX_RETRIES):
resp, response_body = cls.monasca_client.list_metrics(
query_params)
elements = response_body['elements']
for element in elements:
if str(element['name']) == cls._test_metric['name']:
return
time.sleep(constants.RETRY_WAIT_SECS)
assert False, 'Unable to initialize metrics'
开发者ID:Missxiaoguo,项目名称:monasca-api,代码行数:26,代码来源:test_metrics_names.py
示例16: test_create_metric_no_value
def test_create_metric_no_value(self):
timestamp = int(round(time.time() * 1000))
metric = helpers.create_metric(timestamp=timestamp,
value=None)
self.assertRaises(exceptions.UnprocessableEntity,
self.monasca_client.create_metrics,
metric)
开发者ID:jobrs,项目名称:monasca-api,代码行数:7,代码来源:test_metrics.py
示例17: resource_setup
def resource_setup(cls):
super(TestAlarmsStateHistoryOneTransition, cls).resource_setup()
for i in xrange(MIN_HISTORY):
alarm_definition = helpers.create_alarm_definition(
name=data_utils.rand_name('alarm_state_history' + str(i + 1)),
expression="min(name-" + str(i + 1) + ") < " + str(i + 1))
cls.monasca_client.create_alarm_definitions(alarm_definition)
num_transitions = 0
for timer in xrange(constants.MAX_RETRIES):
for i in xrange(MIN_HISTORY):
# Create some metrics to prime the system and waiting for the
# alarms to be created and then for them to change state.
# MIN_HISTORY number of Alarms State History are needed.
metric = helpers.create_metric(name="name-" + str(i + 1))
cls.monasca_client.create_metrics(metric)
# sleep 0.05 second between metrics to make sure timestamps
# are different
time.sleep(0.05)
resp, response_body = cls.monasca_client.\
list_alarms_state_history()
elements = response_body['elements']
if len(elements) >= MIN_HISTORY:
return
else:
num_transitions = len(elements)
time.sleep(constants.RETRY_WAIT_SECS)
assert False, "Required {} alarm state transitions, but found {}".\
format(MIN_HISTORY, num_transitions)
开发者ID:Missxiaoguo,项目名称:monasca-api,代码行数:30,代码来源:test_alarms_state_history_one_transition.py
示例18: test_list_statistics_with_no_merge_metrics
def test_list_statistics_with_no_merge_metrics(self):
key = data_utils.rand_name('key')
value = data_utils.rand_name('value')
metric3 = helpers.create_metric(
name=self._test_name,
dimensions={key: value},
timestamp=self._start_timestamp + 2000)
self.monasca_client.create_metrics(metric3)
query_param = '?name=' + str(self._test_name) + '&start_time=' + \
self._start_time_iso + '&end_time=' + helpers.\
timestamp_to_iso(self._start_timestamp + 1000 * 4) + \
'&merge_metrics=True'
for i in xrange(constants.MAX_RETRIES):
resp, response_body = self.monasca_client.\
list_measurements(query_param)
elements = response_body['elements']
for element in elements:
if str(element['name']) == self._test_name and len(
element['measurements']) == 3:
end_time_iso = helpers.timestamp_to_iso(
self._start_timestamp + 1000 * 4)
query_parms = '?name=' + str(self._test_name) + \
'&statistics=avg' + '&start_time=' + \
str(self._start_time_iso) + '&end_time=' +\
str(end_time_iso) + '&period=100000'
self.assertRaises(exceptions.Conflict,
self.monasca_client.list_statistics,
query_parms)
return
time.sleep(constants.RETRY_WAIT_SECS)
self._check_timeout(i, constants.MAX_RETRIES, elements, 3)
开发者ID:jobrs,项目名称:monasca-api,代码行数:32,代码来源:test_statistics.py
示例19: _create_alarms_for_test_alarms
def _create_alarms_for_test_alarms(self, num):
metric_name = data_utils.rand_name('name')
key = data_utils.rand_name('key')
value = data_utils.rand_name('value')
alarm_definition_ids = []
for i in xrange(num):
# create an alarm definition
expression = "max(" + metric_name + ") > 0"
name = data_utils.rand_name('name-1')
alarm_definition = helpers.create_alarm_definition(
name=name, expression=expression)
resp, response_body = self.monasca_client.create_alarm_definitions(
alarm_definition)
alarm_definition_ids.append(response_body['id'])
expected_metric = helpers.create_metric(name=metric_name,
dimensions={key: value})
# create some metrics
for j in xrange(num):
for i in xrange(constants.MAX_RETRIES):
self.monasca_client.create_metrics(expected_metric)
time.sleep(constants.RETRY_WAIT_SECS)
query_param = '?alarm_definition_id=' + \
str(alarm_definition_ids[j])
resp, response_body = self.monasca_client.list_alarms(
query_param)
elements = response_body['elements']
if len(elements) >= 1:
break
return alarm_definition_ids, expected_metric
开发者ID:skydiator,项目名称:monasca-api,代码行数:29,代码来源:test_alarms.py
示例20: test_create_metric_with_value_meta_exceeds_max_length
def test_create_metric_with_value_meta_exceeds_max_length(self):
value_meta_name = "x"
long_value_meta_value = "y" * constants.MAX_VALUE_META_TOTAL_LENGTH
value_meta_dict = {value_meta_name: long_value_meta_value}
metric = helpers.create_metric(name='name', value_meta=value_meta_dict)
self.assertRaises(exceptions.UnprocessableEntity,
self.monasca_client.create_metrics,
metric)
开发者ID:jobrs,项目名称:monasca-api,代码行数:8,代码来源:test_metrics.py
注:本文中的monasca_tempest_tests.tests.api.helpers.create_metric函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论