def createRelayService(config): from carbon.routers import RelayRulesRouter, ConsistentHashingRouter, AggregatedConsistentHashingRouter from carbon.client import CarbonClientManager from carbon.conf import settings from carbon import events root_service = createBaseService(config) # Configure application components if settings.RELAY_METHOD == 'rules': router = RelayRulesRouter(settings["relay-rules"]) elif settings.RELAY_METHOD == 'consistent-hashing': router = ConsistentHashingRouter( settings.REPLICATION_FACTOR, diverse_replicas=settings.DIVERSE_REPLICAS) elif settings.RELAY_METHOD == 'aggregated-consistent-hashing': from carbon.aggregator.rules import RuleManager RuleManager.read_from(settings["aggregation-rules"]) router = AggregatedConsistentHashingRouter(RuleManager, settings.REPLICATION_FACTOR) client_manager = CarbonClientManager(router) client_manager.setServiceParent(root_service) events.metricReceived.addHandler(client_manager.sendDatapoint) events.metricGenerated.addHandler(client_manager.sendDatapoint) 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
def setupRelayProcessor(root_service, settings): from carbon.routers import AggregatedConsistentHashingRouter, \ ConsistentHashingRouter, RelayRulesRouter from carbon.client import CarbonClientManager if settings.RELAY_METHOD == 'consistent-hashing': router = ConsistentHashingRouter( settings.REPLICATION_FACTOR, diverse_replicas=settings.DIVERSE_REPLICAS) elif settings.RELAY_METHOD == 'aggregated-consistent-hashing': from carbon.aggregator.rules import RuleManager aggregation_rules_path = settings["aggregation-rules"] RuleManager.read_from(aggregation_rules_path) router = AggregatedConsistentHashingRouter( RuleManager, settings.REPLICATION_FACTOR, diverse_replicas=settings.DIVERSE_REPLICAS) elif settings.RELAY_METHOD == 'rules': router = RelayRulesRouter(settings["relay-rules"]) state.client_manager = CarbonClientManager(router) state.client_manager.setServiceParent(root_service) for destination in util.parseDestinations(settings.DESTINATIONS): state.client_manager.startClient(destination)
instance = parts[2] else: instance = None destinations.append((host, port, instance)) if options.debug: log.logToStdout() log.setDebugEnabled(True) defer.setDebugging(True) if options.routing == 'consistent-hashing': router = ConsistentHashingRouter(options.replication, diverse_replicas=options.diverse_replicas) elif options.routing == 'relay': if exists(options.relayrules): router = RelayRulesRouter(options.relayrules) else: print("relay rules file %s does not exist" % options.relayrules) raise SystemExit(1) client_manager = CarbonClientManager(router) reactor.callWhenRunning(client_manager.startService) if options.keyfunc: router.setKeyFunctionFromModule(options.keyfunc) firstConnectAttempts = [ client_manager.startClient(dest) for dest in destinations ] firstConnectsAttempted = defer.DeferredList(firstConnectAttempts)