use of org.commonjava.o11yphant.metrics.api.Meter in project indy by Commonjava.
the class TransferCountingInputStream method close.
@Override
public void close() throws IOException {
long start = System.nanoTime();
try {
CountingInputStream stream = (CountingInputStream) this.in;
Logger logger = LoggerFactory.getLogger(getClass());
size = stream.getByteCount();
logger.trace("Reads: {} bytes", size);
long end = System.nanoTime();
double elapsed = (end - start) / NANOS_PER_SEC;
TraceManager.getActiveSpan().ifPresent(s -> s.setInProgressField(LATENCY_TIMER_PAUSE_KEY, s.getInProgressField(LATENCY_TIMER_PAUSE_KEY, 0.0) + (end - start)));
if (metricsConfig != null && metricsManager != null) {
String name = getName(metricsConfig.getNodePrefix(), TRANSFER_UPLOAD_METRIC_NAME, getDefaultName(TransferCountingInputStream.class, "read"), METER);
Meter meter = metricsManager.getMeter(name);
meter.mark(Math.round(stream.getByteCount() / elapsed));
}
double kbCount = (double) size / 1024;
long speed = Math.round(kbCount / elapsed);
addFieldToActiveSpan(READ_SIZE, kbCount);
addFieldToActiveSpan(READ_SPEED, speed);
} finally {
super.close();
}
}
use of org.commonjava.o11yphant.metrics.api.Meter in project indy by Commonjava.
the class DTOStreamingOutput method write.
@Override
public void write(final OutputStream outputStream) throws IOException, WebApplicationException {
AtomicReference<IOException> ioe = new AtomicReference<>();
metricsManager.wrapWithStandardMetrics(() -> {
CountingOutputStream cout = new CountingOutputStream(outputStream);
long start = System.nanoTime();
try {
mapper.writeValue(cout, dto);
} catch (IOException e) {
ioe.set(e);
} finally {
Logger logger = LoggerFactory.getLogger(getClass());
logger.trace("Wrote: {} bytes", cout.getByteCount());
String name = getName(metricsConfig.getNodePrefix(), TRANSFER_METRIC_NAME, getDefaultName(dto.getClass(), "write"), METER);
long end = System.nanoTime();
double elapsed = (end - start) / NANOS_PER_SEC;
Meter meter = metricsManager.getMeter(name);
meter.mark(Math.round(cout.getByteCount() / elapsed));
}
return null;
}, () -> null);
if (ioe.get() != null) {
throw ioe.get();
}
}
Aggregations