示例#1
0
def process(arguments):
    access_log = arguments['--access-log']
    log_format = arguments['--log-format']
    if access_log is None and not sys.stdin.isatty():
        # assume logs can be fetched directly from stdin when piped
        access_log = 'stdin'
    if access_log is None:
        access_log, log_format = detect_log_config(arguments)

    logging.info('access_log: %s', access_log)
    logging.info('log_format: %s', log_format)
    if access_log != 'stdin' and not os.path.exists(access_log):
        error_exit('access log file "%s" does not exist' % access_log)

    if arguments['info']:
        print('nginx configuration file:\n ', detect_config_path())
        print('access log file:\n ', access_log)
        print('access log format:\n ', log_format)
        print('available variables:\n ',
              ', '.join(sorted(extract_variables(log_format))))
        return

    source = build_source(access_log, arguments)
    pattern = build_pattern(log_format)
    #processor = build_processor(arguments)
    processor = None
    process_log(source, pattern, processor, arguments)
示例#2
0
文件: ngxtop.py 项目: 4honor/ngxtop
def process(arguments):
    access_log = arguments['--access-log']
    log_format = arguments['--log-format']
    if access_log is None and not sys.stdin.isatty():
        # assume logs can be fetched directly from stdin when piped
        access_log = 'stdin'
    if access_log is None:
        access_log, log_format = detect_log_config(arguments)

    logging.info('access_log: %s', access_log)
    logging.info('log_format: %s', log_format)
    if access_log != 'stdin' and not os.path.exists(access_log):
        error_exit('access log file "%s" does not exist' % access_log)

    if arguments['info']:
        print('nginx configuration file:\n ', detect_config_path())
        print('access log file:\n ', access_log)
        print('access log format:\n ', log_format)
        print('available variables:\n ', ', '.join(sorted(extract_variables(log_format))))
        return

    source = build_source(access_log, arguments)
    pattern = build_pattern(log_format)
    processor = build_processor(arguments)
    setup_reporter(processor, arguments)
    process_log(source, pattern, processor, arguments)
示例#3
0
文件: log_reader.py 项目: 2-fly/2fly
def test_processor(conf_file, stat_file):
    arguments = {
        '--config': conf_file,
        '--stat-file': stat_file,
    }

    access_log, log_format = detect_log_config(arguments)
    # $remote_addr - $remote_user [$time_local] "$request" $status $request_length $bytes_sent $body_bytes_sent "$http_referer" "$http_user_agent" "$http_x_forwarded_for"
    #print log_format
    #print('available variables:\n ', ', '.join(sorted(extract_variables(log_format))))

    pattern = build_pattern(log_format)
    source = build_source(access_log, arguments)
    process_log(source, pattern, arguments, log_handler)
示例#4
0
    def get_access_log(self):
        """
        Get nginx access.log file path
        :return: access.log file path and log format
        """
        if self.access_log is not None:
            return self.access_log

        self.access_log = self.arguments['--access-log']
        log_format = self.arguments['--log-format']
        if self.access_log is None and not sys.stdin.isatty():
            # assume logs can be fetched directly from stdin when piped
            self.access_log = 'stdin'
        if self.access_log is None:
            self.access_log, log_format = detect_log_config(self.arguments)

        logging.info('access_log: %s', self.access_log)
        logging.info('log_format: %s', log_format)
        if self.access_log != 'stdin' and not os.path.exists(self.access_log):
            error_exit('access log file "%s" does not exist' % self.access_log)
        return self.access_log, log_format