Java Spring boot metrics+;数据狗

Java Spring boot metrics+;数据狗,java,spring-boot,spring-boot-actuator,datadog,metrics-spring,Java,Spring Boot,Spring Boot Actuator,Datadog,Metrics Spring,有人知道如何将Spring引导指标与datadog集成吗 是一种云级别的IT监控服务 它允许用户使用大量的图表和图形轻松地可视化他们的数据 我有一个spring boot应用程序,它使用度量来填充我用@Timed注释的所有方法的大量信息 另一方面,我正在heroku中部署应用程序,因此无法安装Datadog代理 我想知道是否有一种方法可以自动将spring boot metric system reporting与datadog集成。我终于找到了一个dropwizzard模块,该模块将此库与da

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

是一种云级别的IT监控服务

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

我有一个spring boot应用程序,它使用度量来填充我用
@Timed
注释的所有方法的大量信息

另一方面,我正在heroku中部署应用程序,因此无法安装Datadog代理


我想知道是否有一种方法可以自动将spring boot metric system reporting与datadog集成。

我终于找到了一个dropwizzard模块,该模块将此库与datadog集成:

我已经创建了一个Spring配置类,它使用我的YAML属性创建并初始化这个报告程序

只需在pom中插入此依赖项:

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

org.coursera
dropwizard度量数据狗
1.1.3
将此配置添加到YAML:

yourapp:
  metrics:
    apiKey: <your API key>
    host: <your host>
    period: 10
    enabled: true
yourapp:
韵律学:
apiKey:
主持人:
期间:10
已启用: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;
  }
}
/**
*这个bean将创建并配置一个DatadogReporter,负责发送数据
*Spring启动执行器系统收集到的所有指标都将发送给Datadog。
*     
*@见https://www.datadoghq.com/
*@作者jfcorugedo
*
*/
@配置
@ConfigurationProperties(“yourapp.metrics”)
公共类DatadogReporterConfig{
私有静态最终记录器Logger=LoggerFactory.getLogger(DatadogReporterConfig.class);
/**Datadog API密钥,用于验证对Datadog API的每个请求*/
私钥;
/**与此应用程序发送的所有事件关联的逻辑名称*/
私有字符串主机;
/**每次调用Datadog API之间的时间,以秒为单位。此值越低,发送给Datadog的信息越多*/
私人长期;
/**此标志启用或禁用datadog reporter*/
启用私有布尔值=false;
@豆子
@自动连线
公共DatadogReporter DatadogReporter(MetricRegistry注册表){
DatadogReporter=null;
如果(已启用){
reporter=enableDatadogMetrics(注册表);
}否则{
if(LOGGER.iswarnabled()){
info(“Datadog reporter已禁用。要启用此功能,只需在配置文件(属性或YAML)中设置'rJavaServer.metrics.enabled:true');
}
}
回归记者;
}
专用DatadogReporter启用DataDogMetrics(MetricRegistry注册表){
如果(LOGGER.IsInfo已启用()){
info(“使用[host:{},period(seconds):{},api键:{}]”,getHost(),getPeriod(),getApiKey()初始化Datadog reporter);
}
EnumSet expansions=DatadogReporter.Expansion.ALL;
HttpTransport HttpTransport=新的HttpTransport
.Builder()
.withApiKey(getApiKey())
.build();
DatadogReporter=DatadogReporter.forRegistry(注册表)
.withHost(getHost())
.withTransport(httpTransport)
.带扩展(扩展)
.build();
reporter.start(getPeriod(),TimeUnit.SECONDS);
如果(LOGGER.IsInfo已启用()){
LOGGER.info(“Datadog reporter已成功初始化”);
}
回归记者;
}
/**
*@return-Datadog-API密钥,用于验证每个对Datadog-API的请求
*/
公共字符串getApiKey(){
返回apiKey;
}
/**
*@param-apiKey-Datadog-API-key用于验证对Datadog-API的每个请求
*/
public void setApiKey(字符串apiKey){
this.apiKey=apiKey;
}
/**
*@return与此应用程序发送的所有事件关联的逻辑名称
*/
公共字符串getHost(){
返回主机;
}
/**
*@param主机逻辑名称与此应用程序发送的所有事件关联
*/
公共void setHost(字符串主机){
this.host=host;
}
/**
*@每次调用Datadog API之间的返回时间(秒)。此值越低,发送给Datadog的信息越多
*/
公共长周期(){
重现期;
}
/**
*@param period每次调用Datadog API之间的时间,以秒为单位。此值越低,发送给Datadog的信息越多
*/
公共无效设置周期(长周期){
这个周期=周期;
}
/**
*@如果在此应用程序中启用DatadogReporter,则返回true
*/
公共布尔值isEnabled(){
返回启用;
}
/**
*此标志启用或禁用datadog reporter。
*此标志仅在初始化期间读取,对该值的后续更改将不会生效
*@param已启用
*/
已启用公共void集(已启用布尔值){
this.enabled=已启用;
}
}

如果JMX是您的一个选项,您可以使用与

相结合的方法。Spring Boot 2.x似乎在其指标中添加了几个监控系统。DataDog是受支持的其中之一。见参考文件:

对于Spring Boot 1.x,您可以使用后端口包:


编译“io.Millomer:Millomer spring legacy:latest.release”

这是一个很好的观点。但是,我正在heroku中部署我的应用程序,因此无法在中安装datadog代理OS@jfcorugedo我不认为这个问题提到了任何关于heroku的事情?如果需要heroku解决方案,您需要将其添加到问题中。这似乎也是一个很好的经济理由——您可以免费获得每个实例350个指标。如果您的应用程序将其所有度量值注入DataDog(例如,使用
dropwizard metrics DataDog
),则这些度量值将计入您的自定义使用限制-使用集成可显著减少影响。也可以使用相同的库来进行StatsD报告,而不是HTTP,如果有人对这个选项感兴趣,你是否需要编写一个调度程序,因为添加给定的资源