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;
}
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);
}
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");
}
Aggregations