- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我正在尝试通过将 Micrometer.io 与 Spring Boot 2.0.0.RELEASE 结合使用来生成 Prometheus 指标。
当我尝试将 List 的大小时公开为 Gauge 时,它一直显示 NaN。在文档中它说;
It is your responsibility to hold a strong reference to the state object that you are measuring with a Gauge.
我尝试了一些不同的方法,但我无法解决问题。这是我的一些试验代码。
import io.micrometer.core.instrument.*;
import io.swagger.backend.model.Product;
import io.swagger.backend.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
@RestController
@RequestMapping("metrics")
public class ExampleController {
private AtomicInteger atomicInteger = new AtomicInteger();
private ProductService productService;
private final Gauge productGauge;
@Autowired
public HelloController(ProductService productService,
MeterRegistry registry) {
this.productService = productService;
createGauge("product_gauge", productService.getProducts(), registry);
}
private void createGauge(String metricName, List<Product> products,
MeterRegistry registry) {
List<Product> products = productService.getProducts();
// #1
// this displays product_gauge as NaN
AtomicInteger n = registry.gauge("product_gauge", new AtomicInteger(0));
n.set(1);
n.set(2);
// #2
// this also displays product_gauge as NaN
Gauge
.builder("product_gauge", products, List::size)
.register(registry);
// #3
// this displays also NaN
testListReference = Arrays.asList(1, 2);
Gauge
.builder("random_gauge", testListReference, List::size)
.register(registry);
// #4
// this also displays NaN
AtomicInteger currentHttpRequests = registry.gauge("current.http.requests", new AtomicInteger(0));
}
@GetMapping(path = "/product/decrement")
public Counter decrementAndGetProductCounter() {
// decrement the gague by one
}
}
有没有人可以帮助解决这个问题?任何帮助将不胜感激。
最佳答案
在所有情况下,您都必须持有对观察到的实例的强引用。当您的 createGauge()
方法退出时,所有函数堆栈分配的引用都符合垃圾回收条件。
对于 #1
,像这样传递您的 atomicInteger
字段:registry.gauge("my_ai", atomicInteger);
。然后根据需要递增/递减。每当micrometer需要查询它的时候,只要找到引用它就会查询。
对于 #2
,传递您的 productService
字段和一个 lambda。基本上,无论何时查询仪表,它都会使用提供的对象调用该 lambda:registry.gauge("product_gauge", productService, productService -> productService.getProducts().size());
(不保证语法错误。)
关于java - Micrometer - Prometheus Gauge 显示 NaN,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50821924/
随着 OpenTelemetry 试图成为应用程序/服务可观察性的事实上的标准,Micrometer 在哪里适合? Micrometer 网站声称它是用于度量标准的 SLF4J,但它是否与 OpenT
我正在尝试弄清楚如何为特定指标设置通用标签。注意:我正在使用 Cloudwatch 监控系统。这是我所拥有的: @Bean public MeterRegistryCustomizer metrics
我正在尝试发布我的应用程序正在处理的事件数量。这是我在接收端的代码: public void process(List batch) { logger.info ("Processing ba
这可能听起来很愚蠢,而且可能有一个非常简单的答案,但我还没有找到任何答案。 对于以下形式的每个度量类型,Micrometer 都有 Builder 类: .builder().description(
我想记录多个指标名称的计数,例如 metricA、metricB、metricC 等等。 一种选择是像这样创建多个计数器对象 Counter .builder("metricA") .register
我正在尝试使用 Atlas 配置 Micrometer。我正在遵循 Micrometer 和 Spring 提供的指南(我使用的是 Spring Boot 2.0.1),但我不明白出了什么问题。 我有
考虑以下代码: public static void main(String[] args) { Timer timer = Metrics.timer("item.processing");
任何人都可以解释一下千分尺 @Timed 注释公开的 _count 和 _sum 指标之间的区别是什么。 这里有两个度量值示例,作为方法上的 @Timed 注释的结果。 GET_CARD_LIMITS
我正在使用默认的 MicroMeter Binder ,其中之一创建了 Gauage jvm.memory.used。问题是它带有 2 个可用标签:“area”和“id”。这实际上生成了 6 个我不感
我想将Micrometer的默认执行器指标(JVM内存等)发送到AWS ElasticSearch实例,并在Kibana中可视化数据。 我想我正确设置了它,但是在Kibana中没有任何数据。 这是我的
Micrometer 库是否支持 OpenTsdb 作为监控系统? 如果没有,是否有任何第三方库可以在 Micrometer 之上工作并向 OpenTsdb 报告指标? 最佳答案 在撰写本文时,还没有
我有一段使用 Codahale 指标的旧代码。我想将其更改为千分尺。我可以切换简单的对象,但我在重现某些 Codahale 特定对象的功能时遇到了一些麻烦。 而且我可以切换简单的对象,我在重现某些 C
如何在不重新启动微服务的情况下禁用或启用 Micrometer 的某些指标?我想公开一个端点来更改我的应用程序收集的指标。 最佳答案 禁用/启用场景 您希望停止修改指标,但将其保留在指标端点上,以便您
我正在尝试监控登录用户,我通过调用 api 获取登录用户信息,这是我使用的代码, public class MonitorService { private InfoCollectionSer
我正在尝试使用 Micrometer在我的 Java 应用程序中记录执行时间。这与我的另一个question有关关于使用 @Timed注解。 我有一个类CountedObject有以下两种方法: @M
在 Prometheus 中,http_server_requests_seconds_max 有 14 秒。 http_server_requests_seconds_max{exception="
我是使用 spring-boot 指标的新手,并从千分尺开始。我找不到在我的 spring-boot 应用程序中执行计时器指标的好例子(它是新的事实)。我正在使用 spring-boot-starte
是否有任何简单的方法可以将 Micrometer 计时器与 Webflux Controller 结合使用? @Timed 似乎仅适用于非响应式方法。对于 react 性来说,它记录的时间值非常低。
我正在尝试将我的 Prometheus 指标迁移到千分尺,但现在我在这里遇到了一件事...... 目前我有一个 Prometheus 直方图配置如下: private static final His
我在 Java Spring Boot 1.5 应用程序中使用 Micrometer 来抓取 Prometheus 的自定义指标。 我正在使用“guageCollectionSize”方法来计算 Ha
我是一名优秀的程序员,十分优秀!