Exemple #1
0
def setupReceivers(root_service, settings):
  from carbon.protocols import MetricLineReceiver, MetricPickleReceiver, MetricDatagramReceiver

  for protocol, interface, port in [
      (MetricLineReceiver, settings.LINE_RECEIVER_INTERFACE, settings.LINE_RECEIVER_PORT),
      (MetricPickleReceiver, settings.PICKLE_RECEIVER_INTERFACE, settings.PICKLE_RECEIVER_PORT)
    ]:
    if port:
      factory = ServerFactory()
      factory.protocol = protocol
      service = TCPServer(port, factory, interface=interface)
      service.setServiceParent(root_service)

  if settings.ENABLE_UDP_LISTENER:
      service = UDPServer(int(settings.UDP_RECEIVER_PORT),
                          MetricDatagramReceiver(),
                          interface=settings.UDP_RECEIVER_INTERFACE)
      service.setServiceParent(root_service)

  if settings.ENABLE_AMQP:
    from carbon import amqp_listener
    amqp_host = settings.AMQP_HOST
    amqp_port = settings.AMQP_PORT
    amqp_user = settings.AMQP_USER
    amqp_password = settings.AMQP_PASSWORD
    amqp_verbose = settings.AMQP_VERBOSE
    amqp_vhost = settings.AMQP_VHOST
    amqp_spec = settings.AMQP_SPEC
    amqp_exchange_name = settings.AMQP_EXCHANGE

    factory = amqp_listener.createAMQPListener(
      amqp_user,
      amqp_password,
      vhost=amqp_vhost,
      spec=amqp_spec,
      exchange_name=amqp_exchange_name,
      verbose=amqp_verbose)
    service = TCPClient(amqp_host, amqp_port, factory)
    service.setServiceParent(root_service)

  if settings.ENABLE_MANHOLE:
    from carbon import manhole

    # Configure application components
    if settings.RELAY_METHOD == 'rules':
      router = RelayRulesRouter(settings["relay-rules"])
    elif settings.RELAY_METHOD == 'consistent-hashing':
      router = ConsistentHashingRouter(settings.REPLICATION_FACTOR)
    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)
    elif settings.RELAY_METHOD == 'remove-node-consistent-hashing':
      router = RemoveNodeConsistentHashingRouter(settings.REPLICATION_FACTOR, settings.REMOVE_NODE_INDEX)
    factory = manhole.createManholeListener()
    service = TCPServer(
      settings.MANHOLE_PORT,
      factory,
      interface=settings.MANHOLE_INTERFACE)
    service.setServiceParent(root_service)
Exemple #2
0
def setupReceivers(root_service, settings):
    from carbon.protocols import MetricLineReceiver, MetricPickleReceiver, MetricDatagramReceiver

    for protocol, interface, port in [
        (MetricLineReceiver, settings.LINE_RECEIVER_INTERFACE,
         settings.LINE_RECEIVER_PORT),
        (MetricPickleReceiver, settings.PICKLE_RECEIVER_INTERFACE,
         settings.PICKLE_RECEIVER_PORT)
    ]:
        if port:
            factory = ServerFactory()
            factory.protocol = protocol
            service = TCPServer(port, factory, interface=interface)
            service.setServiceParent(root_service)

    if settings.ENABLE_UDP_LISTENER:
        service = UDPServer(int(settings.UDP_RECEIVER_PORT),
                            MetricDatagramReceiver(),
                            interface=settings.UDP_RECEIVER_INTERFACE)
        service.setServiceParent(root_service)

    if settings.ENABLE_AMQP:
        from carbon import amqp_listener
        amqp_host = settings.AMQP_HOST
        amqp_port = settings.AMQP_PORT
        amqp_user = settings.AMQP_USER
        amqp_password = settings.AMQP_PASSWORD
        amqp_verbose = settings.AMQP_VERBOSE
        amqp_vhost = settings.AMQP_VHOST
        amqp_spec = settings.AMQP_SPEC
        amqp_exchange_name = settings.AMQP_EXCHANGE

        factory = amqp_listener.createAMQPListener(
            amqp_user,
            amqp_password,
            vhost=amqp_vhost,
            spec=amqp_spec,
            exchange_name=amqp_exchange_name,
            verbose=amqp_verbose)
        service = TCPClient(amqp_host, amqp_port, factory)
        service.setServiceParent(root_service)

    if settings.ENABLE_MANHOLE:
        from carbon import manhole

        factory = manhole.createManholeListener()
        service = TCPServer(settings.MANHOLE_PORT,
                            factory,
                            interface=settings.MANHOLE_INTERFACE)
        service.setServiceParent(root_service)
Exemple #3
0
def setupReceivers(root_service, settings):
  from carbon.protocols import MetricLineReceiver, MetricPickleReceiver, MetricDatagramReceiver

  for protocol, interface, port in [
      (MetricLineReceiver, settings.LINE_RECEIVER_INTERFACE, settings.LINE_RECEIVER_PORT),
      (MetricPickleReceiver, settings.PICKLE_RECEIVER_INTERFACE, settings.PICKLE_RECEIVER_PORT)
    ]:
    if port:
      factory = ServerFactory()
      factory.protocol = protocol
      service = TCPServer(port, factory, interface=interface)
      service.setServiceParent(root_service)

  if settings.ENABLE_UDP_LISTENER:
      service = UDPServer(int(settings.UDP_RECEIVER_PORT),
                          MetricDatagramReceiver(),
                          interface=settings.UDP_RECEIVER_INTERFACE)
      service.setServiceParent(root_service)

  if settings.ENABLE_AMQP:
    from carbon import amqp_listener
    amqp_host = settings.AMQP_HOST
    amqp_port = settings.AMQP_PORT
    amqp_user = settings.AMQP_USER
    amqp_password = settings.AMQP_PASSWORD
    amqp_verbose = settings.AMQP_VERBOSE
    amqp_vhost = settings.AMQP_VHOST
    amqp_spec = settings.AMQP_SPEC
    amqp_exchange_name = settings.AMQP_EXCHANGE

    factory = amqp_listener.createAMQPListener(
      amqp_user,
      amqp_password,
      vhost=amqp_vhost,
      spec=amqp_spec,
      exchange_name=amqp_exchange_name,
      verbose=amqp_verbose)
    service = TCPClient(amqp_host, amqp_port, factory)
    service.setServiceParent(root_service)

  if settings.ENABLE_MANHOLE:
    from carbon import manhole

    factory = manhole.createManholeListener()
    service = TCPServer(
      settings.MANHOLE_PORT,
      factory,
      interface=settings.MANHOLE_INTERFACE)
    service.setServiceParent(root_service)
def createBaseService(config):
    from carbon.conf import settings

    from carbon.protocols import (MetricLineReceiver, MetricPickleReceiver,
                                  MetricDatagramReceiver)

    root_service = CarbonRootService()
    root_service.setName(settings.program)

    use_amqp = settings.get("ENABLE_AMQP", False)
    if use_amqp:
        from carbon import amqp_listener

        amqp_host = settings.get("AMQP_HOST", "localhost")
        amqp_port = settings.get("AMQP_PORT", 5672)
        amqp_user = settings.get("AMQP_USER", "guest")
        amqp_password = settings.get("AMQP_PASSWORD", "guest")
        amqp_verbose = settings.get("AMQP_VERBOSE", False)
        amqp_vhost = settings.get("AMQP_VHOST", "/")
        amqp_spec = settings.get("AMQP_SPEC", None)
        amqp_exchange_name = settings.get("AMQP_EXCHANGE", "graphite")

    for interface, port, backlog, protocol in (
        (settings.LINE_RECEIVER_INTERFACE, settings.LINE_RECEIVER_PORT,
         settings.LINE_RECEIVER_BACKLOG, MetricLineReceiver),
        (settings.PICKLE_RECEIVER_INTERFACE, settings.PICKLE_RECEIVER_PORT,
         settings.PICKLE_RECEIVER_BACKLOG, MetricPickleReceiver)):
        if port:
            factory = ServerFactory()
            factory.protocol = protocol
            service = TCPServer(int(port),
                                factory,
                                interface=interface,
                                backlog=backlog)
            service.setServiceParent(root_service)

    if settings.ENABLE_UDP_LISTENER:
        service = UDPServer(int(settings.UDP_RECEIVER_PORT),
                            MetricDatagramReceiver(),
                            interface=settings.UDP_RECEIVER_INTERFACE)
        service.setServiceParent(root_service)

    if use_amqp:
        factory = amqp_listener.createAMQPListener(
            amqp_user,
            amqp_password,
            vhost=amqp_vhost,
            spec=amqp_spec,
            exchange_name=amqp_exchange_name,
            verbose=amqp_verbose)
        service = TCPClient(amqp_host, int(amqp_port), factory)
        service.setServiceParent(root_service)

    if settings.ENABLE_MANHOLE:
        from carbon import manhole

        factory = manhole.createManholeListener()
        service = TCPServer(int(settings.MANHOLE_PORT),
                            factory,
                            interface=settings.MANHOLE_INTERFACE)
        service.setServiceParent(root_service)

    if settings.USE_WHITELIST:
        from carbon.regexlist import WhiteList, BlackList
        WhiteList.read_from(settings["whitelist"])
        BlackList.read_from(settings["blacklist"])

    # Instantiate an instrumentation service that will record metrics about
    # this service.
    from carbon.instrumentation import InstrumentationService

    service = InstrumentationService()
    service.setServiceParent(root_service)

    return root_service
Exemple #5
0
def createBaseService(config):
    from carbon.conf import settings
    from carbon.protocols import (MetricLineReceiver, MetricPickleReceiver,
                                  MetricDatagramReceiver, CmdLineReceiver)

    root_service = CarbonRootService()
    root_service.setName(settings.program)

    use_amqp = settings.get("ENABLE_AMQP", False)
    if use_amqp:
        from carbon import amqp_listener

        amqp_host = settings.get("AMQP_HOST", "localhost")
        amqp_port = settings.get("AMQP_PORT", 5672)
        amqp_user = settings.get("AMQP_USER", "guest")
        amqp_password = settings.get("AMQP_PASSWORD", "guest")
        amqp_verbose  = settings.get("AMQP_VERBOSE", False)
        amqp_vhost    = settings.get("AMQP_VHOST", "/")
        amqp_spec     = settings.get("AMQP_SPEC", None)
        amqp_exchange_name = settings.get("AMQP_EXCHANGE", "graphite")


    for interface, port, protocol in ((settings.LINE_RECEIVER_INTERFACE,
                                       settings.LINE_RECEIVER_PORT,
                                       MetricLineReceiver),
                                      (settings.PICKLE_RECEIVER_INTERFACE,
                                       settings.PICKLE_RECEIVER_PORT,
                                       MetricPickleReceiver),
                                      (settings.CMD_LINE_RECEIVER_INTERFACE,
                                       settings.CMD_LINE_RECEIVER_PORT,
                                       CmdLineReceiver)):
        if port:
            factory = ServerFactory()
            factory.protocol = protocol
            service = TCPServer(int(port), factory, interface=interface)
            service.setServiceParent(root_service)

    if settings.ENABLE_UDP_LISTENER:
        service = UDPServer(int(settings.UDP_RECEIVER_PORT),
                            MetricDatagramReceiver(),
                            interface=settings.UDP_RECEIVER_INTERFACE)
        service.setServiceParent(root_service)

    if use_amqp:
        factory = amqp_listener.createAMQPListener(
            amqp_user, amqp_password,
            vhost=amqp_vhost, spec=amqp_spec,
            exchange_name=amqp_exchange_name,
            verbose=amqp_verbose)
        service = TCPClient(amqp_host, int(amqp_port), factory)
        service.setServiceParent(root_service)

    if settings.ENABLE_MANHOLE:
        from carbon import manhole

        factory = manhole.createManholeListener()
        service = TCPServer(int(settings.MANHOLE_PORT), factory,
                            interface=settings.MANHOLE_INTERFACE)
        service.setServiceParent(root_service)

    if settings.USE_WHITELIST:
      from carbon.regexlist import WhiteList,BlackList
      WhiteList.read_from(settings["whitelist"])
      BlackList.read_from(settings["blacklist"])

    # Instantiate an instrumentation service that will record metrics about
    # this service.
    from carbon.instrumentation import InstrumentationService

    service = InstrumentationService()
    service.setServiceParent(root_service)

    return root_service