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.
|
ConfigMap |
Configuration settings.
|
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.
|
Predicate<T> |
Boolean valued function for a single argument.
|
Registry |
Registry to manage a set of meters.
|
Tag |
Key/value pair used to classify and drill into measurements.
|
Timer |
Timer intended to track a large number of short running events.
|
ValueFunction |
Function to extract a double value from an object.
|
Class | Description |
---|---|
AbstractConfigMap |
Base class for
ConfigMap implementations. |
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.
|
DefaultId |
Id implementation for the default registry.
|
DefaultRegistry |
Default implementation of registry.
|
DoubleFunction |
Function to extract a double value from an object.
|
ExtendedRegistry |
Wraps a registry and provides additional helper methods to make it easier to use.
|
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.
|
SystemConfigMap |
Get configuration settings using
System.getProperty(String) . |
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(Spectator.registry()); class Server { private final ExtendedRegistry registry; private final Id requestCountId; private final Timer requestLatency; private final DistributionSummary responseSizes; public Server(ExtendedRegistry registry) { this.registry = registry; requestCountId = registry.createId("server.requestCount"); requestLatency = registry.timer("server.requestLatency"); responseSizes = registry.distributionSummary("server.responseSizes"); registry.methodValue("server.numConnections", this, "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.ExtendedRegistry
: 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.