Interface | Description |
---|---|
Clock |
A timing source that can be used to access the current wall time as well as a high resolution
monotonic time to measuring elapsed times.
|
Counter |
Measures the rate of change based on calls to increment.
|
DistributionSummary |
Track the sample distribution of events.
|
Gauge |
A meter with a single value that can only be sampled at a point in time.
|
Id |
Identifier for a meter or measurement.
|
LongTaskTimer |
Timer intended to track a small number of long running tasks.
|
Meter |
A device for collecting a set of measurements.
|
Registry |
Registry to manage a set of meters.
|
RegistryConfig |
Configuration settings for the registry.
|
Tag |
Key/value pair used to classify and drill into measurements.
|
TagList |
Base type for a collection of tags.
|
Timer |
Timer intended to track a large number of short running events.
|
Class | Description |
---|---|
AbstractMeter<T> |
Helper base class for meters that maintains a weak reference to the object being measured.
|
AbstractRegistry |
Base class to make it easier to implement a simple registry that only needs to customise the
types returned for Counter, DistributionSummary, and Timer calls.
|
AbstractTimer |
Base class to simplify implementing a
Timer . |
BasicTag |
Immutable implementation of Tag.
|
CompositeRegistry |
Maps calls to zero or more sub-registries.
|
DefaultRegistry |
Default implementation of registry.
|
DoubleFunction<T extends java.lang.Number> |
Function to extract a double value from an object.
|
ExtendedRegistry | Deprecated
This class was used prior to java 8 for adding extension methods to the registry
without breaking all classes implementing the interface.
|
Functions |
Common functions for use with gauges.
|
ManualClock |
Clock implementation that allows the user to explicitly control the time.
|
Measurement |
A measurement sampled from a meter.
|
NoopRegistry |
Registry implementation that does nothing.
|
Spectator |
Static factory used to access the main global registry.
|
Utils |
Helper functions for working with a sequence of measurements.
|
Enum | Description |
---|---|
Statistic |
The valid set of statistics that can be reported by timers and distribution summaries.
|
Server s = new Server(new DefaultRegistry()); class Server { private final Registry registry; private final Id requestCountId; private final Timer requestLatency; private final DistributionSummary responseSizes; public Server(Registry registry) { this.registry = registry; requestCountId = registry.createId("server.requestCount"); requestLatency = registry.timer("server.requestLatency"); responseSizes = registry.distributionSummary("server.responseSizes"); registry.gauge("server.numConnections", this, Server::getNumConnections); } public Response handle(Request req) { final long s = System.nanoTime(); try { Response res = doSomething(req); final Id cntId = requestCountId .withTag("country", req.country()) .withTag("status", res.status()); registry.counter(cntId).increment(); responseSizes.record(res.body().size()); return res; } catch (Exception e) { final Id cntId = requestCountId .withTag("country", req.country()) .withTag("status", "exception") .withTag("error", e.getClass().getSimpleName()); registry.counter(cntId).increment(); throw e; } finally { requestLatency.record(System.nanoTime() - s, TimeUnit.NANOSECONDS); } } public int getNumConnections() { // however we determine the current number of connections on the server } }The main classes you will need to understand:
Spectator
: static entrypoint to access the registry.Registry
: registry class used to create meters.Counter
: meter type for measuring a rate of change.Timer
: meter type for measuring the time for many short
events.LongTaskTimer
: meter type for measuring the time for a
few long events.DistributionSummary
: meter type for measuring the sample
distribution of some type of events.