Exemple #1
0
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
Exemple #2
0
def createCacheService(config):
    from carbon.cache import MetricCache
    from carbon.conf import settings
    from carbon.events import metricReceived
    from carbon.protocols import protocolManager
    from carbon.protocols import CacheQueryHandler

    # Configure application components
    metricReceived.installHandler(MetricCache.store)

    root_service = createBaseService(config)
    factory = protocolManager.createFactory(CacheQueryHandler)
    service = TCPServer(int(settings.CACHE_QUERY_PORT), factory,
                        interface=settings.CACHE_QUERY_INTERFACE)
    service.setServiceParent(root_service)

    # have to import this *after* settings are defined
    from carbon.writer import WriterService

    service = WriterService()
    service.setServiceParent(root_service)

    return root_service
Exemple #3
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
    daemonize()

    pidfile = open(options.pidfile, 'w')
    pidfile.write(str(os.getpid()))
    pidfile.close()

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

    atexit.register(shutdown)

    logToDir(options.logdir)

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

client.connect(settings.DESTINATION_HOST, settings.DESTINATION_PORT)
startRecording()

# Run the twisted reactor
print "%s running with pid %d" % (program, os.getpid())

if options.profile:
    import cProfile

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

    atexit.register(shutdown)

    if settings.USER:
        pwent = pwd.getpwnam(settings.USER)
        os.chown(pidfile, pwent.pw_uid, pwent.pw_gid)
        dropprivs(settings.USER)

    logToDir(logdir)

# Configure application components
metricReceived.installHandler(MetricCache.store)
startListener(settings.LINE_RECEIVER_INTERFACE, settings.LINE_RECEIVER_PORT,
              MetricLineReceiver)
startListener(settings.PICKLE_RECEIVER_INTERFACE,
              settings.PICKLE_RECEIVER_PORT, MetricPickleReceiver)
startListener(settings.CACHE_QUERY_INTERFACE, settings.CACHE_QUERY_PORT,
              CacheQueryHandler)

if use_amqp:
    amqp_listener.startReceiver(amqp_host,
                                amqp_port,
                                amqp_user,
                                amqp_password,
                                vhost=amqp_vhost,
                                spec=amqp_spec,
                                exchange_name=amqp_exchange_name,
    def shutdown():
        if os.path.exists(options.pidfile):
            os.unlink(options.pidfile)

    atexit.register(shutdown)

    if settings.USER:
        pwent = pwd.getpwnam(settings.USER)
        os.chown(options.pidfile, pwent.pw_uid, pwent.pw_gid)
        print "Dropping privileges to become the user %s" % settings.USER
        dropprivs(settings.USER)


# Configure application components
metricReceived.installHandler(MetricCache.store)
startListener(settings.LINE_RECEIVER_INTERFACE, settings.LINE_RECEIVER_PORT, MetricLineReceiver)
startListener(settings.PICKLE_RECEIVER_INTERFACE, settings.PICKLE_RECEIVER_PORT, MetricPickleReceiver)
startListener(settings.CACHE_QUERY_INTERFACE, settings.CACHE_QUERY_PORT, CacheQueryHandler)
startWriter()
startRecordingCacheMetrics()


# Run the twisted reactor
print "%s running" % program

if options.profile:
    import cProfile

    if exists(options.profile):
        os.unlink(options.profile)
Exemple #7
0
  daemonize()
  logToDir(options.logdir)

  pidfile = open(options.pidfile, 'w')
  pidfile.write( str(os.getpid()) )
  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()

Exemple #8
0
  pidfile = open(options.pidfile, 'w')
  pidfile.write( str(os.getpid()) )
  pidfile.close()

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

  atexit.register(shutdown)

  logToDir(options.logdir)


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

client.connect(settings.DESTINATION_HOST, settings.DESTINATION_PORT)
startRecording()


# Run the twisted reactor
print "%s running with pid %d" % (program, os.getpid())

if options.profile:
  import cProfile

  if exists(options.profile):
    os.unlink(options.profile)
    from carbon.util import daemonize
    daemonize()
    logToDir(options.logdir)

    pidfile = open(options.pidfile, 'w')
    pidfile.write(str(os.getpid()))
    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()