Spring Boot 执行器 heapdump 在 cloudfoundry 中的表现

问题描述

我在多个实例中使用 cloudfoundry。我正在尝试使用 spring 的 /actuator 端点生成堆转储。

我的疑问是在 cloudfoundry env 的情况下,其中一次运行 2 个实例,对于该实例,它将生成堆转储。 如何知道 heapdump 是针对哪个实例的,并且无论如何我们都可以命中特定实例。

注意:我只想使用 spring boot 执行器 /heapdump url 选项。

解决方法

我的疑问是在 cloudfoundry env 的情况下,一次运行 2 个实例,对于哪个实例,它将生成堆转储。

您无法真正提前知道请求将到达何处。对您的应用实例的请求由 Gorouter(循环)进行负载平衡,因此除非您的应用没有流量,否则该请求可能会命中任一后端应用实例。

但是,您可以在事后确定请求到达的应用实例。

  1. 在终端中,为您的应用运行 cf logs

  2. 在另一个终端中,运行 curl -v ...。输出将有一个名为 X-Vcap-Request-Id 的标头。复制该指南。

    < HTTP/1.1 200 OK
    < Content-Type: text/html; charset=UTF-8
    < Date: Thu,20 May 2021 12:27:39 GMT
    < Server: Apache
    < Vary: Accept-Encoding
    < X-Vcap-Request-Id: c254c0df-c03f-475f-6210-fe3eea7cf28a  # <-- this line
    < Content-Length: 399
    
  3. cf logs 的输出中查找您在上一步中捕获的 guid。这将标识请求的访问日志条目(请参阅 vcap_request_id 字段)。同一记录中的 app_index 字段会告诉您哪个应用收到了请求。

    2021-05-20T08:27:39.85-0400 [RTR/0] OUT php-info.apps.pcfone.io - [2021-05-20T12:27:39.848995848Z] "GET / HTTP/1.1" 200 0 399 "-" "curl/7.64.1" "192.168.4.4:34744" "192.168.16.31:61075" x_forwarded_for:"23.115.134.147,192.168.4.4" x_forwarded_proto:"https" vcap_request_id:"c254c0df-c03f-475f-6210-fe3eea7cf28a" response_time:0.008122 gorouter_time:0.000506 app_id:"c1985534-3ca3-4ada-8bd2-b9b7a57de440" app_index:"0" x_cf_routererror:"-" x_b3_traceid:"5bc96459099edbfd" x_b3_spanid:"5bc96459099edbfd" x_b3_parentspanid:"-" b3:"5bc96459099edbfd-5bc96459099edbfd"
    

如何知道 heapdump 是针对哪个实例的,以及我们是否可以命中特定实例。

这就是你想要的:https://docs.cloudfoundry.org/devguide/deploy-apps/routes-domains.html#surgical-routing

如果您发送 X-Cf-App-Instance,您可以选择一个特定的应用实例。然后,您可以针对特定应用实例或确保从所有应用实例获得堆转储。

例如:curl myapp.example.com -H "X-Cf-App-Instance: 5cdc7595-2e9b-4f62-8d5a-a86b92f2df0e:9"

X-Cf-App-Instance 的内容是 X-Cf-App-Instance: APP_GUID:APP_INDEX。您可以使用 cf app myapp --guid 检索您的应用程序 guid。 APP_INDEX 从零开始,所以 0 是第一个实例,1 是第二个实例,依此类推...

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...