Search in sources :

Example 1 with Histogram

use of org.commonjava.o11yphant.metrics.api.Histogram in project indy by Commonjava.

the class TransferStreamingOutput method write.

@Override
@Measure
public void write(final OutputStream out) throws IOException, WebApplicationException {
    start = System.nanoTime();
    try {
        cout = new CountingOutputStream(out);
        IOUtils.copy(stream, cout);
        kbCount = (double) cout.getByteCount() / 1024;
        Logger logger = LoggerFactory.getLogger(getClass());
        logger.trace("Wrote: {} bytes", kbCount);
        long end = System.nanoTime();
        RequestContextHelper.setContext(RAW_IO_WRITE_NANOS, end - start);
        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)));
        String rateName = getName(metricsConfig.getNodePrefix(), TRANSFER_METRIC_NAME + WRITE_SPEED, getDefaultName(TransferStreamingOutput.class, WRITE_SPEED), METER);
        Histogram rateGram = metricsManager.getHistogram(rateName);
        writeSpeed = Math.round(kbCount / elapsed);
        logger.info("measured speed: {} kb/s to metric: {}", (writeSpeed / 1024), rateName);
        rateGram.update(writeSpeed);
        String sizeName = getName(metricsConfig.getNodePrefix(), TRANSFER_METRIC_NAME + WRITE_SIZE, getDefaultName(TransferStreamingOutput.class, WRITE_SIZE), METER);
        logger.info("measured size: {} kb to metric: {}", (kbCount / 1024), sizeName);
        Histogram sizeGram = metricsManager.getHistogram(sizeName);
        sizeGram.update(Math.round(kbCount));
    } finally {
        IOUtils.closeQuietly(stream);
        rootSpan.ifPresent(SpanAdapter::close);
    }
}
Also used : CountingOutputStream(org.apache.commons.io.output.CountingOutputStream) Histogram(org.commonjava.o11yphant.metrics.api.Histogram) SpanAdapter(org.commonjava.o11yphant.trace.spi.adapter.SpanAdapter) Logger(org.slf4j.Logger) Measure(org.commonjava.o11yphant.metrics.annotation.Measure)

Aggregations

CountingOutputStream (org.apache.commons.io.output.CountingOutputStream)1 Measure (org.commonjava.o11yphant.metrics.annotation.Measure)1 Histogram (org.commonjava.o11yphant.metrics.api.Histogram)1 SpanAdapter (org.commonjava.o11yphant.trace.spi.adapter.SpanAdapter)1 Logger (org.slf4j.Logger)1