Esempio n. 1
0
 def __init__(self, endpoint, socket=None):
     super(PubLogHandler, self).__init__()
     self.socket = socket
     if self.socket is None:
         ctx = zmq.Context.instance()
         self.socket = ctx.socket(zmq.PUB)
         endpoint, port = bind_zmq_socket(self.socket, endpoint)
     self.endpoint = endpoint
Esempio n. 2
0
 def __init__(self, container, aggregator, endpoint='127.0.0.1', interval=2):
     super(MonitorPusher, self).__init__()
     self.container = container
     self.interval = interval
     ctx = zmq.Context.instance()
     self.socket = ctx.socket(zmq.PUB)
     self.endpoint, port = bind_zmq_socket(self.socket, endpoint)
     logger.info('binding monitoring endpoint %s', self.endpoint)
     self.aggregator = aggregator
Esempio n. 3
0
 def __init__(self, container, aggregator, endpoint='127.0.0.1', interval=2):
     super(MonitorPusher, self).__init__()
     self.container = container
     self.interval = interval
     ctx = zmq.Context.instance()
     self.socket = ctx.socket(zmq.PUB)
     self.endpoint, port = bind_zmq_socket(self.socket, endpoint)
     logger.info('binding monitoring endpoint %s', self.endpoint)
     self.aggregator = aggregator
Esempio n. 4
0
def setup_logging(config, loglevel, logfile):
    """Configure 'lymph' logger handlers and level.

    This function also set the container.log_endpoint in case it wasn't set.
    """
    logconf = dict(config.get_raw('logging', {}))
    log_endpoint = config.get('container.log_endpoint')
    log_socket = None
    # Get log_endpoint in case it wasn't set in the config.
    if not log_endpoint:
        ctx = zmq.Context.instance()
        log_socket = ctx.socket(zmq.PUB)
        log_endpoint, port = bind_zmq_socket(log_socket,
                                             config.get('container.ip'))

        config.set('container.log_endpoint', log_endpoint)

    logconf.setdefault('version', 1)
    formatters = logconf.setdefault('formatters', {})
    formatters.setdefault(
        '_trace', {
            '()':
            'lymph.core.trace.TraceFormatter',
            'format':
            '%(asctime)s [%(levelname)s] %(name)s: %(message)s - trace_id="%(trace_id)s"',
        })
    handlers = logconf.setdefault('handlers', {})
    handlers.setdefault(
        '_zmqpub', {
            'class': 'lymph.utils.logging.PubLogHandler',
            'formatter': '_trace',
            'endpoint': log_endpoint,
            'socket': log_socket,
        })
    console_logconf = {
        'class': 'logging.StreamHandler',
        'formatter': '_trace',
        'level': loglevel.upper(),
    }
    if logfile:
        console_logconf.update({
            'class': 'logging.FileHandler',
            'filename': logfile
        })
    handlers.setdefault('_console', console_logconf)
    loggers = logconf.setdefault('loggers', {})
    loggers.setdefault('lymph', {
        'handlers': ['_console', '_zmqpub'],
        'level': 'DEBUG',
    })
    dictConfig(logconf)
Esempio n. 5
0
def setup_logging(config, loglevel, logfile):
    """Configure 'lymph' logger handlers and level.

    This function also set the container.log_endpoint in case it wasn't set.
    """
    logconf = copy.deepcopy(config.get_raw('logging', {}))
    log_endpoint = config.get('container.log_endpoint')
    log_socket = None
    # Get log_endpoint in case it wasn't set in the config.
    if not log_endpoint:
        ctx = zmq.Context.instance()
        log_socket = ctx.socket(zmq.PUB)
        log_endpoint, port = bind_zmq_socket(log_socket, config.get('container.ip'))

        config.set('container.log_endpoint', log_endpoint)

    logconf.setdefault('version', 1)
    formatters = logconf.setdefault('formatters', {})
    formatters.setdefault('_trace', {
        '()': 'lymph.core.trace.TraceFormatter',
        'format': '%(asctime)s [%(levelname)s] %(name)s: %(message)s - trace_id="%(trace_id)s"',
    })
    handlers = logconf.setdefault('handlers', {})
    handlers.setdefault('_zmqpub', {
        'class': 'lymph.utils.logging.PubLogHandler',
        'formatter': '_trace',
        'endpoint': log_endpoint,
        'socket': log_socket,
    })
    console_logconf = {
        'class': 'logging.StreamHandler',
        'formatter': '_trace',
        'level': 'DEBUG',
    }
    if logfile:
        console_logconf.update({
            'class': 'logging.FileHandler',
            'filename': logfile
        })
    handlers.setdefault('_console', console_logconf)
    loggers = logconf.setdefault('loggers', {})
    loggers.setdefault('lymph', {
        'handlers': ['_console', '_zmqpub'],
        'level': loglevel.upper(),
    })
    dictConfig(logconf)
Esempio n. 6
0
 def __init__(self, endpoint):
     super(PubLogHandler, self).__init__()
     ctx = zmq.Context.instance()
     self.socket = ctx.socket(zmq.PUB)
     self.endpoint, port = bind_zmq_socket(self.socket, endpoint)