我们对日食微轮廓指标@Timed注释有疑问。 它似乎无法衡量时间(仅计算通话次数)。
Payara 5已安装完毕。
通过MDN web docs的典型输出:
# 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版本的多种组合,每种组合都具有相同的结果。
以下是一些代码段(碱基来自http://localhost:8080/metrics/application,仅添加了@Timed)
咖啡豆:
@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资源:
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
<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请求指标时不会发生
curl -H "Accept: application/json" http://localhost:8080/metrics/application
问题已在下一个payara版本中解决: https://github.com/sdaschner/hello-prometheus/tree/microprofile
答案 0 :(得分:0)
如果要查看0以外的值,则需要一种方法,该方法需要更多时间才能执行!只需增加一个计数器并返回一个类似的字符串,几乎不需要花费任何时间,绝对不会超过0.1秒,因此您将永远不会在指标中看到任何值。
尝试在方法中添加Thread.sleep(1500)
,以查看计时器是否记录1.5秒。
由于@Timed
为您提供了大量统计信息,因此您也可以尝试Thread.sleep(Math.random() * 1000)
使您执行的时间有所不同,并提供更多有趣的指标进行检查。
编辑:如下面的评论所述,Payara Micro 5.182中似乎存在一个错误,导致计时器无法正常工作。