Skip to content

Commit 134a917

Browse files
committed
feat(metrics): add registry-level metric name filter functionality
Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com>
1 parent 56f4a22 commit 134a917

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

docs/content/getting-started/registry.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,27 @@ and full label-schema validation and duplicate detection still apply. A collecto
9696
non-null type but leaves `getLabelNames()` as `null` is still validated, with its labels treated as
9797
empty.
9898

99+
## Filtering Metrics
100+
101+
You can set a registry-level metric name filter that applies to all scrape operations.
102+
Only metrics whose names match the filter predicate will be included in scrape results:
103+
104+
```java
105+
PrometheusRegistry.defaultRegistry.setMetricFilter(name -> !name.startsWith("debug_"));
106+
```
107+
108+
The registry filter is AND-combined with any scrape-time `includedNames` predicate passed to
109+
`scrape(Predicate)`. For example, if the registry filter allows `counter_*` and the scrape-time
110+
filter allows `counter_a`, only `counter_a` will be included.
111+
112+
To remove the filter, set it to `null`:
113+
114+
```java
115+
PrometheusRegistry.defaultRegistry.setMetricFilter(null);
116+
```
117+
118+
Note that `clear()` does not reset the metric filter -- it only removes registered collectors.
119+
99120
## Unregistering a Metric
100121

101122
There is no automatic expiry of unused metrics (yet), once a metric is registered it will remain

0 commit comments

Comments
 (0)