Micrometer

How to use Micrometer Timer to record duration of async method (returns Mono or Flux)

做~自己de王妃 提交于 2020-01-14 10:11:18
问题 I'd like to use Micrometer to record the execution time of an async method when it eventually happens. Is there a recommended way to do this? Example: Kafka Replying Template. I want to record the time it takes to actually execute the sendAndReceive call (sends a message on a request topic and receives a response on a reply topic). public Mono<String> sendRequest(Mono<String> request) { return request .map(r -> new ProducerRecord<String, String>(requestsTopic, r)) .map(pr -> { pr.headers()

querying data with micrometer

試著忘記壹切 提交于 2020-01-06 14:54:28
问题 We have this fancy monitoring system to which our spring-boot services are posting metrics to an influx DB with micrometer. There's a nice grafana frontend, but the problem is that we're now at a stage where we have to have some of these metrics available in other services to reason on. The whole system was set up by my predecessor, and my current understanding of it is practically zero. I can add and post new metrics, but I can't for the life of me get anything out of it. Here's a short

Spring Boot 2.0 Prometheus Backward Compatibility

旧巷老猫 提交于 2020-01-02 04:10:08
问题 I am migrating to Spring Boot 2.0 and I am having issues with my Prometheus Metrics. I know that MicroMeter is the new way of doing stuff, which is not as crisp as the Prometheus libs but OK. My issue is that If I do not want to change my metrics now I cannot upgrade to Spring Boot 2.0. Am I right? I tried the following: Trial no 1 Keep my implementations "as is" add the new dependency io.micrometer:micrometer-registry-prometheus:1.0.2 to my app (actuator is already in there) change stuff in

Adding micrometer dependency causes weird Spring proxy issue

試著忘記壹切 提交于 2019-12-24 00:39:24
问题 I have a simple Spring Boot application with private @Scheduled method: @SpringBootApplication @EnableScheduling public class DemoApplication { public static void main(String[] args) { SpringApplication.run(DemoApplication.class, args); } @Scheduled(fixedRate = 1000) private void scheduledTask() { System.out.println("Scheduled task"); } } pom.xml: <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi

Micrometer/Prometheus How do I keep a gauge value from becoming NaN?

心已入冬 提交于 2019-12-22 09:00:19
问题 I am trying to monitor logged in users, i am getting the logged in user info by calling api, this is the code i have used, public class MonitorService { private InfoCollectionService infoService; public MonitorService(InfoCollectionService infoService) { this.infoService = infoService } @Scheduled(fixedDelay = 5000) public void currentLoggedInUserMonitor() { infoService.getLoggedInUser("channel").forEach(channel -> { Metrics.gauge("LoggedInUsers.Inchannel_" + channel.getchannelName(), channel

Spring Boot 默认的指标数据从哪来的?

非 Y 不嫁゛ 提交于 2019-12-21 21:26:42
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 了解有关 Spring Boot 默认指标及其来源的更多信息。 您是否注意到 Spring Boot 和 Micrometer 为您的应用生成的所有默认指标?如果没有 - 您可以将 actuator 依赖项添加到项目中,然后点击 / actuator / metrics 端点,在那里您将找到有关 JVM 、进程、Tomcat、流量等的有用信息。然后,添加一些 缓存 , 数据源 或 JPA 依赖项,甚至会出现更多指标。如果您想知道它们是如何结束的,我们可以在哪里找到关于它们所描述的参数的解释,那么这篇文章就是为您准备的。 显示指标 为了让它井然有序,让我们从如何在 Spring Boot 应用程序中显示指标开始。如果您已经知道了,可以跳过这一部分。 Spring Boot中的指标由 micrometer.io 处理。但是,如果您使用 actuator ,则不需要向项目添加 micrometer 依赖项,因为 actuator 已经依赖于它。即使您对它提供的端点不感兴趣,也希望您使用 actuator ,因为这是通过其 AutoConfigurations 注册许多指标的模块。稍后我们会详细讨论。 因此,首先,只需将执行器依赖项添加到项目中(这里是 build.gradle.kts ) dependencies {

How can I start and stop a timer in different classes?

寵の児 提交于 2019-12-13 02:15:20
问题 I want to measure the time from the start of an incoming HTTP request and the application getting to a certain point. Both those points in time are located in different classes. How would I start and stop a timer from these different classes. I don't see a way to use 'named' timers from the MeterRegistry. How would I go about this? 回答1: You can use AOP as below : @Aspect @Component public class ControllerMonitor { protected static final Logger LOGGER = LoggerFactory.getLogger

Why do reading Micrometer measurement returns NaN sometimes?

我们两清 提交于 2019-12-12 20:06:48
问题 I'm trying to programmatically read the Meters as follows: Get registry: MeterRegistry registry = Metrics.globalRegistry.getRegistries().iterator().next(); Read measurement: double systemCpuUsage = registry.get("system.cpu.usage").gauge().measure().iterator().next().getValue(); The problem is that sometimes I get NaN . I read about this in the docs: Why is my Gauge reporting NaN or disappearing? but I'm not sure what I shall do. Also, I'm reading the "built-in" gauge of Spring Boot actuator

How to emit custom metrics from SpringBoot application and use it in PCF Autoscaler

帅比萌擦擦* 提交于 2019-12-11 16:43:24
问题 I am following this example for emitting the custom metrics and followed these details for registering the metrics in PCF. Here is the code: @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)

How to use Micrometer timer together with webflux endpoints

限于喜欢 提交于 2019-12-11 15:49:09
问题 IS there any simple way to use Micrometer timers with Webflux controllers? It seems that @Timed works only with non-reactive methods. For reactive it records very low time values. I found a similar question: How to use Micrometer Timer to record duration of async method (returns Mono or Flux) but the answers were too complex for such a common issue Any ideas? 回答1: If you want to measure time for Web-flux methods/calls you can then use easily metrics directly from Flux/Mono (plus configure