【问题标题】:Spring boot metrics + datadog春季启动指标+数据狗
【发布时间】:2016-03-27 16:55:37
【问题描述】:

有人知道如何将 Spring 引导指标与 datadog 集成吗?

Datadog 是面向 IT 的云级监控服务。

它允许用户使用大量图表和图形轻松地可视化他们的数据。

我有一个 Spring Boot 应用程序,它使用 dropwizard 指标来填充关于我用 @Timed 注释的所有方法的大量信息。

另一方面,我在 heroku 中部署我的应用程序,所以我无法安装 Datadog 代理。

我想知道是否有办法自动将spring boot metric系统报告与datadog集成。

【问题讨论】:

    标签: java spring-boot spring-boot-actuator datadog metrics-spring


    【解决方案1】:

    Spring Boot 2.x 似乎在其指标中添加了几个监控系统。 DataDog 是micrometer.io 支持的其中之一。参见参考文档:https://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-metrics.html#production-ready-metrics-export-newrelic

    对于 Spring Boot 1.x,您可以使用反向移植包:

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

    【讨论】:

    • 嘿,spring boot 2 与 datadog 代理 5 一起工作吗?因为我已将我的应用程序升级到 spring boot 2,现在我的 datadog 中没有任何指标!我需要改变什么吗?我听说 datadog 不支持 netty 我对 APM 指标有疑问
    • 同样的问题...spring boot 2 应用程序说它只提交 jdbc 和池指标,甚至那些我在 datadog gui 中看不到的指标。
    • @Marc,您是否将 management.metrics.export.datadog.enabled 设置为 true?您可能需要实现指标配置和计量服务
    【解决方案2】:

    如果您可以选择 JMX,您可以将 JMX dropwizrd reporterjava datalog integration 结合使用

    【讨论】:

    • 这很好。但是我在 heroku 中部署我的应用程序,所以我无法在操作系统中安装 datadog 代理
    • @jfcorugedo 我认为这个问题没有提到关于heroku的任何内容?如果需要 heroku 解决方案,您需要将其添加到问题中。
    • 这种方式似乎也有一个很好的经济论据 - 每个实例免费获得 350 个指标。如果您的应用程序将其所有指标注入 DataDog(例如使用 dropwizard-metrics-datadog),这些指标将计入您的自定义使用限制 - 使用集成可显着减少影响。
    【解决方案3】:

    我终于找到了一个将这个库与 datadog 集成的 dropwizzard 模块:metrics-datadog

    我创建了一个 Spring 配置类,它使用我的 YAML 的属性创建和初始化这个 Reporter。

    只需在你的 pom 中插入这个依赖项:

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

    将此配置添加到您的 YAML:

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

    并将这个配置类添加到您的项目中:

    /**
     * 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;
      }
    }
    

    【讨论】:

    • 如果有人对此选项感兴趣,也可以使用相同的库而不是 HTTP 来进行 StatsD 报告。
    • 您是否需要编写调度程序,因为添加给定资源对我来说不起作用。
    猜你喜欢
    • 2015-04-18
    • 2019-04-18
    • 2020-08-19
    • 2017-09-11
    • 2015-04-18
    • 2017-06-24
    • 2015-08-22
    • 2015-09-18
    • 2015-03-20
    相关资源
    最近更新 更多