我遵循这个示例来发布自定义度量,并遵循这些细节在PCF中注册这些指标。
以下是代码:
@RestController
public class CustomMetricsController {
@Autowired
private MeterRegistry registry;
@GetMapping("/high_latency")
public ResponseEntity<Integer> highLatency() throws InterruptedException {
int queueLength=0;
Random random = new Random();
int number = random.nextInt(50);
System.out.println("Generate number is : "+number);
if(number % 2 == 0) {
queueLength=99;
} else {
queueLength=200;
}
return new ResponseEntity<>(queueLength, null, HttpStatus.OK);
}
}application.yml:
management:
endpoints:
web:
exposure:
include: "metrics,prometheus"
endpoint:
metrics:
enabled: true
prometheus:
enabled: trueSecurityConfiguration类:

build.gradle依赖关系部分:

在应用程序部署到PCF之后,我按照以下步骤注册自定义度量:
metric-registrar
log-cache插件以验证度量端点,下面是日志

这是我在自动分配器事件历史中遇到的错误。
最近的事件历史:2019年7月17日(星期三)上午11:20自动分词器在缩放窗口期间没有收到任何关于high_latency的度量。缩减将推迟到这些指标可用为止。
发布于 2019-07-18 03:18:14
我调查了这个大案子。这里有几件事。
cf register-metrics-endpoint api high_latency,这意味着您有一个名为api的应用程序,在high_latency上有一个端点,它使用Prometheus格式导出度量标准。根据README和我的简短测试,对于这个示例应用程序,路径应该是/actuator/prometheus。
当我使用命令cf register-metrics-endpoint app-name /actuator/prometheus时,我能够看到来自cf tail的输出中的自定义度量&在包含的输出中看不到它们。
例句:(没有出现在你的截图中)
2019年-07-17T22:54:37.83-0400定制-度量-演示/0规格tomcat_global_request_max_seconds:2.006000 2019-07-17T22:54:37.83-0400自定义-度量-演示/0规范system_cpu_count:4.000000 2019-07-17T22:54:37.83-0400自定义-度量-演示/0计数器tomcat_sessions_created_sessions_total:12 2019-07-17T22:54:37.83-0400自定义-指标-演示/0计数器custom_metric_total:15 2019-07-17T22:54:37.83-0400自定义-度量-演示/0规格jvm_gc_pause_seconds_sum:0.138000 2019-07-17T22:54:37.83-0400自定义-度量-演示/0计数器jvm_gc_pause_seconds_count:25high_latency的度量,因此这不能作为度量的名称,因为它永远不会由应用程序生成。如果在浏览器中访问/actuator/prometheus端点,则可以看到所有指标。Prometheus格式基于文本,非常容易阅读。custom_metric,它将无法工作,因为它是一个计数器。您将只看到关于自动分词器的消息,在缩放窗口中看不到任何度量事件。确保您正在选择一个可用于缩放的量规。tomcat_servlet_request_seconds_sum{name="dispatcherServlet",},我不认为有一种方法可以告诉自动分词器,name标记必须是某个值。该信息在LogCache中,但我不认为自动分配器在这个时候使用它。在我写这篇文章的时候,我快速地浏览了一下代码,似乎表明它只是在查看度量名称。如果您要创建一个自定义度量,这并不重要。只是不要用任何标记来衡量指标。希望这能帮上忙!
https://stackoverflow.com/questions/57079356
复制相似问题