Search in sources :

Example 1 with MetricId

use of com.spotify.metrics.core.MetricId in project apollo by spotify.

the class SemanticServiceMetrics method metersForEndpoint.

private CachedMeters metersForEndpoint(String endpoint) {
    MetricId id = metricId.tagged("endpoint", endpoint);
    // precreate meters for defined status codes to ensure that they start out at value 0 on restart
    for (Integer code : precreateCodes) {
        requestRateMeter(id, code);
    }
    Meter sentReplies = new Meter();
    Meter sentErrors = new Meter();
    if (enabledMetrics.test(ERROR_RATIO)) {
        registerRatioGauge(id, "1m", errorRatioSupplier(sentErrors::getOneMinuteRate, sentReplies::getOneMinuteRate), metricRegistry);
        registerRatioGauge(id, "5m", errorRatioSupplier(sentErrors::getFiveMinuteRate, sentReplies::getFiveMinuteRate), metricRegistry);
        registerRatioGauge(id, "15m", errorRatioSupplier(sentErrors::getFifteenMinuteRate, sentReplies::getFifteenMinuteRate), metricRegistry);
    }
    return new CachedMeters(requestRateCounter(id), fanoutHistogram(id), responseSizeHistogram(id), requestSizeHistogram(id), requestDurationTimer(id), droppedRequests(id), sentReplies, sentErrors);
}
Also used : MetricId(com.spotify.metrics.core.MetricId) Meter(com.codahale.metrics.Meter)

Example 2 with MetricId

use of com.spotify.metrics.core.MetricId in project apollo by spotify.

the class RouteTransformMetricsExampleTest method responsePayloadSizeHistogram.

/**
 * Middleware to track response payload size in a Histogram,
 * tagged with an endpoint tag set to the given endpoint name.
 */
public Middleware<AsyncHandler<Response<ByteString>>, AsyncHandler<Response<ByteString>>> responsePayloadSizeHistogram(String endpointName) {
    final MetricId histogramId = MetricId.build().tagged("service", serviceName).tagged("endpoint", endpointName).tagged("what", "endpoint-response-size");
    final Histogram histogram = registry.histogram(histogramId);
    return (inner) -> (requestContext) -> inner.invoke(requestContext).whenComplete((response, t) -> {
        if (response != null) {
            histogram.update(response.payload().map(ByteString::size).orElse(0));
        }
    });
}
Also used : Matchers.hasEntry(org.hamcrest.Matchers.hasEntry) Histogram(com.codahale.metrics.Histogram) Response(com.spotify.apollo.Response) AsyncHandler(com.spotify.apollo.route.AsyncHandler) RequestContext(com.spotify.apollo.RequestContext) Matchers.allOf(org.hamcrest.Matchers.allOf) MetricId(com.spotify.metrics.core.MetricId) SemanticMetricRegistry(com.spotify.metrics.core.SemanticMetricRegistry) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Middleware(com.spotify.apollo.route.Middleware) Route(com.spotify.apollo.route.Route) Matchers.hasProperty(org.hamcrest.Matchers.hasProperty) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) ByteString(okio.ByteString) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Collections(java.util.Collections) Mockito.mock(org.mockito.Mockito.mock) MetricId(com.spotify.metrics.core.MetricId) Histogram(com.codahale.metrics.Histogram) ByteString(okio.ByteString)

Example 3 with MetricId

use of com.spotify.metrics.core.MetricId in project simple-bigtable by spotify.

the class BigtableSemanticMetricsRegistry method meter.

@Override
public Meter meter(final String name) {
    final MetricId tagged = baseMetricId.tagged("what", name);
    final com.codahale.metrics.Meter meter = registry.meter(tagged);
    return new Meter() {

        @Override
        public void mark() {
            meter.mark();
        }

        @Override
        public void mark(long size) {
            meter.mark(size);
        }
    };
}
Also used : MetricId(com.spotify.metrics.core.MetricId) Meter(com.google.cloud.bigtable.metrics.Meter)

Example 4 with MetricId

use of com.spotify.metrics.core.MetricId in project simple-bigtable by spotify.

the class BigtableSemanticMetricsRegistry method timer.

@Override
public Timer timer(final String name) {
    final MetricId tagged = baseMetricId.tagged("what", name);
    final com.codahale.metrics.Timer timer = registry.timer(tagged);
    return new Timer() {

        @Override
        public Context time() {
            final com.codahale.metrics.Timer.Context context = timer.time();
            return context::close;
        }

        @Override
        public void update(final long duration, final TimeUnit timeUnit) {
            timer.update(duration, timeUnit);
        }
    };
}
Also used : MetricId(com.spotify.metrics.core.MetricId) Timer(com.google.cloud.bigtable.metrics.Timer) TimeUnit(java.util.concurrent.TimeUnit)

Example 5 with MetricId

use of com.spotify.metrics.core.MetricId in project simple-bigtable by spotify.

the class BigtableSemanticMetricsRegistry method counter.

@Override
public Counter counter(final String name) {
    final MetricId tagged = baseMetricId.tagged("what", name);
    final com.codahale.metrics.Counter counter = registry.counter(tagged);
    return new Counter() {

        @Override
        public void inc() {
            counter.inc();
        }

        @Override
        public void dec() {
            counter.dec();
        }
    };
}
Also used : MetricId(com.spotify.metrics.core.MetricId) Counter(com.google.cloud.bigtable.metrics.Counter)

Aggregations

MetricId (com.spotify.metrics.core.MetricId)5 Histogram (com.codahale.metrics.Histogram)1 Meter (com.codahale.metrics.Meter)1 Counter (com.google.cloud.bigtable.metrics.Counter)1 Meter (com.google.cloud.bigtable.metrics.Meter)1 Timer (com.google.cloud.bigtable.metrics.Timer)1 RequestContext (com.spotify.apollo.RequestContext)1 Response (com.spotify.apollo.Response)1 AsyncHandler (com.spotify.apollo.route.AsyncHandler)1 Middleware (com.spotify.apollo.route.Middleware)1 Route (com.spotify.apollo.route.Route)1 SemanticMetricRegistry (com.spotify.metrics.core.SemanticMetricRegistry)1 Collections (java.util.Collections)1 TimeUnit (java.util.concurrent.TimeUnit)1 ByteString (okio.ByteString)1 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)1 Matchers.allOf (org.hamcrest.Matchers.allOf)1 Matchers.containsInAnyOrder (org.hamcrest.Matchers.containsInAnyOrder)1 Matchers.hasEntry (org.hamcrest.Matchers.hasEntry)1 Matchers.hasProperty (org.hamcrest.Matchers.hasProperty)1