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


Python metric.Metrics类代码示例

本文整理汇总了Python中apache_beam.metrics.metric.Metrics的典型用法代码示例。如果您正苦于以下问题:Python Metrics类的具体用法?Python Metrics怎么用?Python Metrics使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: test_create_counter_distribution

  def test_create_counter_distribution(self):
    sampler = statesampler.StateSampler('', counters.CounterFactory())
    statesampler.set_current_tracker(sampler)
    state1 = sampler.scoped_state('mystep', 'myState',
                                  metrics_container=MetricsContainer('mystep'))
    sampler.start()
    with state1:
      counter_ns = 'aCounterNamespace'
      distro_ns = 'aDistributionNamespace'
      name = 'a_name'
      counter = Metrics.counter(counter_ns, name)
      distro = Metrics.distribution(distro_ns, name)
      counter.inc(10)
      counter.dec(3)
      distro.update(10)
      distro.update(2)
      self.assertTrue(isinstance(counter, Metrics.DelegatingCounter))
      self.assertTrue(isinstance(distro, Metrics.DelegatingDistribution))

      del distro
      del counter

      container = MetricsEnvironment.current_container()
      self.assertEqual(
          container.counters[MetricName(counter_ns, name)].get_cumulative(),
          7)
      self.assertEqual(
          container.distributions[MetricName(distro_ns, name)].get_cumulative(),
          DistributionData(12, 2, 2, 10))
    sampler.stop()
开发者ID:JavierRoger,项目名称:beam,代码行数:30,代码来源:metric_test.py

示例2: test_create_counter_distribution

  def test_create_counter_distribution(self):
    MetricsEnvironment.set_current_container(MetricsContainer('mystep'))
    counter_ns = 'aCounterNamespace'
    distro_ns = 'aDistributionNamespace'
    gauge_ns = 'aGaugeNamespace'
    name = 'a_name'
    counter = Metrics.counter(counter_ns, name)
    distro = Metrics.distribution(distro_ns, name)
    gauge = Metrics.gauge(gauge_ns, name)
    counter.inc(10)
    counter.dec(3)
    distro.update(10)
    distro.update(2)
    gauge.set(10)
    self.assertTrue(isinstance(counter, Metrics.DelegatingCounter))
    self.assertTrue(isinstance(distro, Metrics.DelegatingDistribution))
    self.assertTrue(isinstance(gauge, Metrics.DelegatingGauge))

    del distro
    del counter
    del gauge

    container = MetricsEnvironment.current_container()
    self.assertEqual(
        container.counters[MetricName(counter_ns, name)].get_cumulative(),
        7)
    self.assertEqual(
        container.distributions[MetricName(distro_ns, name)].get_cumulative(),
        DistributionData(12, 2, 2, 10))
    self.assertEqual(
        container.gauges[MetricName(gauge_ns, name)].get_cumulative().value,
        10)
开发者ID:aljoscha,项目名称:incubator-beam,代码行数:32,代码来源:metric_test.py

示例3: process

 def process(self, element):
   gauge = Metrics.gauge(self.__class__, 'latest_element')
   gauge.set(element)
   count = Metrics.counter(self.__class__, 'elements')
   count.inc()
   distro = Metrics.distribution(self.__class__, 'element_dist')
   distro.update(element)
   return [element]
开发者ID:charlesccychen,项目名称:incubator-beam,代码行数:8,代码来源:direct_runner_test.py

示例4: __init__

 def __init__(self, project, fixed_batch_size=None):
   """
   Args:
     project: str, the cloud project id.
     fixed_batch_size: int, for testing only, this forces all batches of
        writes to be a fixed size, for easier unittesting.
   """
   self._project = project
   self._datastore = None
   self._fixed_batch_size = fixed_batch_size
   self._rpc_successes = Metrics.counter(
       _Mutate.DatastoreWriteFn, "datastoreRpcSuccesses")
   self._rpc_errors = Metrics.counter(
       _Mutate.DatastoreWriteFn, "datastoreRpcErrors")
开发者ID:gamars,项目名称:beam,代码行数:14,代码来源:datastoreio.py

示例5: test_run_api

 def test_run_api(self):
   my_metric = Metrics.counter('namespace', 'my_metric')
   runner = DirectRunner()
   result = runner.run(
       beam.Create([1, 10, 100]) | beam.Map(lambda x: my_metric.inc(x)))
   result.wait_until_finish()
   # Use counters to assert the pipeline actually ran.
   my_metric_value = result.metrics().query()['counters'][0].committed
   self.assertEqual(my_metric_value, 111)
开发者ID:aaltay,项目名称:incubator-beam,代码行数:9,代码来源:runner_test.py

示例6: __init__

 def __init__(self, project, fixed_batch_size=None):
   """
   Args:
     project: str, the cloud project id.
     fixed_batch_size: int, for testing only, this forces all batches of
        writes to be a fixed size, for easier unittesting.
   """
   self._project = project
   self._datastore = None
   self._fixed_batch_size = fixed_batch_size
   self._rpc_successes = Metrics.counter(
       _Mutate.DatastoreWriteFn, "datastoreRpcSuccesses")
   self._rpc_errors = Metrics.counter(
       _Mutate.DatastoreWriteFn, "datastoreRpcErrors")
   self._throttled_secs = Metrics.counter(
       _Mutate.DatastoreWriteFn, "cumulativeThrottlingSeconds")
   self._throttler = AdaptiveThrottler(window_ms=120000, bucket_ms=1000,
                                       overload_ratio=1.25)
开发者ID:lukecwik,项目名称:incubator-beam,代码行数:18,代码来源:datastoreio.py

示例7: test_scoped_container

  def test_scoped_container(self):
    c1 = MetricsContainer('mystep')
    c2 = MetricsContainer('myinternalstep')
    with ScopedMetricsContainer(c1):
      self.assertEqual(c1, MetricsEnvironment.current_container())
      counter = Metrics.counter('ns', 'name')
      counter.inc(2)

      with ScopedMetricsContainer(c2):
        self.assertEqual(c2, MetricsEnvironment.current_container())
        counter = Metrics.counter('ns', 'name')
        counter.inc(3)
        self.assertEqual(
            c2.get_cumulative().counters.items(),
            [(MetricKey('myinternalstep', MetricName('ns', 'name')), 3)])

      self.assertEqual(c1, MetricsEnvironment.current_container())
      counter = Metrics.counter('ns', 'name')
      counter.inc(4)
      self.assertEqual(
          c1.get_cumulative().counters.items(),
          [(MetricKey('mystep', MetricName('ns', 'name')), 6)])
开发者ID:eljefe6a,项目名称:incubator-beam,代码行数:22,代码来源:execution_test.py

示例8: test_uses_right_container

  def test_uses_right_container(self):
    c1 = MetricsContainer('step1')
    c2 = MetricsContainer('step2')
    counter = Metrics.counter('ns', 'name')
    MetricsEnvironment.set_current_container(c1)
    counter.inc()
    MetricsEnvironment.set_current_container(c2)
    counter.inc(3)
    MetricsEnvironment.unset_current_container()

    self.assertEqual(
        c1.get_cumulative().counters.items(),
        [(MetricKey('step1', MetricName('ns', 'name')), 1)])

    self.assertEqual(
        c2.get_cumulative().counters.items(),
        [(MetricKey('step2', MetricName('ns', 'name')), 3)])
开发者ID:eljefe6a,项目名称:incubator-beam,代码行数:17,代码来源:execution_test.py

示例9: start_bundle

 def start_bundle(self):
   count = Metrics.counter(self.__class__, 'bundles')
   count.inc()
开发者ID:jasonkuster,项目名称:incubator-beam,代码行数:3,代码来源:runner_test.py

示例10: __init__

 def __init__(self):
   super(ParseGameEventFn, self).__init__()
   self.num_parse_errors = Metrics.counter(self.__class__, 'num_parse_errors')
开发者ID:dpmills,项目名称:incubator-beam,代码行数:3,代码来源:leader_board.py

示例11: test_get_namespace_error

 def test_get_namespace_error(self):
   with self.assertRaises(ValueError):
     Metrics.get_namespace(object())
开发者ID:aaltay,项目名称:incubator-beam,代码行数:3,代码来源:metric_test.py

示例12: test_get_namespace_class

  def test_get_namespace_class(self):
    class MyClass(object):
      pass

    self.assertEqual('{}.{}'.format(MyClass.__module__, MyClass.__name__),
                     Metrics.get_namespace(MyClass))
开发者ID:aaltay,项目名称:incubator-beam,代码行数:6,代码来源:metric_test.py

示例13: test_distribution_empty_namespace

 def test_distribution_empty_namespace(self):
   with self.assertRaises(ValueError):
     Metrics.distribution("", "names")
开发者ID:aaltay,项目名称:incubator-beam,代码行数:3,代码来源:metric_test.py

示例14: test_counter_empty_namespace

 def test_counter_empty_namespace(self):
   with self.assertRaises(ValueError):
     Metrics.counter("", "names")
开发者ID:aaltay,项目名称:incubator-beam,代码行数:3,代码来源:metric_test.py

示例15: finish_bundle

 def finish_bundle(self):
   count = Metrics.counter(self.__class__, 'finished_bundles')
   count.inc()
开发者ID:jasonkuster,项目名称:incubator-beam,代码行数:3,代码来源:runner_test.py


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