当前位置: 首页>>代码示例>>Python>>正文


Python AgentCheck.get_metrics方法代码示例

本文整理汇总了Python中monasca_agent.collector.checks.AgentCheck.get_metrics方法的典型用法代码示例。如果您正苦于以下问题:Python AgentCheck.get_metrics方法的具体用法?Python AgentCheck.get_metrics怎么用?Python AgentCheck.get_metrics使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在monasca_agent.collector.checks.AgentCheck的用法示例。


在下文中一共展示了AgentCheck.get_metrics方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: TestDynamicCheckHelper

# 需要导入模块: from monasca_agent.collector.checks import AgentCheck [as 别名]
# 或者: from monasca_agent.collector.checks.AgentCheck import get_metrics [as 别名]
class TestDynamicCheckHelper(unittest.TestCase):
    def setUp(self):
        agent_config = base_config.get_config(sections='Main')

        self._instances = [{'name': 'test',
                            'mapping': {
                                'gauges': ['stats.(MessagesAvg)'],
                                'counters': ['MessagesTotal'],
                                'dimensions': {
                                    'index': 'index',
                                    'simple_dimension': 'simple_label',
                                    'complex_dimension': {
                                        'source_key': 'complex_label',
                                        'regex': 'k8s_([._\-a-zA-Z0-9]*)_postfix'
                                    },
                                    'complex_dimension_rest': {
                                        'source_key': 'complex_label',
                                        'regex': 'k8s_([._\-a-zA-Z0-9]*_postfix)'
                                    }
                                },
                                'groups': {
                                    'testgroup': {
                                        'dimensions': {
                                            'user': 'user'
                                        },
                                        'rates': ['.*\.Responses.*', '(sec_auth_.*).stats',
                                                  '(io_service_bytes)_stats_Total']
                                    }
                                    # dimensions should be inherited from above
                                }}}]
        self.check = AgentCheck("DynCheckHelper-Teset", {}, agent_config, self._instances)  # TODO mock check
        self.helper = DynamicCheckHelper(self.check, 'dynhelper')

    def run_check(self):
        self.check.run()
        metric_dict = {"sec": {"auth": [{"user": "me", "total.stats": 10}, {"user": "you", "total.stats": 15}]},
                       "io_service_bytes": {"stats": {"Total": 10}}}
        self.helper.push_metric_dict(self._instances[0], metric_dict, group="testgroup",
                                     labels={'simple_label': 'simple_label_test',
                                             'complex_label': 'k8s_monasca-api-a8109321_postfix'}, max_depth=3)
        self.helper.push_metric(self._instances[0], metric='req.ResponsesOk', value=10.0,
                                group="testgroup",
                                labels={'simple_label': 'simple_label_test',
                                        'complex_label': 'k8s_monasca-api-a8109321_postfix'})
        self.helper.push_metric(self._instances[0], metric='stats.MessagesAvg', value=5.0,
                                labels={'simple_label': 'simple_label_test',
                                        'complex_label': 'k8s_monasca-api-a8109321_postfix'})
        self.helper.push_metric(self._instances[0], metric='MessagesTotal', value=1)
        time.sleep(1)
        self.helper.push_metric_dict(self._instances[0], metric_dict, group="testgroup",
                                     labels={'simple_label': 'simple_label_test',
                                             'complex_label': 'k8s_monasca-api-a8109321_postfix'}, max_depth=3)
        self.helper.push_metric(self._instances[0], metric='req.ResponsesOk', value=15.0,
                                group="testgroup",
                                labels={'simple_label': 'simple_label_test',
                                        'complex_label': 'k8s_monasca-api-a8109321_postfix'})
        self.helper.push_metric(self._instances[0], metric='MessagesTotal', value=100)
        metrics = self.check.get_metrics()

        return metrics

    def testMeasurements(self):
        metrics = self.run_check()
        for m in metrics:
            print "metric: {0}, dimensions: {1}".format(m['measurement']['name'], repr(m['measurement']['dimensions']))
        metric1 = sorted(filter(lambda m: m['measurement']['name'] == 'dynhelper.messages_avg', metrics))
        metric2 = sorted(filter(lambda m: m['measurement']['name'] == 'dynhelper.messages_total', metrics))
        metric3 = sorted(filter(lambda m: m['measurement']['name'] == 'dynhelper.testgroup.req_responses_ok', metrics))
        metric4 = sorted(filter(lambda m: m['measurement']['name'] == 'dynhelper.testgroup.sec_auth_total', metrics))
        self.assertTrue(len(metric1) > 0,
                        'gauge dynhelper.messages_avg missing in metric list {0}'.format(repr(metrics)))
        self.assertEqual(metric1[0]['measurement']['dimensions'],
                          {'simple_dimension': 'simple_label_test', 'complex_dimension': 'monasca-api-a8109321',
                           'complex_dimension_rest': 'monasca-api-a8109321_postfix',
                           'hostname': metric1[0]['measurement']['dimensions'].get('hostname')})
        self.assertTrue(len(metric2) > 0,
                        'rate dynhelper.messages_total missing in metric list {0}'.format(repr(metrics)))
        self.assertEqual(metric2[0]['measurement']['dimensions'],
                          {'hostname': metric2[0]['measurement']['dimensions'].get('hostname')})
        self.assertTrue(len(metric3) > 0,
                        'rate dynhelper.testgroup.req_responses_ok missing in metric list {0}'.format(repr(metrics)))
        self.assertEqual(metric3[0]['measurement']['dimensions'],
                          {'simple_dimension': 'simple_label_test', 'complex_dimension': 'monasca-api-a8109321',
                           'complex_dimension_rest': 'monasca-api-a8109321_postfix',
                           'hostname': metric3[0]['measurement']['dimensions'].get('hostname')})
        self.assertTrue(len(metric4) == 2,
                        'rate dynhelper.testgroup.sec_auth_total missing in metric list {0}'.format(repr(metrics)))
        self.assertEqual(metric4[0]['measurement']['dimensions'],
                          {'simple_dimension': 'simple_label_test', 'complex_dimension': 'monasca-api-a8109321',
                           'complex_dimension_rest': 'monasca-api-a8109321_postfix',
                           'user': 'me', 'hostname': metric4[0]['measurement']['dimensions'].get('hostname')})
        self.assertEqual(metric4[1]['measurement']['dimensions'],
                          {'simple_dimension': 'simple_label_test', 'complex_dimension': 'monasca-api-a8109321',
                           'complex_dimension_rest': 'monasca-api-a8109321_postfix',
                           'user': 'you', 'hostname': metric4[1]['measurement']['dimensions'].get('hostname')})
开发者ID:openstack,项目名称:monasca-agent,代码行数:97,代码来源:test_checks_utils.py


注:本文中的monasca_agent.collector.checks.AgentCheck.get_metrics方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。