Search in sources :

Example 1 with AtomicBuffer

use of org.agrona.concurrent.AtomicBuffer in project Aeron by real-logic.

the class CommonContext method saveErrorLog.

/**
     * Read the error log to a given {@link PrintStream}
     *
     * @param out to write the error log contents to.
     * @return the number of observations from the error log
     */
public int saveErrorLog(final PrintStream out) {
    final File dirFile = new File(aeronDirectoryName);
    int distinctErrorCount = 0;
    if (dirFile.exists() && dirFile.isDirectory()) {
        final File cncFile = new File(aeronDirectoryName, CncFileDescriptor.CNC_FILE);
        if (cncFile.exists()) {
            MappedByteBuffer cncByteBuffer = null;
            try {
                cncByteBuffer = IoUtil.mapExistingFile(cncFile, CncFileDescriptor.CNC_FILE);
                final UnsafeBuffer cncMetaDataBuffer = CncFileDescriptor.createMetaDataBuffer(cncByteBuffer);
                final int cncVersion = cncMetaDataBuffer.getInt(CncFileDescriptor.cncVersionOffset(0));
                if (CncFileDescriptor.CNC_VERSION != cncVersion) {
                    throw new IllegalStateException("aeron cnc file version not understood: version=" + cncVersion);
                }
                final AtomicBuffer buffer = CncFileDescriptor.createErrorLogBuffer(cncByteBuffer, cncMetaDataBuffer);
                final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSSZ");
                distinctErrorCount = ErrorLogReader.read(buffer, (observationCount, firstObservationTimestamp, lastObservationTimestamp, encodedException) -> out.format("***%n%d observations from %s to %s for:%n %s%n", observationCount, dateFormat.format(new Date(firstObservationTimestamp)), dateFormat.format(new Date(lastObservationTimestamp)), encodedException));
                out.format("%n%d distinct errors observed.%n", distinctErrorCount);
            } catch (final Exception ex) {
                LangUtil.rethrowUnchecked(ex);
            } finally {
                IoUtil.unmap(cncByteBuffer);
            }
        }
    }
    return distinctErrorCount;
}
Also used : PrintStream(java.io.PrintStream) Date(java.util.Date) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) SimpleDateFormat(java.text.SimpleDateFormat) UUID(java.util.UUID) IoUtil(org.agrona.IoUtil) File(java.io.File) ManyToOneRingBuffer(org.agrona.concurrent.ringbuffer.ManyToOneRingBuffer) Consumer(java.util.function.Consumer) LangUtil(org.agrona.LangUtil) System.getProperty(java.lang.System.getProperty) ErrorLogReader(org.agrona.concurrent.errors.ErrorLogReader) AtomicBuffer(org.agrona.concurrent.AtomicBuffer) MappedByteBuffer(java.nio.MappedByteBuffer) MappedByteBuffer(java.nio.MappedByteBuffer) AtomicBuffer(org.agrona.concurrent.AtomicBuffer) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) File(java.io.File) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 2 with AtomicBuffer

use of org.agrona.concurrent.AtomicBuffer in project Aeron by real-logic.

the class ErrorStat method main.

public static void main(final String[] args) throws Exception {
    final File cncFile = CommonContext.newDefaultCncFile();
    System.out.println("Command `n Control file " + cncFile);
    final MappedByteBuffer cncByteBuffer = IoUtil.mapExistingFile(cncFile, "cnc");
    final DirectBuffer cncMetaDataBuffer = CncFileDescriptor.createMetaDataBuffer(cncByteBuffer);
    final int cncVersion = cncMetaDataBuffer.getInt(CncFileDescriptor.cncVersionOffset(0));
    if (CncFileDescriptor.CNC_VERSION != cncVersion) {
        throw new IllegalStateException("CNC version not supported: file version=" + cncVersion);
    }
    final AtomicBuffer buffer = CncFileDescriptor.createErrorLogBuffer(cncByteBuffer, cncMetaDataBuffer);
    final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSSZ");
    final int distinctErrorCount = ErrorLogReader.read(buffer, (observationCount, firstObservationTimestamp, lastObservationTimestamp, encodedException) -> System.out.format("***%n%d observations from %s to %s for:%n %s%n", observationCount, dateFormat.format(new Date(firstObservationTimestamp)), dateFormat.format(new Date(lastObservationTimestamp)), encodedException));
    System.out.format("%n%d distinct errors observed.%n", distinctErrorCount);
}
Also used : DirectBuffer(org.agrona.DirectBuffer) MappedByteBuffer(java.nio.MappedByteBuffer) AtomicBuffer(org.agrona.concurrent.AtomicBuffer) File(java.io.File) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 3 with AtomicBuffer

use of org.agrona.concurrent.AtomicBuffer in project Aeron by real-logic.

the class LossStat method main.

public static void main(final String[] args) {
    final String aeronDirectoryName = getProperty(AERON_DIR_PROP_NAME, AERON_DIR_PROP_DEFAULT);
    final File lossReportFile = LossReportUtil.file(aeronDirectoryName);
    if (!lossReportFile.exists()) {
        System.err.print("Loss report does not exist: " + lossReportFile);
        System.exit(1);
    }
    final MappedByteBuffer mappedByteBuffer = IoUtil.mapExistingFile(lossReportFile, "Loss Report");
    final AtomicBuffer buffer = new UnsafeBuffer(mappedByteBuffer);
    final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSSZ");
    System.out.println("#OBSERVATION_COUNT, TOTAL_BYTES_LOST, FIRST_OBSERVATION," + " LAST_OBSERVATION, SESSION_ID, STREAM_ID, CHANNEL, SOURCE");
    final int entriesRead = LossReportReader.read(buffer, (observationCount, totalBytesLost, firstObservationTimestamp, lastObservationTimestamp, sessionId, streamId, channel, source) -> System.out.format("%d,%d,%s,%s,%d,%d,%s,%s%n", observationCount, totalBytesLost, dateFormat.format(new Date(firstObservationTimestamp)), dateFormat.format(new Date(lastObservationTimestamp)), sessionId, streamId, channel, source));
    System.out.println(entriesRead + " entries read");
}
Also used : MappedByteBuffer(java.nio.MappedByteBuffer) AtomicBuffer(org.agrona.concurrent.AtomicBuffer) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) File(java.io.File) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Aggregations

File (java.io.File)3 MappedByteBuffer (java.nio.MappedByteBuffer)3 SimpleDateFormat (java.text.SimpleDateFormat)3 Date (java.util.Date)3 AtomicBuffer (org.agrona.concurrent.AtomicBuffer)3 UnsafeBuffer (org.agrona.concurrent.UnsafeBuffer)2 PrintStream (java.io.PrintStream)1 System.getProperty (java.lang.System.getProperty)1 UUID (java.util.UUID)1 Consumer (java.util.function.Consumer)1 DirectBuffer (org.agrona.DirectBuffer)1 IoUtil (org.agrona.IoUtil)1 LangUtil (org.agrona.LangUtil)1 ErrorLogReader (org.agrona.concurrent.errors.ErrorLogReader)1 ManyToOneRingBuffer (org.agrona.concurrent.ringbuffer.ManyToOneRingBuffer)1