예제 #1
0
def collect_gpdb_logs(array, start_time, errors_only=False, master_only=False):
    """ 
    This retrieves log messages from all segments that happened within the last
    'duration' seconds.  The tuples returned are (dbid, hostname, datadir, logdata), 
    sorted by dbid.
    """
    log_chunks = []
    for seg in array.getDbList():
        if master_only and seg.getSegmentContentId() != -1:
            continue
        duration = time.time() - start_time
        cmd = GpLogFilter(
            'collect log chunk',
            '\\`ls -rt %s | tail -1\\`' %
            os.path.join(seg.getSegmentDataDirectory(), 'pg_log', '*.csv'),
            duration='0:0:%s' % (int(math.ceil(duration)) + 3),
            trouble=errors_only,
            ctxt=REMOTE,
            remoteHost=seg.getSegmentHostName())
        cmd.run()
        log_data = cmd.get_results().stdout
        if log_data:
            log_chunks.append((seg.getSegmentDbId(), seg.getSegmentHostName(),
                               seg.getSegmentDataDirectory(), log_data))

    log_chunks.sort(key=lambda chunk: chunk[0])

    return log_chunks
예제 #2
0
파일: __init__.py 프로젝트: 50wu/gpdb
def collect_gpdb_logs(array, start_time, errors_only=False, master_only=False):
    """ 
    This retrieves log messages from all segments that happened within the last
    'duration' seconds.  The tuples returned are (dbid, hostname, datadir, logdata), 
    sorted by dbid.
    """
    log_chunks = []
    for seg in array.getDbList():
        if master_only and seg.getSegmentContentId() != -1:
            continue
        duration = time.time() - start_time
        cmd = GpLogFilter('collect log chunk',
                          '\\`ls -rt %s | tail -1\\`' % os.path.join(seg.getSegmentDataDirectory(), 'pg_log', '*.csv'),
                          duration='0:0:%s' % (int(math.ceil(duration)) + 3),
                          trouble=errors_only,
                          ctxt=REMOTE,
                          remoteHost=seg.getSegmentHostName())
        cmd.run()
        log_data = cmd.get_results().stdout
        if log_data:
            log_chunks.append((seg.getSegmentDbId(), 
                               seg.getSegmentHostName(),
                               seg.getSegmentDataDirectory(),
                               log_data))

    log_chunks.sort(key=lambda chunk: chunk[0])

    return log_chunks
예제 #3
0
    def _gather_log_from_gp_log_filter(start_time, end_time=None, out_file=_DEFAULT_OUT_FILE, host='localhost',
                                   port=_DEFAULT_PORT, user=_DEFAULT_USER, dbname=_DEFAULT_USER, errors_only=False, master_only=False):
        """
        This retrieves log messages from all segments that happened within the last
        'duration' seconds. The format of start_time and end_time is YYYY-MM-DD [hh:mm[:ss]]
        The tuples returned are (dbid, hostname, datadir, logdata). sorted by dbid.
        Returns True/False based on whether matching log entries were found.
        """
        format_start_time = time.strftime("%Y-%m-%dT%H:%M:%S",time.localtime(start_time))
        if end_time:
            format_end_time = time.strftime("%Y-%m-%dT%H:%M:%S",time.localtime(end_time))
        else:
            format_end_time = time.strftime("%Y-%m-%dT%H:%M:%S",time.localtime())

        tinctest.logger.info("Collecting log from %s to %s into the file -%s" % (format_start_time,format_end_time, out_file))

        array = GpArray.initFromCatalog(DbURL(hostname=host, port=port, username=user, dbname=dbname), True)

        log_chunks = []

        for seg in array.getDbList():
            tinctest.logger.info("Collecting log for segment - %s : %s" %(seg.getSegmentHostName(), seg.getSegmentContentId()))
            if master_only and seg.getSegmentContentId() != -1:
                continue

            cmd = GpLogFilter('collect log chunk',
                              '\\`ls -rt %s | tail -1\\`' % os.path.join(seg.getSegmentDataDirectory(), 'pg_log', '*.csv'),
                              start=format_start_time, end=format_end_time,
                              trouble=errors_only,
                              ctxt=REMOTE,
                              remoteHost=seg.getSegmentHostName())
            cmd.run()
            rc = cmd.get_results().rc
            if rc:
                tinctest.logger.warning("Failed command execution %s : %s" %(cmd, cmd.get_results().stderr))
                continue

            log_data = cmd.get_results().stdout

            if not log_data:
                tinctest.logger.warning("No log data returned for the given time frame.")
            else:
                log_chunks.append((seg.getSegmentContentId(),
                                   seg.getSegmentHostName(),
                                   seg.getSegmentDataDirectory(),
                                   log_data))

        if log_chunks:
            tinctest.logger.info("Writing log data to file - %s" %(out_file))
            with open(out_file, 'w') as f:
                for part in log_chunks:
                    f.write("-"*70)
                    f.write("\n  DBID %s (%s:%s)\n" % (part[0], part[1], part[2]))
                    f.write("-"*70)
                    f.write("\n%s" % part[3])
                    f.write("\n\n")
예제 #4
0
파일: gplog.py 프로젝트: 50wu/gpdb
    def _gather_log_from_gp_log_filter(start_time, end_time=None, out_file=_DEFAULT_OUT_FILE, host='localhost',
                                   port=_DEFAULT_PORT, user=_DEFAULT_USER, dbname=_DEFAULT_USER, errors_only=False, master_only=False):
        """
        This retrieves log messages from all segments that happened within the last
        'duration' seconds. The format of start_time and end_time is YYYY-MM-DD [hh:mm[:ss]]
        The tuples returned are (dbid, hostname, datadir, logdata). sorted by dbid.
        Returns True/False based on whether matching log entries were found.
        """
        format_start_time = time.strftime("%Y-%m-%dT%H:%M:%S",time.localtime(start_time))
        if end_time:
            format_end_time = time.strftime("%Y-%m-%dT%H:%M:%S",time.localtime(end_time))
        else:
            format_end_time = time.strftime("%Y-%m-%dT%H:%M:%S",time.localtime())

        tinctest.logger.info("Collecting log from %s to %s into the file -%s" % (format_start_time,format_end_time, out_file))

        array = GpArray.initFromCatalog(DbURL(hostname=host, port=port, username=user, dbname=dbname), True)

        log_chunks = []

        for seg in array.getDbList():
            tinctest.logger.info("Collecting log for segment - %s : %s" %(seg.getSegmentHostName(), seg.getSegmentContentId()))
            if master_only and seg.getSegmentContentId() != -1:
                continue

            cmd = GpLogFilter('collect log chunk',
                              '\\`ls -rt %s | tail -1\\`' % os.path.join(seg.getSegmentDataDirectory(), 'pg_log', '*.csv'),
                              start=format_start_time, end=format_end_time,
                              trouble=errors_only,
                              ctxt=REMOTE,
                              remoteHost=seg.getSegmentHostName())
            cmd.run()
            rc = cmd.get_results().rc
            if rc:
                tinctest.logger.warning("Failed command execution %s : %s" %(cmd, cmd.get_results().stderr))
                continue

            log_data = cmd.get_results().stdout

            if not log_data:
                tinctest.logger.warning("No log data returned for the given time frame.")
            else:
                log_chunks.append((seg.getSegmentContentId(),
                                   seg.getSegmentHostName(),
                                   seg.getSegmentDataDirectory(),
                                   log_data))

        if log_chunks:
            tinctest.logger.info("Writing log data to file - %s" %(out_file))
            with open(out_file, 'w') as f:
                for part in log_chunks:
                    f.write("-"*70)
                    f.write("\n  DBID %s (%s:%s)\n" % (part[0], part[1], part[2]))
                    f.write("-"*70)
                    f.write("\n%s" % part[3])
                    f.write("\n\n")