Search in sources :

Example 1 with Meter

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();
    }
}
Also used : Meter(org.commonjava.o11yphant.metrics.api.Meter) CountingInputStream(org.apache.commons.io.input.CountingInputStream) Logger(org.slf4j.Logger)

Example 2 with Meter

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();
    }
}
Also used : CountingOutputStream(org.apache.commons.io.output.CountingOutputStream) Meter(org.commonjava.o11yphant.metrics.api.Meter) AtomicReference(java.util.concurrent.atomic.AtomicReference) IOException(java.io.IOException) Logger(org.slf4j.Logger)

Aggregations

Meter (org.commonjava.o11yphant.metrics.api.Meter)2 Logger (org.slf4j.Logger)2 IOException (java.io.IOException)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 CountingInputStream (org.apache.commons.io.input.CountingInputStream)1 CountingOutputStream (org.apache.commons.io.output.CountingOutputStream)1