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);
}
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;
}
}
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;
}
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;
}
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;
}
}
Aggregations