Interface MeterFilter
- All Known Implementing Classes:
OnlyOnceLoggingDenyMeterFilter
public interface MeterFilter
As requests are made of a
MeterRegistry
to create new metrics, allow for filtering out
the metric altogether, transforming its ID (name or tags) in some way, and transforming its
configuration.
All new metrics should pass through each MeterFilter
in the order in which they were added.
-
Method Summary
Modifier and TypeMethodDescriptionstatic MeterFilter
accept()
Include a meter in published metrics.default MeterFilterReply
static MeterFilter
When the given predicate istrue
, the meter should be present in published metrics.static MeterFilter
acceptNameStartsWith
(String prefix) Meters that start with the provided name should be present in published metrics.static MeterFilter
commonTags
(Iterable<Tag> tags) Add common tags that are applied to every meter created afterward.default DistributionStatisticConfig
configure
(Meter.Id id, DistributionStatisticConfig config) This is only called when filtering new timers and distribution summaries (i.e.static MeterFilter
deny()
Reject a meter in published metrics.static MeterFilter
When the given predicate istrue
, the meter should NOT be present in published metrics.static MeterFilter
denyNameStartsWith
(String prefix) Meters that start with the provided name prefix should NOT be present in published metrics.static MeterFilter
denyUnless
(Predicate<Meter.Id> iff) Can be used to build a whitelist of metrics matching certain criteria.static MeterFilter
ignoreTags
(String... tagKeys) Suppress tags with given tag keys.default Meter.Id
static MeterFilter
maxExpected
(String prefix, double max) Set a maximum expected value on anyDistributionSummary
whose name begins with the given prefix.static MeterFilter
maxExpected
(String prefix, long max) Deprecated.static MeterFilter
maxExpected
(String prefix, Duration max) Set a maximum expected value on anyTimer
whose name begins with the given prefix.static MeterFilter
maximumAllowableMetrics
(int maximumTimeSeries) Useful for cost-control in monitoring systems which charge directly or indirectly by the total number of time series you generate.static MeterFilter
maximumAllowableTags
(String meterNamePrefix, String tagKey, int maximumTagValues, MeterFilter onMaxReached) Places an upper bound on the number of tags produced by matching metrics.static MeterFilter
minExpected
(String prefix, double min) Set a minimum expected value on anyDistributionSummary
whose name begins with the given prefix.static MeterFilter
minExpected
(String prefix, long min) Deprecated.UseminExpected(String, double)
instead since 1.4.0.static MeterFilter
minExpected
(String prefix, Duration min) Set a minimum expected value on anyTimer
whose name begins with the given prefix.static MeterFilter
Rename a tag key for every metric beginning with a given prefix.static MeterFilter
Replace tag values according to the provided mapping for all matching tag keys.
-
Method Details
-
commonTags
Add common tags that are applied to every meter created afterward. The common tags will not override tag values from a meter ID. They will also not override previously configured common tag MeterFilters that have the same tag key.- Parameters:
tags
- Common tags.- Returns:
- A common tag filter.
-
renameTag
Rename a tag key for every metric beginning with a given prefix.- Parameters:
meterNamePrefix
- Apply filter to metrics that begin with this name.fromTagKey
- Rename tags matching this key.toTagKey
- Rename to this key.- Returns:
- A tag-renaming filter.
-
ignoreTags
Suppress tags with given tag keys.- Parameters:
tagKeys
- Keys of tags that should be suppressed.- Returns:
- A tag-suppressing filter.
-
replaceTagValues
static MeterFilter replaceTagValues(String tagKey, Function<String, String> replacement, String... exceptions) Replace tag values according to the provided mapping for all matching tag keys. This can be used to reduce the total cardinality of a tag by mapping some portion of tag values to something else.- Parameters:
tagKey
- The tag key for which replacements should be madereplacement
- The value to replace withexceptions
- All matching tags with this value to retain its original value- Returns:
- A filter that replaces tag values.
-
denyUnless
Can be used to build a whitelist of metrics matching certain criteria. Opposite ofdeny(Predicate)
.- Parameters:
iff
- When a meter id matches, allow its inclusion, otherwise deny.- Returns:
- A meter filter that whitelists metrics matching a predicate.
-
accept
When the given predicate istrue
, the meter should be present in published metrics.- Parameters:
iff
- When a meter id matches, guarantee its inclusion in published metrics.- Returns:
- A filter that guarantees the inclusion of matching meters.
-
deny
When the given predicate istrue
, the meter should NOT be present in published metrics. Opposite ofdenyUnless(Predicate)
.- Parameters:
iff
- When a meter id matches, guarantee its exclusion in published metrics.- Returns:
- A filter that guarantees the exclusion of matching meters.
-
accept
Include a meter in published metrics. Can be used as a subordinate action on another filter likemaximumAllowableTags(java.lang.String, java.lang.String, int, io.micrometer.core.instrument.config.MeterFilter)
.- Returns:
- A filter that guarantees the inclusion of all meters.
-
deny
Reject a meter in published metrics. Can be used as a subordinate action on another filter likemaximumAllowableTags(java.lang.String, java.lang.String, int, io.micrometer.core.instrument.config.MeterFilter)
.- Returns:
- A filter that guarantees the exclusion of all meters.
-
maximumAllowableMetrics
Useful for cost-control in monitoring systems which charge directly or indirectly by the total number of time series you generate.While this filter doesn't discriminate between your most critical and less useful metrics in deciding what to drop (all the metrics you intend to use should fit below this threshold), it can effectively cap your risk of an accidentally high-cardinality metric costing too much.
- Parameters:
maximumTimeSeries
- The total number of unique name/tag permutations allowed before filtering kicks in.- Returns:
- A filter that globally limits the number of unique name and tag combinations.
-
maximumAllowableTags
static MeterFilter maximumAllowableTags(String meterNamePrefix, String tagKey, int maximumTagValues, MeterFilter onMaxReached) Places an upper bound on the number of tags produced by matching metrics.- Parameters:
meterNamePrefix
- Apply filter to metrics that begin with this name.tagKey
- The tag to place an upper bound on.maximumTagValues
- The total number of tag values that are allowable.onMaxReached
- After the maximum number of tag values have been seen, apply this filter.- Returns:
- A meter filter that limits the number of tags produced by matching metrics.
-
denyNameStartsWith
Meters that start with the provided name prefix should NOT be present in published metrics.- Parameters:
prefix
- When a meter name starts with the prefix, guarantee its exclusion in published metrics.- Returns:
- A filter that guarantees the exclusion of matching meters.
-
acceptNameStartsWith
Meters that start with the provided name should be present in published metrics.- Parameters:
prefix
- When a meter name starts with the prefix, guarantee its inclusion in published metrics.- Returns:
- A filter that guarantees the inclusion of matching meters.
- Since:
- 1.2.0
-
maxExpected
Set a maximum expected value on anyTimer
whose name begins with the given prefix.- Parameters:
prefix
- Apply the maximum only to timers whose name begins with this prefix.max
- The maximum expected value of the timer.- Returns:
- A filter that applies a maximum expected value to a timer.
-
maxExpected
Deprecated.UsemaxExpected(String, double)
instead since 1.4.0.Set a maximum expected value on anyDistributionSummary
whose name begins with the given prefix.- Parameters:
prefix
- Apply the maximum only to distribution summaries whose name begins with this prefix.max
- The maximum expected value of the distribution summary.- Returns:
- A filter that applies a maximum expected value to a distribution summary.
-
maxExpected
Set a maximum expected value on anyDistributionSummary
whose name begins with the given prefix.- Parameters:
prefix
- Apply the maximum only to distribution summaries whose name begins with this prefix.max
- The maximum expected value of the distribution summary.- Returns:
- A filter that applies a maximum expected value to a distribution summary.
- Since:
- 1.4.0
-
minExpected
Set a minimum expected value on anyTimer
whose name begins with the given prefix.- Parameters:
prefix
- Apply the minimum only to timers whose name begins with this prefix.min
- The minimum expected value of the timer.- Returns:
- A filter that applies a minimum expected value to a timer.
-
minExpected
Deprecated.UseminExpected(String, double)
instead since 1.4.0.Set a minimum expected value on anyDistributionSummary
whose name begins with the given prefix.- Parameters:
prefix
- Apply the minimum only to distribution summaries whose name begins with this prefix.min
- The minimum expected value of the distribution summary.- Returns:
- A filter that applies a minimum expected value to a distribution summary.
-
minExpected
Set a minimum expected value on anyDistributionSummary
whose name begins with the given prefix.- Parameters:
prefix
- Apply the minimum only to distribution summaries whose name begins with this prefix.min
- The minimum expected value of the distribution summary.- Returns:
- A filter that applies a minimum expected value to a distribution summary.
- Since:
- 1.4.0
-
accept
- Parameters:
id
- Id withmap(io.micrometer.core.instrument.Meter.Id)
transformations applied.- Returns:
- After all transformations, should a real meter be registered for this id, or should it be no-op'd.
-
map
- Parameters:
id
- Id to transform.- Returns:
- Transformations to any part of the id.
-
configure
@Nullable default DistributionStatisticConfig configure(Meter.Id id, DistributionStatisticConfig config) This is only called when filtering new timers and distribution summaries (i.e. those meter types that useDistributionStatisticConfig
).- Parameters:
id
- Id withmap(io.micrometer.core.instrument.Meter.Id)
transformations applied.config
- A histogram configuration guaranteed to be non-null.- Returns:
- Overrides to any part of the histogram config, when applicable.
-
maxExpected(String, double)
instead since 1.4.0.