0
votes

I want to disable all builtin metrics (jvm, cpu, etc) but keep my custom metrics.

When I enabled Spring Boot Actuator metrics together with Datadog I end up with +320 metrics sent to datadog. Most of these metrics are from the builtin core metrics (JVM metrics, CPU metrics, File description metrics) only 5 of those metrics are my custom metrics that are the ones that I want to send to datadog.

According to this section of the Spring Boot documentation:

Spring Boot also configures built-in instrumentation (i.e. MeterBinder implementations) that you can control via configuration or dedicated annotation markers

but there is no direct example on how to exclude the those metrics

From what I found in this other SO question one way to control it is:

management.metrics.enable.all=false
management.metrics.enable.jvm=true

and that removes all the metrics except the JVM ones. But it also removes my custom metrics.

I don't see how can I reenable my custom metrics.

Just for the record the way I register the custom metrics is this way:

    @Autowired
    public void setMeterRegistry(MeterRegistry registry) {
        this.meterRegistry = registry;
    }

    ....
    Counter n_event_in = this.meterRegistry.counter("n_events_in");

This works ok, as long as `management.metrics.enable.all=true

So how can I disable all core metrics , but keep my custom metrics?

1
Please walk me through how to enable actuator metrics together with datadog and get it on UI? I am getting exceptions like text cannot be parsed to duration inspite of giving proper seconds value in step. Or with another way, I get datadog missing exception.esha ingle

1 Answers

0
votes

Your metrics should have a common prefix like myapp.metric1, myapp.metric2, etc. Then you can disable all metrics and enable explicitly all myapp.* metrics like so:

application.properties:

management.metrics.enable.all=false
management.metrics.enable.myapp=true

the management.metrics.enable.<your_custom_prefix> will enable all <your_custome_prefix>.* metrics.

If you want to enable some of the built-in core metrics again, for example reenabling jvm.*, you can do:

management.metrics.enable.all=false
management.metrics.enable.myapp=true
management.metrics.enable.jvm=true

I've created a sample project in github that disables core metrics, enables custom metrics, and jvm.* metrics and sends to Datadog.