Search in sources :

Example 1 with MetricName

use of com.palantir.tritium.metrics.registry.MetricName in project atlasdb by palantir.

the class TransactionManagersTest method assertThatTimeAndLockMetricsWithTagsAreRecorded.

private void assertThatTimeAndLockMetricsWithTagsAreRecorded(String timestampMetric, String lockMetric, Map<String, String> tags) {
    MetricName timestampMetricName = MetricName.builder().safeName(timestampMetric).putAllSafeTags(tags).build();
    MetricName lockMetricName = MetricName.builder().safeName(lockMetric).putAllSafeTags(tags).build();
    assertThat(metricsManager.getTaggedRegistry().timer(timestampMetricName).getCount()).isEqualTo(0L);
    assertThat(metricsManager.getTaggedRegistry().timer(lockMetricName).getCount()).isEqualTo(0L);
    LockAndTimestampServices lockAndTimestamp = getLockAndTimestampServices();
    lockAndTimestamp.timelock().getFreshTimestamp();
    lockAndTimestamp.timelock().currentTimeMillis();
    assertThat(metricsManager.getTaggedRegistry().timer(timestampMetricName).getCount()).isEqualTo(1L);
    assertThat(metricsManager.getTaggedRegistry().timer(lockMetricName).getCount()).isEqualTo(1L);
}
Also used : MetricName(com.palantir.tritium.metrics.registry.MetricName)

Example 2 with MetricName

use of com.palantir.tritium.metrics.registry.MetricName in project atlasdb by palantir.

the class MetricsManager method registerOrGet.

/**
 * Add a new gauge metric of the given name or get the existing gauge if it is already registered.
 *
 * @throws IllegalStateException if a non-gauge metric with the same name already exists.
 */
public <T> Gauge<T> registerOrGet(Class<?> clazz, String metricName, Gauge<T> gauge, Map<String, String> tag) {
    MetricName metricToAdd = getTaggedMetricName(clazz, metricName, tag);
    try {
        Gauge<T> registeredGauge = taggedMetricRegistry.gauge(metricToAdd, gauge);
        registerTaggedMetricName(metricToAdd);
        return registeredGauge;
    } catch (IllegalArgumentException ex) {
        log.error("Tried to add a gauge to a metric name {} that has non-gauge metrics associated with it." + " This indicates a product bug.", SafeArg.of("metricName", metricName), ex);
        throw ex;
    }
}
Also used : MetricName(com.palantir.tritium.metrics.registry.MetricName)

Example 3 with MetricName

use of com.palantir.tritium.metrics.registry.MetricName in project atlasdb by palantir.

the class MetricsManager method registerOrGetTaggedHistogram.

public Histogram registerOrGetTaggedHistogram(Class<?> clazz, String metricName, Map<String, String> tags, Supplier<Histogram> supplier) {
    MetricName name = getTaggedMetricName(clazz, metricName, tags);
    Histogram histogram = taggedMetricRegistry.histogram(name, supplier);
    registerTaggedMetricName(name);
    return histogram;
}
Also used : MetricName(com.palantir.tritium.metrics.registry.MetricName) Histogram(com.codahale.metrics.Histogram)

Example 4 with MetricName

use of com.palantir.tritium.metrics.registry.MetricName in project atlasdb by palantir.

the class MetricsManager method registerOrGetTaggedMeter.

public Meter registerOrGetTaggedMeter(Class<?> clazz, String metricName, Map<String, String> tags) {
    MetricName name = getTaggedMetricName(clazz, metricName, tags);
    Meter meter = taggedMetricRegistry.meter(name);
    registerTaggedMetricName(name);
    return meter;
}
Also used : MetricName(com.palantir.tritium.metrics.registry.MetricName) Meter(com.codahale.metrics.Meter)

Example 5 with MetricName

use of com.palantir.tritium.metrics.registry.MetricName in project atlasdb by palantir.

the class MetricsBasedTimelockHealthCheck method getStatus.

@Override
public TimelockServiceStatus getStatus() {
    Map<MetricName, Metric> metrics = metricsManager.getTaggedRegistry().getMetrics();
    Metric success = metrics.get(MetricName.builder().safeName(AtlasDbMetricNames.TIMELOCK_SUCCESSFUL_REQUEST).build());
    Metric failure = metrics.get(MetricName.builder().safeName(AtlasDbMetricNames.TIMELOCK_FAILED_REQUEST).build());
    if (!(success instanceof Meter) || !(failure instanceof Meter)) {
        throw new SafeIllegalStateException("Timelock client metrics is not properly set");
    }
    double successfulRequestRate = ((Meter) success).getFiveMinuteRate();
    double failedRequestRate = ((Meter) failure).getFiveMinuteRate();
    if (successfulRequestRate >= failedRequestRate) {
        return TimelockServiceStatus.HEALTHY;
    } else {
        return TimelockServiceStatus.UNHEALTHY;
    }
}
Also used : MetricName(com.palantir.tritium.metrics.registry.MetricName) Meter(com.codahale.metrics.Meter) Metric(com.codahale.metrics.Metric) SafeIllegalStateException(com.palantir.logsafe.exceptions.SafeIllegalStateException)

Aggregations

MetricName (com.palantir.tritium.metrics.registry.MetricName)37 TaggedMetricRegistry (com.palantir.tritium.metrics.registry.TaggedMetricRegistry)11 Test (org.junit.jupiter.api.Test)10 Metric (com.codahale.metrics.Metric)9 DefaultTaggedMetricRegistry (com.palantir.tritium.metrics.registry.DefaultTaggedMetricRegistry)9 Timer (com.codahale.metrics.Timer)7 Counter (com.codahale.metrics.Counter)6 Histogram (com.codahale.metrics.Histogram)6 Meter (com.codahale.metrics.Meter)6 Test (org.junit.Test)6 Gauge (com.codahale.metrics.Gauge)5 Closeable (java.io.Closeable)5 ImmutableList (com.google.common.collect.ImmutableList)4 List (java.util.List)4 ConsoleReporter (com.codahale.metrics.ConsoleReporter)3 MetricSet (com.codahale.metrics.MetricSet)3 OkHttpClient (okhttp3.OkHttpClient)3 Request (okhttp3.Request)3 Response (okhttp3.Response)3 ExponentiallyDecayingReservoir (com.codahale.metrics.ExponentiallyDecayingReservoir)2