标签: spring-boot-actuator

使用Dropwizard导出Spring Boot Actuator Metrics到Jmx或Graphite

我想使用Spring Boot MetricsWriter将我的Spring Boot应用程序中的数据写入/导出到我选择的数据源(比如-Jmx/Graphite).我可以使用JmxReporter/ GraphiteReporter,但我想Spring的抽象Writer/ Exporter可以在以后的数据源更改方面发挥重要作用.

我的REST端点使用Dropwizard注释进行注释

@Timed(absolute=true, name="invokeEndpoint")
public ResponseEntity<Object> callSomeApi() {
   ...
}
Run Code Online (Sandbox Code Playgroud)

我的配置类如下所示:

@Configuration
public class SpringBootMetrics {

    @Bean
    @ExportMetricReader
    public MetricReader metricReader() {
        return new MetricRegistryMetricReader(metricRegistry());
    }   

    public MetricRegistry metricRegistry() {
        final MetricRegistry metricRegistry = new MetricRegistry();
        return metricRegistry;
    }

    @Bean
    @ExportMetricWriter
    MetricWriter metricWriter(MBeanExporter exporter) {
        return new JmxMetricWriter(exporter);
    }
}
Run Code Online (Sandbox Code Playgroud)

我没有看到通过我的jconsole在Jmx中收集端点调用的任何指标.我错过了什么?

metrics dropwizard spring-boot spring-boot-actuator

6
推荐指数
1
解决办法
1303
查看次数

Spring Boot Actuator管理端点异常处理

问题:如何处理管理上下文中 MVC 端点抛出的异常?

public class MyMvcEndpoints extends EndpointMvcAdapter {
    @ResponseBody
    @RequestMapping(method = GET, value = "/foo", produces = APPLICATION_JSON_VALUE)
    public Foo foo() {
        throw new FooNotFound("Foo Not Found!");
    }
}

@ResponseStatus(value = HttpStatus.NOT_FOUND)
public class FooNotFound extends RuntimeException {
    public NotFoundException(String message){
        super(message);
    }
}
Run Code Online (Sandbox Code Playgroud)

使用当前配置,我收到500的不是404. 我尝试了常见的异常处理方法,如 ControllerAdvice、ExceptionHandler 方法等,但没有成功。
我还发现CompositeHandlerExceptionResolver其中EndpointWebMvcChildContextConfiguration负责异常处理。我尝试定义自己的HandlerExceptionResolverbean,但它无法在管理上下文中找到我的解析器。

java spring spring-mvc spring-boot spring-boot-actuator

6
推荐指数
1
解决办法
2307
查看次数

@RefreshScope与@ConditionalOnProperty不起作用

问题

探索一种@RequestMapping无需重新启动JVM即可按需启用/禁用端点的选项。在运行时在端点上实现kill开关。

尝试

我尝试了以下方法,但@RefreshScope似乎无法使用@ConditionOnProperty

@RestController
@RefreshScope
@ConditionalOnProperty(name = "stackoverflow.endpoints", havingValue = "enabled")
public class MyController {

    @Value("${stackoverflow.endpoints}")
    String value;

    @RequestMapping(path = "/sample", method = RequestMethod.GET)
    public ResponseEntity<String> process() {
        return ResponseEntity.ok(value);
    }

}
Run Code Online (Sandbox Code Playgroud)

使用更新属性

POST /env?stackoverflow.endpoints=anyvalue
Run Code Online (Sandbox Code Playgroud)

并使用重新加载上下文

POST /refresh
Run Code Online (Sandbox Code Playgroud)

此时,控制器返回更新后的值。

还有其他方法可以实现所需的功能吗?

runtime environment-variables spring-boot spring-cloud spring-boot-actuator

6
推荐指数
1
解决办法
668
查看次数

Prometheus端点不起作用Spring Boot 2.0.0.RC1启用了Spring Webflux

我按照此处的文档(https://docs.spring.io/spring-boot/docs/2.0.0.RC1/reference/htmlsingle/#production-ready-endpoints-enabling-endpoints)进行操作,并确保application.yml文件具有以下

management:
  metrics:
    export:
      prometheus:
        enabled: true
  endpoints:
    web:
      expose:
        health, info, httptrace, metrics, threaddump, mappings, prometheus
Run Code Online (Sandbox Code Playgroud)

根据文档(https://docs.spring.io/spring-boot/docs/current-SNAPSHOT/actuator-api/html/#prometheus),以下操作无效。

curl 'http://localhost:8080/actuator/prometheus' -i
Run Code Online (Sandbox Code Playgroud)

我得到404处理程序映射未找到异常。有人可以让我知道如何启用Prometheus端点进行抓取,以及需要使用哪个URL端点进行测试吗?

o.s.w.r.r.m.a.RequestMappingHandlerMapping[276] - Did not find handler method for [/actuator/prometheus]
Run Code Online (Sandbox Code Playgroud)

所有其他端点的运行状况,信息,httptrace,线程转储,映射均正常运行。

spring spring-boot spring-boot-actuator spring-webflux

6
推荐指数
2
解决办法
5808
查看次数

Spring执行器http.server.requests统计数据的单位是什么

我已经使用 实现了服务spring-boot-starter-2.0.0.RELEASE。我已经为其启用了执行器指标,但是我无法理解指标以什么单位表示。具体来说,我对http.server.requests.

端点的输出示例为:

{
    "name": "http.server.requests",
    "measurements": [
        {
            "statistic": "COUNT",
            "value": 2
        },
        {
            "statistic": "TOTAL_TIME",
            "value": 0.049653001
        },
        {
            "statistic": "MAX",
            "value": 0.040696019
        }
    ],
    "availableTags": [
        {
            "tag": "exception",
            "values": [
                "None"
            ]
        },
        {
            "tag": "method",
            "values": [
                "GET"
            ]
        },
        {
            "tag": "status",
            "values": [
                "200"
            ]
        }
    ]
}
Run Code Online (Sandbox Code Playgroud)

spring metrics spring-boot spring-boot-actuator

6
推荐指数
1
解决办法
3559
查看次数

如何使用Spring Boot 2将Kafka指标公开到/ actuator / metrics

我看了一会儿,似乎没有找到答案。我正在使用Spring Boot 2,Spring Kafka 2.1.4,并且我想在Spring Boot执行器的/ metrics端点中看到kafka使用者度量。我不明白的是-我应该自己实施曝光还是在启动2中立即使用它?

如果我实现自己的自我,最好的方法是什么?

metrics spring-boot spring-boot-actuator spring-kafka

6
推荐指数
2
解决办法
3814
查看次数

Spring Boot 2.0 Prometheus向后兼容性

我正在迁移到Spring Boot 2.0,我的Prometheus Metrics存在问题.

我知道MicroMeter是一种新的做事方式,它不像Prometheus libs那样清脆,但还可以.

我的问题是,如果我现在不想更改我的指标,我就无法升级到Spring Boot 2.0.我对吗?

我尝试了以下方法:

试验1号

  • 保持我的实现"按原样"
  • 将新依赖项添加io.micrometer:micrometer-registry-prometheus:1.0.2到我的应用程序(执行器已经在那里)
  • 更改内容application.properties以访问端点actuator/prometheus

=>我CountersGauges过去被忽略了.好的,从技术角度来看,我理解这一点.

试验2

  • 保持我的实现"按原样"
  • 添加"旧"'io.prometheus'依赖项并删除千分尺依赖项
  • 更改内容application.properties以访问端点actuator/prometheus

=>现在我得到以下的重复

Caused by: java.lang.ClassNotFoundException: org.springframework.boot.actuate.endpoint.AbstractEndpoint
at java.net.URLClassLoader.findClass(URLClassLoader.java:381) ~[na:1.8.0_161]
at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_161]
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:338) ~[na:1.8.0_161]
at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_161]
... 37 common frames omitted
Run Code Online (Sandbox Code Playgroud)

所以我的问题是:是否有"软迁移"方式有效?

spring spring-boot spring-boot-actuator prometheus micrometer

6
推荐指数
1
解决办法
1758
查看次数

动态添加和删除Spring Boot运行状况检查

我正在开发一个基于Spring Boot的应用程序,通过API动态添加和删除特定于域的任务.由于这些作业可能单独失败,我想HealthIndicator在每个作业运行时添加s,然后将其删除.Spring Actuator的健康端点已经集成到多个监视器中,这只会将这些信息推向下游.

我当然可以将所有工作的健康状况检查汇总到一个HealthIndicatorbean中,但我更愿意以某种方式列出所有检查的健康状况.在HealthIndicator不但是只允许返回一个Health实例.有没有办法返回这些对象的集合?

java spring health-monitoring spring-boot spring-boot-actuator

6
推荐指数
1
解决办法
1079
查看次数

防止在所有当前请求完成之前关闭Spring Boot应用程序

我们有一个Spring Boot(2.0.4)应用程序,它公开了许多端点,其中一个端点使客户端可以检索有时非常大的文件(约200 GB)。该应用程序通过配置了滚动更新策略的Kubernetes部署在Pod中公开。

当我们通过将映像设置为最新版本来更新部署时,吊舱会被破坏,新的吊舱会旋转。我们的服务可满足新要求。但是,当前的请求可能并且确实会被切断,这对于下载非常大文件的客户端来说可能会很烦人。

我们可以在部署规范中配置Container Lifecycle Pre-Stop挂钩,以在通过其PID发送关闭信号给应用之前注入暂停。这有助于防止任何新流量流向已设置为“终止”的Pod。有没有一种方法可以暂停应用程序关闭过程,直到所有当前请求都已完成(这可能需要数十分钟)?

这是我们在Spring Boot应用程序中尝试过的方法:

  • 实现一个关闭侦听器ContextCloseEvents; 不幸的是,我们无法可靠地检索活动请求列表。在关机过程的此阶段,任何可能有用的执行器指标均不可用。

  • 通过实施HttpSessionListener和覆盖sessionCreated/Destroy方法来更新计数器来对活动会话进行计数。失败是因为方法没有在单独的线程上调用,所以始终在关闭侦听器中报告相同的值。

我们应该尝试其他策略吗?从应用程序本身或容器中,还是直接通过Kubernetes资源描述符?建议/帮助/指针将不胜感激。

编辑:我们管理集群,因此我们仅尝试通过修改的Pod规范在对部署进行托管更新期间减轻当前连接的客户端的服务中断

java docker spring-boot kubernetes spring-boot-actuator

6
推荐指数
1
解决办法
393
查看次数

是否有办法从 AsyncResttemplate 获取 http.client.requests 指标?

我正在尝试通过千分尺和普罗米修斯监控我的 Spring Boot 应用程序的其余模板指标。当我使用 ResttemplateBuilder 构建的 Resttemplate 并用于调用另一个 api 时,它确实获得了预期的 http.client.requests 指标。但是对于 AsyncResttemplate,当我使用 AsyncResttemplate 创建并使用它来调用另一个 api 时,它没有提供任何 http.client.requests 指标。

这是我创建 AsyncResttemplate bean 时的代码

    @Bean
    public AsyncRestTemplate asyncRestTemplate(){
        return new AsyncRestTemplate();
    }
Run Code Online (Sandbox Code Playgroud)

这是我使用异步调用另一个 api 时的代码

    public ListenableFuture async() {
        ListenableFuture<ResponseEntity<AccountResponse>> accountResponseList = asyncRestTemplate.exchange(accountUrl, HttpMethod.GET, new HttpEntity<>(new HttpHeaders()), AccountResponse.class);
        accountResponseList.addCallback(new ListenableFutureCallback<ResponseEntity<AccountResponse>>() {
            @Override
            public void onSuccess(ResponseEntity<AccountResponse> accountResponseResponseEntity) {
                System.out.println("Success");
            }

            @Override
            public void onFailure(Throwable throwable) {
                System.out.println("Failure");
            }
        });
        return accountResponseList;
    }
Run Code Online (Sandbox Code Playgroud)

这些是pom.xml中导入的相关依赖项

<dependency>
      <groupId>io.micrometer</groupId>
      <artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
<dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
Run Code Online (Sandbox Code Playgroud)

这是我期望从微米普罗米修斯指标中获得的结果 …

java spring-boot spring-boot-actuator spring-micrometer

6
推荐指数
1
解决办法
6707
查看次数