Search in sources :

Example 1 with LogFilter

use of org.apache.geode.management.internal.cli.util.LogFilter in project geode by apache.

the class SizeExportLogsFunction method estimateLogFileSize.

long estimateLogFileSize(final DistributedMember member, final File logFile, final File statArchive, final Args args) throws IOException {
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("SizeExportLogsFunction started for member {}", member);
    }
    File baseLogFile = null;
    File baseStatsFile = null;
    if (args.isIncludeLogs() && !logFile.toString().isEmpty()) {
        baseLogFile = logFile.getAbsoluteFile();
    }
    if (args.isIncludeStats() && !statArchive.toString().isEmpty()) {
        baseStatsFile = statArchive.getAbsoluteFile();
    }
    LogFilter logFilter = new LogFilter(args.getLogLevel(), args.isThisLogLevelOnly(), args.getStartTime(), args.getEndTime());
    long estimatedSize = new LogExporter(logFilter, baseLogFile, baseStatsFile).estimateFilteredSize();
    LOGGER.info("Estimated log file size: " + estimatedSize);
    return estimatedSize;
}
Also used : LogExporter(org.apache.geode.management.internal.cli.util.LogExporter) File(java.io.File) LogFilter(org.apache.geode.management.internal.cli.util.LogFilter)

Example 2 with LogFilter

use of org.apache.geode.management.internal.cli.util.LogFilter in project geode by apache.

the class ExportLogsFunction method execute.

@Override
public void execute(final FunctionContext context) {
    try {
        InternalCache cache = GemFireCacheImpl.getInstance();
        DistributionConfig config = cache.getInternalDistributedSystem().getConfig();
        String memberId = cache.getDistributedSystem().getMemberId();
        logger.info("ExportLogsFunction started for member {}", memberId);
        Region exportLogsRegion = createOrGetExistingExportLogsRegion(false, cache);
        Args args = (Args) context.getArguments();
        File baseLogFile = null;
        File baseStatsFile = null;
        if (args.isIncludeLogs() && !config.getLogFile().toString().isEmpty()) {
            baseLogFile = config.getLogFile().getAbsoluteFile();
        }
        if (args.isIncludeStats() && !config.getStatisticArchiveFile().toString().isEmpty()) {
            baseStatsFile = config.getStatisticArchiveFile().getAbsoluteFile();
        }
        LogFilter logFilter = new LogFilter(args.getLogLevel(), args.isThisLogLevelOnly(), args.getStartTime(), args.getEndTime());
        Path exportedZipFile = new LogExporter(logFilter, baseLogFile, baseStatsFile).export();
        // nothing to return back
        if (exportedZipFile == null) {
            context.getResultSender().lastResult(null);
            return;
        }
        logger.info("Streaming zipped file: " + exportedZipFile.toString());
        try (FileInputStream inputStream = new FileInputStream(exportedZipFile.toFile())) {
            byte[] buffer = new byte[BUFFER_SIZE];
            int bytesRead;
            while ((bytesRead = inputStream.read(buffer)) > 0) {
                if (bytesRead == BUFFER_SIZE) {
                    exportLogsRegion.put(memberId, buffer);
                } else {
                    exportLogsRegion.put(memberId, Arrays.copyOfRange(buffer, 0, bytesRead));
                }
            }
        }
        context.getResultSender().lastResult(null);
    } catch (Exception e) {
        e.printStackTrace();
        logger.error(e);
        context.getResultSender().sendException(e);
    }
}
Also used : Path(java.nio.file.Path) InternalCache(org.apache.geode.internal.cache.InternalCache) FileInputStream(java.io.FileInputStream) ParseException(java.text.ParseException) IOException(java.io.IOException) DistributionConfig(org.apache.geode.distributed.internal.DistributionConfig) LogExporter(org.apache.geode.management.internal.cli.util.LogExporter) Region(org.apache.geode.cache.Region) File(java.io.File) LogFilter(org.apache.geode.management.internal.cli.util.LogFilter)

Aggregations

File (java.io.File)2 LogExporter (org.apache.geode.management.internal.cli.util.LogExporter)2 LogFilter (org.apache.geode.management.internal.cli.util.LogFilter)2 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 ParseException (java.text.ParseException)1 Region (org.apache.geode.cache.Region)1 DistributionConfig (org.apache.geode.distributed.internal.DistributionConfig)1 InternalCache (org.apache.geode.internal.cache.InternalCache)1