Exemple #1
0
def startRelaying(servers, rulesFile):
  assert not RelayServers, "Relaying already started"
  loadRules(rulesFile)

  for server in servers:
    if ':' in server:
      host, port = server.split(':', 1)
      port = int(port)
    else:
      host, port = server, 2004 # default cache pickle listener port

    factory = MetricSenderFactory(host, port)
    RelayServers.append(factory) # each factory represents a cache server

    reactor.connectTCP(host, port, factory)

  RelayServers.sort(key=lambda f: f.remoteAddr) # normalize the order
Exemple #2
0
def createRelayService(config):
    from carbon.log import msg
    from carbon.conf import settings
    from carbon.events import metricReceived
    from carbon.hashing import setDestinationHosts
    from carbon.relay import createClientConnections, relay
    from carbon.rules import loadRules, allDestinationServers, parseHostList

    root_service = createBaseService(config)

    # Configure application components
    metricReceived.installHandler(relay)

    if settings["RELAY_METHOD"] == "rules":
        loadRules(settings["relay-rules"])
        createClientConnections(allDestinationServers())
    elif settings["RELAY_METHOD"] == "consistent-hashing":
        hosts = parseHostList(settings["CH_HOST_LIST"])
        msg('consistent-hashing hosts = %s' % str(hosts))
        setDestinationHosts(hosts)
        createClientConnections(hosts)

    return root_service
Exemple #3
0
  pidfile.close()

  def shutdown():
    if os.path.exists(options.pidfile):
      os.unlink(options.pidfile)

  atexit.register(shutdown)


# Configure application components
metricReceived.installHandler(relay)
startListener(settings.LINE_RECEIVER_INTERFACE, settings.LINE_RECEIVER_PORT, MetricLineReceiver)
startListener(settings.PICKLE_RECEIVER_INTERFACE, settings.PICKLE_RECEIVER_PORT, MetricPickleReceiver)

if settings.RELAY_METHOD == 'rules':
  loadRules(options.rules)
  createClientConnections( allDestinationServers() )
elif settings.RELAY_METHOD == 'consistent-hashing':
  hosts = parseHostList(settings.CH_HOST_LIST)
  msg('consistent-hashing hosts = %s' % str(hosts))
  setDestinationHosts(hosts)
  createClientConnections(hosts)

startRecording()


# Run the twisted reactor
if options.profile:
  import cProfile

  if exists(options.profile):
    def shutdown():
        if os.path.exists(options.pidfile):
            os.unlink(options.pidfile)

    atexit.register(shutdown)

# Configure application components
metricReceived.installHandler(relay)
startListener(settings.LINE_RECEIVER_INTERFACE, settings.LINE_RECEIVER_PORT,
              MetricLineReceiver)
startListener(settings.PICKLE_RECEIVER_INTERFACE,
              settings.PICKLE_RECEIVER_PORT, MetricPickleReceiver)

if settings.RELAY_METHOD == 'rules':
    loadRules(options.rules)
    createClientConnections(allDestinationServers())
elif settings.RELAY_METHOD == 'consistent-hashing':
    hosts = parseHostList(settings.CH_HOST_LIST)
    msg('consistent-hashing hosts = %s' % str(hosts))
    setDestinationHosts(hosts)
    createClientConnections(hosts)

startRecording()

# Run the twisted reactor
if options.profile:
    import cProfile

    if exists(options.profile):
        os.unlink(options.profile)