com.palantir.conjure.java.okhttp.OkhttpMetrics Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of okhttp-clients Show documentation
Show all versions of okhttp-clients Show documentation
Palantir open source project
The newest version!
package com.palantir.conjure.java.okhttp;
import com.codahale.metrics.Gauge;
import com.palantir.logsafe.Preconditions;
import com.palantir.tritium.metrics.registry.MetricName;
import com.palantir.tritium.metrics.registry.TaggedMetricRegistry;
/**
* Conjure okhttp client metrics.
*/
final class OkhttpMetrics {
private static final String JAVA_VERSION = System.getProperty("java.version", "unknown");
private static final String LIBRARY_NAME = "conjure-java-runtime";
private static final String LIBRARY_VERSION = "8.13.0";
private static final MetricName dispatcherCallsQueuedMetricName = MetricName.builder()
.safeName("com.palantir.conjure.java.dispatcher.calls.queued")
.putSafeTags("libraryName", LIBRARY_NAME)
.putSafeTags("libraryVersion", LIBRARY_VERSION)
.putSafeTags("javaVersion", JAVA_VERSION)
.build();
private static final MetricName dispatcherCallsRunningMetricName = MetricName.builder()
.safeName("com.palantir.conjure.java.dispatcher.calls.running")
.putSafeTags("libraryName", LIBRARY_NAME)
.putSafeTags("libraryVersion", LIBRARY_VERSION)
.putSafeTags("javaVersion", JAVA_VERSION)
.build();
private static final MetricName connectionPoolConnectionsTotalMetricName = MetricName.builder()
.safeName("com.palantir.conjure.java.connection-pool.connections.total")
.putSafeTags("libraryName", LIBRARY_NAME)
.putSafeTags("libraryVersion", LIBRARY_VERSION)
.putSafeTags("javaVersion", JAVA_VERSION)
.build();
private static final MetricName connectionPoolConnectionsIdleMetricName = MetricName.builder()
.safeName("com.palantir.conjure.java.connection-pool.connections.idle")
.putSafeTags("libraryName", LIBRARY_NAME)
.putSafeTags("libraryVersion", LIBRARY_VERSION)
.putSafeTags("javaVersion", JAVA_VERSION)
.build();
private final TaggedMetricRegistry registry;
private OkhttpMetrics(TaggedMetricRegistry registry) {
this.registry = registry;
}
static OkhttpMetrics of(TaggedMetricRegistry registry) {
return new OkhttpMetrics(Preconditions.checkNotNull(registry, "TaggedMetricRegistry"));
}
/**
* Reports the number of queued outgoing requests.
*/
void dispatcherCallsQueued(Gauge extends Number> gauge) {
registry.registerWithReplacement(dispatcherCallsQueuedMetricName(), gauge);
}
static MetricName dispatcherCallsQueuedMetricName() {
return dispatcherCallsQueuedMetricName;
}
/**
* Reports the number of active outgoing requests.
*/
void dispatcherCallsRunning(Gauge extends Number> gauge) {
registry.registerWithReplacement(dispatcherCallsRunningMetricName(), gauge);
}
static MetricName dispatcherCallsRunningMetricName() {
return dispatcherCallsRunningMetricName;
}
/**
* Total number of connections in the connection pool.
*/
void connectionPoolConnectionsTotal(Gauge extends Number> gauge) {
registry.registerWithReplacement(connectionPoolConnectionsTotalMetricName(), gauge);
}
static MetricName connectionPoolConnectionsTotalMetricName() {
return connectionPoolConnectionsTotalMetricName;
}
/**
* Number of idle connections in the connection pool.
*/
void connectionPoolConnectionsIdle(Gauge extends Number> gauge) {
registry.registerWithReplacement(connectionPoolConnectionsIdleMetricName(), gauge);
}
static MetricName connectionPoolConnectionsIdleMetricName() {
return connectionPoolConnectionsIdleMetricName;
}
@Override
public String toString() {
return "OkhttpMetrics{registry=" + registry + '}';
}
}