-
Notifications
You must be signed in to change notification settings - Fork 798
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ability to filter metrics in DropwizardExports #573
Comments
Fix prometheus#573 Signed-off-by: Vasily Vasilkov <[email protected]>
Add comments Fix prometheus#573 Signed-off-by: Vasily Vasilkov <[email protected]>
Code review fixes Fix prometheus#573 Signed-off-by: Vasily Vasilkov <[email protected]>
Code review fixes, split wildcard import into concrete classes Fix prometheus#573 Signed-off-by: Vasily Vasilkov <[email protected]>
Code review fixes Fix prometheus#573 Signed-off-by: Vasily Vasilkov <[email protected]>
Code review fixes Fix prometheus#573 Signed-off-by: Vasily Vasilkov <[email protected]>
If I understand correctly this fix has not been released. So, bellow is a powerful workaround, that can be used now: public static MetricRegistry decorateMetricRegistryByFilter(MetricRegistry sourceRegistry, MetricFilter filter) {
MetricRegistry decoratedRegistry = new MetricRegistry();
MetricRegistryListener listener = new MetricRegistryListener() {
@Override
public void onGaugeAdded(String name, Gauge<?> gauge) {
if (filter.matches(name, gauge)) {
decoratedRegistry.register(name, gauge);
}
}
@Override
public void onGaugeRemoved(String name) {
decoratedRegistry.remove(name);
}
@Override
public void onCounterAdded(String name, com.codahale.metrics.Counter counter) {
if (filter.matches(name, counter)) {
decoratedRegistry.register(name, counter);
}
}
@Override
public void onCounterRemoved(String name) {
decoratedRegistry.remove(name);
}
@Override
public void onHistogramAdded(String name, Histogram histogram) {
if (filter.matches(name, histogram)) {
decoratedRegistry.register(name, histogram);
}
}
@Override
public void onHistogramRemoved(String name) {
decoratedRegistry.remove(name);
}
@Override
public void onMeterAdded(String name, Meter meter) {
if (filter.matches(name, meter)) {
decoratedRegistry.register(name, meter);
}
}
@Override
public void onMeterRemoved(String name) {
decoratedRegistry.remove(name);
}
@Override
public void onTimerAdded(String name, Timer timer) {
if (filter.matches(name, timer)) {
decoratedRegistry.register(name, timer);
}
}
@Override
public void onTimerRemoved(String name) {
decoratedRegistry.remove(name);
}
};
sourceRegistry.addListener(listener);
return decoratedRegistry;
} Then all we need is passing the decorated registry to the DropwizardExports instead of the original: ...
MetricRegistry decoratedRegistry decorateMetricRegistryByFilter(originalRegistry, metricFilter);
DropwizardExports exports = new DropwizardExports(decoratedRegistry, metricFilter);
... Moreover, performance can be dramatically increased by the snippet above in case if the filter works slowly, for example because the filter computes regexp. Because each filter requires to be applied only once, we are free ещ use even inefficient filtering and forget about filtering costs. |
We are migrating from dropwizard metrics to prometheus right now. We exported all old dropwizard metrics to prometheus and added all metrics to prometheus one by one. However, there is a problem – metric is added to prometheus is exported via DropwizardExports too, so, we see two similar metrics in output.
It will be great if we can filter metrics are exported to Dropwizard by standard MetricFilter mechanism.
The text was updated successfully, but these errors were encountered: