Class MetricsRegistry
- All Implemented Interfaces:
Metrics
Metrics implementation with a bounded number of series. Use it to assert on
measurements in tests, or render it with PrometheusText for a scrape endpoint.
Recording is lock-free and allocation-free: counters and gauges are LongAdders and a
timer adds to one of a fixed set of bucket adders. Looking an instrument up takes a lock the
first time a series is created. The registry is thread-safe; readers see each value as it is
updated, so a read taken while requests are in flight is not an atomic snapshot across series.
Cardinality. The registry keeps at most maxSeries distinct
name-and-tag combinations. Once the limit is reached, a request for a further new series gets a
working instrument that is not stored, and droppedSeries() counts the request, so an
application bug that puts user input into a tag cannot exhaust memory. Existing series keep
recording. Tag values longer than 256 characters are truncated.
Histograms and help. Timers are histograms with DEFAULT_BUCKETS
unless MetricsRegistry.Builder.timerBuckets sets other bounds, for every timer or for one name. The
registry keeps no quantiles and no exemplars: a histogram lets the monitoring system derive
quantiles across instances, and an exemplar would need a per-request identifier that must never
be a tag. MetricsRegistry.Builder.help gives a metric text for the exposition's # HELP line.
Consistency. A metric name always has one kind (counter, gauge or timer) and
one set of tag keys; using it differently fails with IllegalArgumentException.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classSettings of aMetricsRegistry.static final recordA timer's totals.Nested classes/interfaces inherited from interface com.jsgalactic.axiom.observability.Metrics
Metrics.Counter, Metrics.Gauge, Metrics.Timer -
Field Summary
FieldsModifier and TypeFieldDescriptionTimer bucket upper bounds used unless a timer is configured otherwise: 1 ms, 5 ms, 10 ms, 25 ms, 50 ms, 100 ms, 250 ms, 500 ms, 1 s, 2.5 s, 5 s and 10 s.static final intSeries limit ofcreate().static final intMost upper bounds one timer may have, not counting the implicit final bucket.static final intLongest help text.static final intLongest metric name.static final intLongest stored tag value; longer values are truncated. -
Method Summary
Modifier and TypeMethodDescriptionstatic MetricsRegistry.Builderbuilder()Starts a registry with explicit settings: the series limit, the histogram buckets of all timers or of one timer, and help text.Returns the monotonically increasing counter for a series, creating it if needed.longcounterValue(String name, String... tags) Reads a counter.static MetricsRegistrycreate()Creates a registry that keeps up toDEFAULT_MAX_SERIESseries.static MetricsRegistrycreate(int maxSeries) Creates a registry with an explicit series limit.longReturns how many lookups asked for a new series after the limit was reached.Returns the gauge for a series, creating it if needed.longgaugeValue(String name, String... tags) Reads a gauge.Returns the help text of a metric.Optional Prometheus text exposition (format 0.0.4) of this implementation's series.intReturns how many distinct series are stored.Returns the timer for a series, creating it if needed.timerBuckets(String name) Returns a timer's bucket upper bounds.timerSnapshot(String name, String... tags) Reads a timer.
-
Field Details
-
DEFAULT_MAX_SERIES
public static final int DEFAULT_MAX_SERIESSeries limit ofcreate().- See Also:
-
MAX_VALUE_LENGTH
public static final int MAX_VALUE_LENGTHLongest stored tag value; longer values are truncated.- See Also:
-
MAX_NAME_LENGTH
public static final int MAX_NAME_LENGTHLongest metric name.- See Also:
-
MAX_BUCKETS
public static final int MAX_BUCKETSMost upper bounds one timer may have, not counting the implicit final bucket.- See Also:
-
MAX_HELP_LENGTH
public static final int MAX_HELP_LENGTHLongest help text.- See Also:
-
DEFAULT_BUCKETS
Timer bucket upper bounds used unless a timer is configured otherwise: 1 ms, 5 ms, 10 ms, 25 ms, 50 ms, 100 ms, 250 ms, 500 ms, 1 s, 2.5 s, 5 s and 10 s. An implicit final bucket holds everything larger.
-
-
Method Details
-
builder
Starts a registry with explicit settings: the series limit, the histogram buckets of all timers or of one timer, and help text.- Returns:
- a new builder with the defaults of
create()
-
create
Creates a registry that keeps up toDEFAULT_MAX_SERIESseries.- Returns:
- an empty registry
-
create
Creates a registry with an explicit series limit.- Parameters:
maxSeries- most distinct name-and-tag combinations to keep, at least one- Returns:
- an empty registry
- Throws:
IllegalArgumentException- if the limit is below one
-
counter
Description copied from interface:MetricsReturns the monotonically increasing counter for a series, creating it if needed. -
gauge
Description copied from interface:MetricsReturns the gauge for a series, creating it if needed. A gauge is a value that moves both ways, such as a queue depth. It is changed by deltas, so several components can share one series and the value stays the sum of their contributions. -
timer
Description copied from interface:MetricsReturns the timer for a series, creating it if needed. A timer records durations and keeps their distribution, so latency percentiles can be derived from it. -
prometheusText
Description copied from interface:MetricsOptional Prometheus text exposition (format 0.0.4) of this implementation's series. The management listener's/metricsendpoint calls this on every scrape; the runtime caps the returned text at the configured response limit. The default is empty: an implementation that does not expose text serves an empty scrape.MetricsRegistryinaxiom-metricsoverrides this withPrometheusText.render(this); no rendering code or third-party type enters core.- Specified by:
prometheusTextin interfaceMetrics- Returns:
- exposition text, or empty when this implementation has no text form
-
counterValue
Reads a counter.- Parameters:
name- metric nametags- alternating tag keys and values- Returns:
- its value, or zero if the series does not exist
-
gaugeValue
Reads a gauge.- Parameters:
name- metric nametags- alternating tag keys and values- Returns:
- its value, or zero if the series does not exist
-
timerSnapshot
Reads a timer.- Parameters:
name- metric nametags- alternating tag keys and values- Returns:
- its observation count and total, or zeros if the series does not exist
-
seriesCount
public int seriesCount()Returns how many distinct series are stored.- Returns:
- series count, at most the limit
-
droppedSeries
public long droppedSeries()Returns how many lookups asked for a new series after the limit was reached.- Returns:
- number of refused series creations
-
help
Returns the help text of a metric.- Parameters:
name- metric name- Returns:
- the text given to
MetricsRegistry.Builder.help, or empty
-
timerBuckets
Returns a timer's bucket upper bounds.- Parameters:
name- metric name- Returns:
- the configured bounds in ascending order, or the registry default
-