當前位置: 首頁>>代碼示例>>Python>>正文


Python rewrite.RewriteRuleManager類代碼示例

本文整理匯總了Python中carbon.rewrite.RewriteRuleManager的典型用法代碼示例。如果您正苦於以下問題:Python RewriteRuleManager類的具體用法?Python RewriteRuleManager怎麽用?Python RewriteRuleManager使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了RewriteRuleManager類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: process

  def process(self, metric, datapoint):
    increment('datapointsReceived')

    for rule in RewriteRuleManager.rules(PRE):
      metric = rule.apply(metric)

    aggregate_metrics = set()

    for rule in RuleManager.rules:
      aggregate_metric = rule.get_aggregate_metric(metric)

      if aggregate_metric is None:
        continue
      else:
        aggregate_metrics.add(aggregate_metric)

      values_buffer = BufferManager.get_buffer(aggregate_metric)

      if not values_buffer.configured:
        values_buffer.configure_aggregation(rule.frequency, rule.aggregation_func)

      values_buffer.input(datapoint)

    for rule in RewriteRuleManager.rules(POST):
      metric = rule.apply(metric)

    if metric not in aggregate_metrics:
      yield (metric, datapoint)
開發者ID:Akulatraxas,項目名稱:carbon,代碼行數:28,代碼來源:processor.py

示例2: process

  def process(self, metric, datapoint):
    increment('datapointsReceived')

    for rule in RewriteRuleManager.rules(PRE):
      metric = rule.apply(metric)

    aggregate_metrics = set()

    for rule in RuleManager.rules:
      aggregate_metric = rule.get_aggregate_metric(metric)

      if aggregate_metric is None:
        continue
      else:
        aggregate_metrics.add(aggregate_metric)

      values_buffer = BufferManager.get_buffer(aggregate_metric)

      if not values_buffer.configured:
        values_buffer.configure_aggregation(rule.frequency, rule.aggregation_func)

      values_buffer.input(datapoint)

    for rule in RewriteRuleManager.rules(POST):
      metric = rule.apply(metric)

    if settings.FORWARD_ALL and metric not in aggregate_metrics:
      if settings.LOG_AGGREGATOR_MISSES and len(aggregate_metrics) == 0:
        log.msg(
          "Couldn't match metric %s with any aggregation rule. Passing on un-aggregated." % metric)
      yield (metric, datapoint)
開發者ID:NixM0nk3y,項目名稱:carbon,代碼行數:31,代碼來源:processor.py

示例3: createAggregatorService

def createAggregatorService(config):
    from carbon.aggregator import receiver
    from carbon.aggregator.rules import RuleManager
    from carbon.routers import ConsistentHashingRouter
    from carbon.client import CarbonClientManager
    from carbon.rewrite import RewriteRuleManager
    from carbon.conf import settings
    from carbon import events

    root_service = createBaseService(config)

    # Configure application components
    router = ConsistentHashingRouter()
    client_manager = CarbonClientManager(router)
    client_manager.setServiceParent(root_service)

    events.metricReceived.addHandler(receiver.process)
    events.metricGenerated.addHandler(client_manager.sendDatapoint)

    RuleManager.read_from(settings["aggregation-rules"])
    if exists(settings["rewrite-rules"]):
        RewriteRuleManager.read_from(settings["rewrite-rules"])

    if not settings.DESTINATIONS:
      raise CarbonConfigException("Required setting DESTINATIONS is missing from carbon.conf")

    for destination in util.parseDestinations(settings.DESTINATIONS):
      client_manager.startClient(destination)

    return root_service
開發者ID:laiwei,項目名稱:carbon,代碼行數:30,代碼來源:service.py

示例4: test_read_clears_if_no_file

  def test_read_clears_if_no_file(self):
    import carbon.rewrite
    RewriteRuleManager.rules_file = 'foo.conf'

    with patch.object(carbon.rewrite, 'exists', Mock(return_value=False)):
      with patch.object(RewriteRuleManager, 'clear') as clear_mock:
        RewriteRuleManager.read_rules()
        clear_mock.assert_called_once_with()
開發者ID:Akulatraxas,項目名稱:carbon,代碼行數:8,代碼來源:test_rewrite.py

示例5: test_read_records_mtime

  def test_read_records_mtime(self):
    import carbon.rewrite
    RewriteRuleManager.rules_file = 'foo.conf'

    with patch.object(carbon.rewrite, 'open', mock_open(), create=True):
      with patch.object(carbon.rewrite, 'exists', Mock(return_value=True)):
        with patch.object(carbon.rewrite, 'getmtime', Mock(return_value=1234)):
          RewriteRuleManager.read_rules()
    self.assertEqual(1234, RewriteRuleManager.rules_last_read)
開發者ID:Akulatraxas,項目名稱:carbon,代碼行數:9,代碼來源:test_rewrite.py

示例6: test_read_opens_file_if_mtime_newer

  def test_read_opens_file_if_mtime_newer(self):
    import carbon.rewrite
    RewriteRuleManager.rules_last_read = 1234
    RewriteRuleManager.rules_file = 'foo.conf'

    with patch.object(carbon.rewrite, 'open', mock_open(), create=True) as open_mock:
      with patch.object(carbon.rewrite, 'exists', Mock(return_value=True)):
        with patch.object(carbon.rewrite, 'getmtime', Mock(return_value=5678)):
          RewriteRuleManager.read_rules()
          self.assertTrue(open_mock.called)
開發者ID:Akulatraxas,項目名稱:carbon,代碼行數:10,代碼來源:test_rewrite.py

示例7: test_comments_ignored

  def test_comments_ignored(self):
    import carbon.rewrite

    open_mock = Mock(return_value=iter(self.commented_config.splitlines()))
    RewriteRuleManager.rules_file = 'foo.conf'

    with patch.object(carbon.rewrite, 'open', open_mock, create=True):
      with patch.object(carbon.rewrite, 'exists', Mock(return_value=True)):
        with patch.object(carbon.rewrite, 'getmtime', Mock(return_value=1234)):
          RewriteRuleManager.read_rules()
    self.assertEqual(1, len(RewriteRuleManager.rules('pre')))
開發者ID:Akulatraxas,項目名稱:carbon,代碼行數:11,代碼來源:test_rewrite.py

示例8: test_section_parsed_into_ruleset

  def test_section_parsed_into_ruleset(self):
    import carbon.rewrite

    open_mock = Mock(return_value=iter(self.sample_config.splitlines()))
    RewriteRuleManager.rules_file = 'foo.conf'

    with patch.object(carbon.rewrite, 'open', open_mock, create=True):
      with patch.object(carbon.rewrite, 'exists', Mock(return_value=True)):
        with patch.object(carbon.rewrite, 'getmtime', Mock(return_value=1234)):
          RewriteRuleManager.read_rules()
    self.assertTrue('pre' in RewriteRuleManager.rulesets)
開發者ID:Akulatraxas,項目名稱:carbon,代碼行數:11,代碼來源:test_rewrite.py

示例9: test_read_doesnt_open_file_if_mtime_unchanged

  def test_read_doesnt_open_file_if_mtime_unchanged(self):
    import carbon.rewrite
    mtime = 1234
    RewriteRuleManager.rules_last_read = mtime
    RewriteRuleManager.rules_file = 'foo.conf'

    with patch.object(carbon.rewrite, 'open', mock_open(), create=True) as open_mock:
      with patch.object(carbon.rewrite, 'exists', Mock(return_value=True)):
        with patch.object(carbon.rewrite, 'getmtime', Mock(return_value=1234)):
          RewriteRuleManager.read_rules()
          self.assertFalse(open_mock.called)
開發者ID:Akulatraxas,項目名稱:carbon,代碼行數:11,代碼來源:test_rewrite.py

示例10: test_rules_unchanged_if_mtime_unchanged

  def test_rules_unchanged_if_mtime_unchanged(self):
    import carbon.rewrite
    mtime = 1234
    rulesets = {'pre': [Mock(RewriteRule)]}
    RewriteRuleManager.rules_last_read = mtime
    RewriteRuleManager.rulesets.update(rulesets)
    RewriteRuleManager.rules_file = 'foo.conf'

    with patch.object(carbon.rewrite, 'exists', Mock(return_value=True)):
      with patch.object(carbon.rewrite, 'getmtime', Mock(return_value=mtime)):
        RewriteRuleManager.read_rules()

    self.assertEqual(rulesets, RewriteRuleManager.rulesets)
開發者ID:Akulatraxas,項目名稱:carbon,代碼行數:13,代碼來源:test_rewrite.py

示例11: createAggregatorService

def createAggregatorService(config):
    from carbon.events import metricReceived
    from carbon.aggregator import receiver
    from carbon.aggregator.rules import RuleManager
    from carbon.aggregator import client
    from carbon.rewrite import RewriteRuleManager
    from carbon.conf import settings

    root_service = createBaseService(config)

    # Configure application components
    metricReceived.installHandler(receiver.process)
    RuleManager.read_from(settings["aggregation-rules"])
    if exists(settings["rewrite-rules"]):
        RewriteRuleManager.read_from(settings["rewrite-rules"])

    client.connect(settings["DESTINATION_HOST"],
                   int(settings["DESTINATION_PORT"]))

    return root_service
開發者ID:mtodd,項目名稱:graphite,代碼行數:20,代碼來源:service.py

示例12: test_request_for_nonexistent_rules_returns_iterable

 def test_request_for_nonexistent_rules_returns_iterable(self):
   try:
     iter(RewriteRuleManager.rules('foo'))
   except TypeError:
     self.fail("RewriteRuleManager.rules() returned a non-iterable type")
開發者ID:Akulatraxas,項目名稱:carbon,代碼行數:5,代碼來源:test_rewrite.py

示例13: tearDown

 def tearDown(self):
   instrumentation.stats.clear()
   BufferManager.clear()
   RuleManager.clear()
   RewriteRuleManager.clear()
開發者ID:Akulatraxas,項目名稱:carbon,代碼行數:5,代碼來源:test_aggregator_processor.py

示例14: setupRewriterProcessor

def setupRewriterProcessor(root_service, settings):
  from carbon.rewrite import RewriteRuleManager

  rewrite_rules_path = settings["rewrite-rules"]
  RewriteRuleManager.read_from(rewrite_rules_path)
開發者ID:zhpn,項目名稱:carbon,代碼行數:5,代碼來源:service.py

示例15: tearDown

 def tearDown(self):
   RewriteRuleManager.rules_file = None
   RewriteRuleManager.rules_last_read = 0.0
   RewriteRuleManager.clear()
開發者ID:Akulatraxas,項目名稱:carbon,代碼行數:4,代碼來源:test_rewrite.py


注:本文中的carbon.rewrite.RewriteRuleManager類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。