首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >指标@ time确实测量时间,总是0。

指标@ time确实测量时间,总是0。
EN

Stack Overflow用户
提问于 2018-07-17 14:18:12
回答 1查看 707关注 0票数 2

度量@Timed注释有一个问题。它似乎不测量时间(只计算通话次数)。

设置与Payara 5完全。

典型的http://localhost:8080/metrics/application输出

代码语言:javascript
复制
    # TYPE application:total_coffees_retrieved counter
application:total_coffees_retrieved 4
# TYPE application:total_coffees_consumed counter
application:total_coffees_consumed 4
# TYPE application:com_sebastian_daschner_hello_prometheus_coffees_retrieve_coffee_rate_per_second gauge
application:com_sebastian_daschner_hello_prometheus_coffees_retrieve_coffee_rate_per_second 1.4044150172871745
# TYPE application:com_sebastian_daschner_hello_prometheus_coffees_retrieve_coffee_one_min_rate_per_second gauge
application:com_sebastian_daschner_hello_prometheus_coffees_retrieve_coffee_one_min_rate_per_second 0.0
# TYPE application:com_sebastian_daschner_hello_prometheus_coffees_retrieve_coffee_five_min_rate_per_second gauge
application:com_sebastian_daschner_hello_prometheus_coffees_retrieve_coffee_five_min_rate_per_second 0.0
# TYPE application:com_sebastian_daschner_hello_prometheus_coffees_retrieve_coffee_fifteen_min_rate_per_second gauge
application:com_sebastian_daschner_hello_prometheus_coffees_retrieve_coffee_fifteen_min_rate_per_second 0.0
# TYPE application:com_sebastian_daschner_hello_prometheus_coffees_retrieve_coffee_mean_seconds gauge
application:com_sebastian_daschner_hello_prometheus_coffees_retrieve_coffee_mean_seconds 0.0
# TYPE application:com_sebastian_daschner_hello_prometheus_coffees_retrieve_coffee_max_seconds gauge
application:com_sebastian_daschner_hello_prometheus_coffees_retrieve_coffee_max_seconds 0.0
# TYPE application:com_sebastian_daschner_hello_prometheus_coffees_retrieve_coffee_min_seconds gauge
application:com_sebastian_daschner_hello_prometheus_coffees_retrieve_coffee_min_seconds 0.0
# TYPE application:com_sebastian_daschner_hello_prometheus_coffees_retrieve_coffee_stddev_seconds gauge
application:com_sebastian_daschner_hello_prometheus_coffees_retrieve_coffee_stddev_seconds 0.0
# TYPE application:com_sebastian_daschner_hello_prometheus_coffees_retrieve_coffee_seconds summary
application:com_sebastian_daschner_hello_prometheus_coffees_retrieve_coffee_seconds_count 4
application:com_sebastian_daschner_hello_prometheus_coffees_retrieve_coffee_seconds{quantile="0.5"} 0.0
application:com_sebastian_daschner_hello_prometheus_coffees_retrieve_coffee_seconds{quantile="0.75"} 0.0
application:com_sebastian_daschner_hello_prometheus_coffees_retrieve_coffee_seconds{quantile="0.95"} 0.0
application:com_sebastian_daschner_hello_prometheus_coffees_retrieve_coffee_seconds{quantile="0.98"} 0.0
application:com_sebastian_daschner_hello_prometheus_coffees_retrieve_coffee_seconds{quantile="0.99"} 0.0
application:com_sebastian_daschner_hello_prometheus_coffees_retrieve_coffee_seconds{quantile="0.999"} 0.0

平均,最大,分位数都是"0.0",而计数工作得很好(= 4)。

我们已经尝试了多个Payara/JEE/Microprofile版本的组合,每个版本都有相同的结果。

下面是一些代码片段(基本代码摘自https://github.com/sdaschner/hello-prometheus/tree/microprofile,只添加了@Timed)

咖啡豆:

代码语言:javascript
复制
@ApplicationScoped
public class Coffees {


    @Counted(name = "total_coffees_retrieved", absolute = true, monotonic = true)
    @Timed   
    public String retrieveCoffee() {
        try {
            Thread.sleep((int) (1000 * Math.random()));
        } catch (InterruptedException ex) {
            Logger.getLogger(Coffees.class.getName()).log(Level.SEVERE, null, ex);
        }

        return "Coffee!";
    }

}

JAX-RS REST资源:

代码语言:javascript
复制
import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;

@Path("coffee")
public class CoffeesResource {

    @Inject
    Coffees coffees;

    @GET
    public String getCoffee() {
        return coffees.retrieveCoffee();
    }

}

pom.xml

代码语言:javascript
复制
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.sebastian-daschner</groupId>
    <artifactId>hello-prometheus</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>war</packaging>

    <dependencies>
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-api</artifactId>
            <version>7.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.eclipse.microprofile.metrics</groupId>
            <artifactId>microprofile-metrics-api</artifactId>
            <version>1.1.1</version> <!-- also tried 1.0 and 1.1 -->
            <scope>provided</scope>
        </dependency>
    </dependencies>

    <build>
        <finalName>hello-prometheus</finalName>
    </build>

    <properties>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <failOnMissingWebXml>false</failOnMissingWebXml>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
</project>

有什么办法解决这个问题吗?

编辑:在使用application/json请求度量标准时不发生

代码语言:javascript
复制
curl -H "Accept: application/json" http://localhost:8080/metrics/application

下一个payara版本已经解决了问题:https://github.com/payara/Payara/issues/2970

EN

回答 1

Stack Overflow用户

发布于 2018-07-18 09:25:22

如果您想看到比0更多的东西,您将需要一个需要更多时间执行的方法!简单地递增一个计数器并返回这样的字符串几乎不需要任何时间,绝对远小于0.1秒,因此您的度量标准中将永远看不到任何值。

尝试将Thread.sleep(1500)添加到方法中,以查看计时器是否记录了1.5秒。

由于@Timed提供了大量的统计数据,您还可以尝试使用Thread.sleep(Math.random() * 1000)来给出执行所需时间的一些变化,并为您提供更多有趣的度量来检查。

编辑:正如在下面的评论中提到的,在PayaraMicro5.182中出现了一个错误,导致计时器无法工作。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51383738

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档