Class MetricRegistries
java.lang.Object
com.palantir.tritium.metrics.MetricRegistries
Utilities for working with
MetricRegistry instances.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfacestatic interfacestatic interfacestatic interface -
Method Summary
Modifier and TypeMethodDescriptionstatic com.codahale.metrics.MetricRegistryCreate metric registry which produces timers and histograms backed by high dynamic range histograms and timers, that accumulates internal state forever.static com.codahale.metrics.MetricRegistryCreate ametric registrywhich produces timers and histograms backed bylock free expoentially decaying reservoirs.static com.codahale.metrics.MetricRegistrycreateWithSlidingTimeWindowReservoirs(long window, TimeUnit windowUnit) Creates aMetricRegistrywhich produces timers and histograms backed by sliding time window array that store measurements for the specified sliding time window.executor()Returns a builder forExecutorServiceinstrumentation.static ExecutorServiceinstrument(com.palantir.tritium.metrics.registry.TaggedMetricRegistry registry, ExecutorService delegate, @Safe String name) Returns an instrumentedExecutorServicethat monitors the number of tasks submitted, running, completed and also keeps aTimerfor the task duration.static ScheduledExecutorServiceinstrument(com.palantir.tritium.metrics.registry.TaggedMetricRegistry registry, ScheduledExecutorService delegate, @Safe String name) Returns an instrumentedScheduledExecutorServicethat monitors the number of tasks submitted, running, completed and also keeps aTimerfor the task duration.static ThreadFactoryinstrument(com.palantir.tritium.metrics.registry.TaggedMetricRegistry registry, ThreadFactory delegate, @Safe String name) Returns an instrumentedThreadFactorythat monitors the number of created, running, and terminated threads.static SSLContextinstrument(com.palantir.tritium.metrics.registry.TaggedMetricRegistry registry, SSLContext context, @Safe String name) Returns an instrumentedSSLContextthat monitors handshakes and ciphers.static SSLSocketFactoryinstrument(com.palantir.tritium.metrics.registry.TaggedMetricRegistry registry, SSLSocketFactory factory, @Safe String name) Returns an instrumentedSSLSocketFactorythat monitors handshakes and ciphers.metricsMatching(com.codahale.metrics.MetricRegistry metrics, com.codahale.metrics.MetricFilter filter) Returns a sorted map of metrics from the specified registry matching the specified filter.static com.codahale.metrics.MetricFiltermetricsPrefixedBy(@Safe String prefix) Creates aMetricFilterpredicate to match metrics with names starting with the specified prefix.static voidregisterAll(com.palantir.tritium.metrics.registry.TaggedMetricRegistry registry, @Safe String prefix, com.codahale.metrics.MetricSet metricSet) Registers a DropwizardMetricSetwith a TritiumTaggedMetricRegistry.static voidregisterCache(com.codahale.metrics.MetricRegistry registry, com.google.common.cache.Cache<?, ?> cache, @Safe String name) Deprecated.static voidregisterCache(com.palantir.tritium.metrics.registry.TaggedMetricRegistry registry, com.google.common.cache.Cache<?, ?> cache, @Safe String name) Deprecated.Do not use Guava caches, they are outperformed by and harder to use than Caffeine caches.static voidregisterGarbageCollection(com.palantir.tritium.metrics.registry.TaggedMetricRegistry registry) Adds Garbage Collection metrics to the given metric registry.static voidregisterMemoryPools(com.palantir.tritium.metrics.registry.TaggedMetricRegistry registry) Adds memory pool metrics to the given metric registry.static <T extends com.codahale.metrics.Metric>
TregisterSafe(com.codahale.metrics.MetricRegistry registry, @Safe String name, T metric) Ensures aMetricis registered to aMetricRegistrywith the suppliedname.static <T extends com.codahale.metrics.Metric>
TregisterWithReplacement(com.codahale.metrics.MetricRegistry registry, @Safe String name, T metric) static SSLEngineExtracts the wrapped delegate if the inputSSLEngineis instrumented, otherwise returns the input.
-
Method Details
-
createWithHdrHistogramReservoirs
public static com.codahale.metrics.MetricRegistry createWithHdrHistogramReservoirs()Create metric registry which produces timers and histograms backed by high dynamic range histograms and timers, that accumulates internal state forever.- Returns:
- metric registry
-
createWithSlidingTimeWindowReservoirs
public static com.codahale.metrics.MetricRegistry createWithSlidingTimeWindowReservoirs(long window, TimeUnit windowUnit) Creates aMetricRegistrywhich produces timers and histograms backed by sliding time window array that store measurements for the specified sliding time window.See also:
- Parameters:
window- window of timewindowUnit- unit for window- Returns:
- metric registry
-
createWithLockFreeExponentiallyDecayingReservoirs
public static com.codahale.metrics.MetricRegistry createWithLockFreeExponentiallyDecayingReservoirs()Create ametric registrywhich produces timers and histograms backed bylock free expoentially decaying reservoirs.- Returns:
- metric registry
- See Also:
-
metricsPrefixedBy
Creates aMetricFilterpredicate to match metrics with names starting with the specified prefix.- Parameters:
prefix- metric name prefix- Returns:
- metric filter
-
metricsMatching
public static SortedMap<String, com.codahale.metrics.Metric> metricsMatching(com.codahale.metrics.MetricRegistry metrics, com.codahale.metrics.MetricFilter filter) Returns a sorted map of metrics from the specified registry matching the specified filter.- Parameters:
metrics- metric registryfilter- metric filter predicate- Returns:
- sorted map of metrics
-
registerCache
@Deprecated public static void registerCache(com.codahale.metrics.MetricRegistry registry, com.google.common.cache.Cache<?, ?> cache, @Safe @Safe String name) Deprecated.Register specified cache with the given metric registry. Callers should ensure that they haveenabled stats recordingCacheBuilder.newBuilder().recordStats()otherwise there are no cache metrics to register.- Parameters:
registry- metric registrycache- cache to instrumentname- cache name- Throws:
IllegalArgumentException- if name is blank
-
registerCache
@Deprecated public static void registerCache(com.palantir.tritium.metrics.registry.TaggedMetricRegistry registry, com.google.common.cache.Cache<?, ?> cache, @Safe @Safe String name) Deprecated.Do not use Guava caches, they are outperformed by and harder to use than Caffeine caches. Preferandinvalid reference
Caffeine#recordStats(Supplier).invalid reference
CacheStats#of(TaggedMetricRegistry, String)Register specified cache with the given metric registry. Callers should ensure that they haveenabled stats recordingCacheBuilder.newBuilder().recordStats()otherwise there are no cache metrics to register.- Parameters:
registry- metric registrycache- cache to instrumentname- cache name- Throws:
IllegalArgumentException- if name is blank
-
registerGarbageCollection
public static void registerGarbageCollection(com.palantir.tritium.metrics.registry.TaggedMetricRegistry registry) Adds Garbage Collection metrics to the given metric registry.Registers gauges
jvm.gc.count
andjvm.gc.time
tagged with{collector: NAME}.- Parameters:
registry- metric registry
-
registerMemoryPools
public static void registerMemoryPools(com.palantir.tritium.metrics.registry.TaggedMetricRegistry registry) Adds memory pool metrics to the given metric registry.Registers the following metrics, tagged with
{memoryPool: NAME}.- jvm.memory.pools.max
- jvm.memory.pools.used
- jvm.memory.pools.committed
- jvm.memory.pools.init
- jvm.memory.pools.usage
- jvm.memory.pools.used-after-gc (Only for supported pools)
- Parameters:
registry- metric registry
-
instrument
public static ScheduledExecutorService instrument(com.palantir.tritium.metrics.registry.TaggedMetricRegistry registry, ScheduledExecutorService delegate, @Safe @Safe String name) Returns an instrumentedScheduledExecutorServicethat monitors the number of tasks submitted, running, completed and also keeps aTimerfor the task duration. Similar toInstrumentedScheduledExecutorService, but produces tagged metrics to the specifiedTaggedMetricRegistry.- Parameters:
registry- tagged metric registrydelegate- executor service to instrumentname- executor service name- Returns:
- instrumented executor service
-
instrument
public static ExecutorService instrument(com.palantir.tritium.metrics.registry.TaggedMetricRegistry registry, ExecutorService delegate, @Safe @Safe String name) Returns an instrumentedExecutorServicethat monitors the number of tasks submitted, running, completed and also keeps aTimerfor the task duration. Similar toInstrumentedExecutorService, but produces tagged metrics to the specifiedTaggedMetricRegistry.- Parameters:
registry- tagged metric registrydelegate- executor service to instrumentname- executor service name- Returns:
- instrumented executor service
-
instrument
public static ThreadFactory instrument(com.palantir.tritium.metrics.registry.TaggedMetricRegistry registry, ThreadFactory delegate, @Safe @Safe String name) Returns an instrumentedThreadFactorythat monitors the number of created, running, and terminated threads.- Parameters:
registry- tagged metric registrydelegate- Thread factory to instrumentname- Thread factory name- Returns:
- instrumented thread factory
-
instrument
public static SSLContext instrument(com.palantir.tritium.metrics.registry.TaggedMetricRegistry registry, SSLContext context, @Safe @Safe String name) Returns an instrumentedSSLContextthat monitors handshakes and ciphers. A name may be reused across many contexts.- Parameters:
registry- tagged metric registrycontext- ssl context to instrumentname- context name- Returns:
- instrumented ssl context
-
instrument
public static SSLSocketFactory instrument(com.palantir.tritium.metrics.registry.TaggedMetricRegistry registry, SSLSocketFactory factory, @Safe @Safe String name) Returns an instrumentedSSLSocketFactorythat monitors handshakes and ciphers. A name may be reused across many factories.- Parameters:
registry- tagged metric registryfactory- socket factory to instrumentname- socket factory name- Returns:
- instrumented socket factory
-
unwrap
Extracts the wrapped delegate if the inputSSLEngineis instrumented, otherwise returns the input. Some libraries (Conscrypt, for example) useinstanceofchecks and casts to configure specificSSLEngineimplementations. In such cases, it may be necessary to unwrap the instrumented instance.- Parameters:
engine- Engine to unwrap- Returns:
- The delegate instrumented engine, or the input if it is not instrumented
-
registerSafe
public static <T extends com.codahale.metrics.Metric> T registerSafe(com.codahale.metrics.MetricRegistry registry, @Safe @Safe String name, T metric) Ensures aMetricis registered to aMetricRegistrywith the suppliedname. If there is an existingMetricregistered tonamewith the same implemented set of interfaces asmetricthen it's returned. Otherwisemetricis registered and returned.This is intended to imitate the semantics of
MetricRegistry.counter(String)and should only be used forMetricimplementations that can't be registered/created in that manner (because it does not actually guarantee that the registeredMetricmatches the inputmetric).For example, this may be useful for registering
Gauges which might cause issues from being added multiple times to a staticMetricRegistryin a unit test- Throws:
IllegalArgumentException- if there is already aMetricregistered that doesn't implement the same interfaces asmetric
-
registerWithReplacement
public static <T extends com.codahale.metrics.Metric> T registerWithReplacement(com.codahale.metrics.MetricRegistry registry, @Safe @Safe String name, T metric) -
registerAll
public static void registerAll(com.palantir.tritium.metrics.registry.TaggedMetricRegistry registry, @Safe @Safe String prefix, com.codahale.metrics.MetricSet metricSet) Registers a DropwizardMetricSetwith a TritiumTaggedMetricRegistry. Semantics match callingMetricRegistry.register(String, Metric)with aMetricSet.- Parameters:
registry- Target Tritium registryprefix- Metric name prefixmetricSet- Set to register with the tagged registry
-
executor
@CheckReturnValue public static MetricRegistries.ExecutorInstrumentationBuilderRegistryStage executor()Returns a builder forExecutorServiceinstrumentation.
-
registerCache(TaggedMetricRegistry, Cache, String)