Spring boot metrics + datadog

Does anyone know how to integrate Spring boot metrics with datadog?

Datadog is a cloud computing monitoring service for IT.

This allows users to easily visualize their data using a variety of charts and graphs.

I have a Spring boot application that uses dropwizard metrics to populate a lot of information about all the methods that I annotated using @Timed .

On the other hand, I am deploying my application in heroku, so I cannot install the Datadog agent.

I want to know if there is a way to automatically integrate Spring boot system reporting with datadog.

+5
source share
3 answers

I finally found a dropwizzard module that integrates this library with datadog: metrics-datadog

I created a Spring configuration class that creates and initializes this reporter using the properties of my YAML.

Just paste this dependency into your pom:

  <!-- Send metrics to Datadog --> <dependency> <groupId>org.coursera</groupId> <artifactId>dropwizard-metrics-datadog</artifactId> <version>1.1.3</version> </dependency> 

Add this configuration to your YAML:

 yourapp: metrics: apiKey: <your API key> host: <your host> period: 10 enabled: true 

and add this configuration class to your project:

 /** * This bean will create and configure a DatadogReporter that will be in charge of sending * all the metrics collected by Spring Boot actuator system to Datadog. * * @see https://www.datadoghq.com/ * @author jfcorugedo * */ @Configuration @ConfigurationProperties("yourapp.metrics") public class DatadogReporterConfig { private static final Logger LOGGER = LoggerFactory.getLogger(DatadogReporterConfig.class); /** Datadog API key used to authenticate every request to Datadog API */ private String apiKey; /** Logical name associated to all the events send by this application */ private String host; /** Time, in seconds, between every call to Datadog API. The lower this value the more information will be send to Datadog */ private long period; /** This flag enables or disables the datadog reporter */ private boolean enabled = false; @Bean @Autowired public DatadogReporter datadogReporter(MetricRegistry registry) { DatadogReporter reporter = null; if(enabled) { reporter = enableDatadogMetrics(registry); } else { if(LOGGER.isWarnEnabled()) { LOGGER.info("Datadog reporter is disabled. To turn on this feature just set 'rJavaServer.metrics.enabled:true' in your config file (property or YAML)"); } } return reporter; } private DatadogReporter enableDatadogMetrics(MetricRegistry registry) { if(LOGGER.isInfoEnabled()) { LOGGER.info("Initializing Datadog reporter using [ host: {}, period(seconds):{}, api-key:{} ]", getHost(), getPeriod(), getApiKey()); } EnumSet<Expansion> expansions = DatadogReporter.Expansion.ALL; HttpTransport httpTransport = new HttpTransport .Builder() .withApiKey(getApiKey()) .build(); DatadogReporter reporter = DatadogReporter.forRegistry(registry) .withHost(getHost()) .withTransport(httpTransport) .withExpansions(expansions) .build(); reporter.start(getPeriod(), TimeUnit.SECONDS); if(LOGGER.isInfoEnabled()) { LOGGER.info("Datadog reporter successfully initialized"); } return reporter; } /** * @return Datadog API key used to authenticate every request to Datadog API */ public String getApiKey() { return apiKey; } /** * @param apiKey Datadog API key used to authenticate every request to Datadog API */ public void setApiKey(String apiKey) { this.apiKey = apiKey; } /** * @return Logical name associated to all the events send by this application */ public String getHost() { return host; } /** * @param host Logical name associated to all the events send by this application */ public void setHost(String host) { this.host = host; } /** * @return Time, in seconds, between every call to Datadog API. The lower this value the more information will be send to Datadog */ public long getPeriod() { return period; } /** * @param period Time, in seconds, between every call to Datadog API. The lower this value the more information will be send to Datadog */ public void setPeriod(long period) { this.period = period; } /** * @return true if DatadogReporter is enabled in this application */ public boolean isEnabled() { return enabled; } /** * This flag enables or disables the datadog reporter. * This flag is only read during initialization, subsequent changes on this value will no take effect * @param enabled */ public void setEnabled(boolean enabled) { this.enabled = enabled; } } 
+8
source

If JMX is an option for you, you can use the JMX dropwizrd reporter in conjunction with java datalog integration

+2
source

It seems that Spring Boot 2.x has added several monitoring systems to its metrics. DataDog is one of them supported by micrometer.io . See Help documentation: https://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-metrics.html#production-ready-metrics-export-newrelic

For Spring Boot 1.x, you can use the reverse port package:

compile 'io.micrometer:micrometer-spring-legacy:latest.release'

+1
source

Source: https://habr.com/ru/post/1238852/


All Articles