Search code examples
restcustomizationmetricsdropwizardhealth-check

Dropwizard Rest Application. How to view only my custom metrics


Hello Rest Api lovers !!

I created a DropWizard basic rest application. I would like to view metrics but ONLY MY CUSTOM ONES and not dropwizard api's. how can i disable dropwizard's healtCheks and Metrics and only view mines (the custum ones). I hope it is clear....


Solution

    1. If you are concerned about the "view" part of metrics/healthchecks, you can set filter that will apply when data is returned. It can be done on start of an application:
    environment.getAdminContext().setAttribute(MetricsServlet.METRIC_FILTER, new MetricFilter() {
       @Override
       public boolean matches(final String name, final Metric metric) {
           return // you logic;
       }
    });
    environment.getAdminContext().setAttribute(HealthCheckServlet.HEALTH_CHECK_FILTER, new HealthCheckFilter() {
       @Override
       public boolean matches(final String s, final HealthCheck healthCheck) {
           return // you logic;
       }
    });
    
    1. If you don't want to have metrics/healthchecks at all, you can directly remove them:
    environment.healthChecks().unregister();
    environment.metrics().remove();