是否有方法在使用/metrics时侦听https://quarkus.io/guides/micrometer端点
我想收集一些需要调用不同API的指标.而不是建立一个时间表(https://quarkus.io/guides/scheduler-reference).
示例:
更新一些量规。
首先,/metrics给我们提供了:
# HELP test_metric_a
# TYPE test_metric_a gauge
test_metric_a{namespace="test123",user="admin",} 1.0
test_metric_a{namespace="testabc",user="admin",} 1.0
# HELP test_metric_b
# TYPE test_metric_b gauge
test_metric_b 0.0第二个/metrics可能提供:
# HELP test_metric_a
# TYPE test_metric_a gauge
test_metric_a 0.0
# HELP test_metric_b
# TYPE test_metric_b gauge
test_metric_b{namespace="testabc",user="admin",} 2.0如何使用 来调用Kubernetes API,因为应用程序中可能没有任何更改会导致对量规/注册表的更新,但是外部事件或时间传递会导致状态(所需的度量输出)发生更改.
请注意,自定义度量(见下面的注释)只被调用一次(我猜它是一个单例?)。理想情况下,我希望每次/metrics被回复时都打电话给我.
进一步编辑,以显示如何创建/更新量规:
@ApplicationScoped
public class MyMetrics {
private final MeterRegistry registry;
MyMetrics(MeterRegistry registry) {
this.registry = registry;
}
//...
// somehow call this whenever /metrics is hit?
protected void updateGauges() {
// use KubernetesClient to query K8s API to gather some customer resources, then process that list... etc...
// there is a loop over the below for user/namespace pairs in the tags
//final Tags tags = getTags();
//int count = getCount();
//registry.gauge("test_metric_a", tags, count);
// so this could roll out to something like:
registry.gauge("test_metric_a", Tags.of("user", "user1", "namespace", "ns1"), 1);
registry.gauge("test_metric_a", Tags.of("user", "user2", "namespace", "ns1"), 2);
registry.gauge("test_metric_a", Tags.of("user", "user1", "namespace", "ns2"), 1);
registry.gauge("test_metric_b", Tags.of("user", "user1", "namespace", "ns1"), 1);
registry.gauge("test_metric_b", Tags.of("user", "user2", "namespace", "ns1"), 1);
}
}...perhaps这些gauges可能是counters..。但问题仍然是..。
发布于 2021-04-01 14:04:22
好的。正如我在评论中指出的那样,当收集度量时(例如,Prometheus,当端点被刮掉时),就会观察到度量的值。
如果您正在讨论添加包含名称空间之类内容的标记,那么常见的标记示例可能为您提供了一些内容,在这里您可以预先计算标签:
registry.config().commonTags("stack", "prod", "region", "us-east-1");这将将这些标记添加到所有度量中,但您可以使用MeterFilter来进行更多的选择(例如,只将标记添加到与某些条件匹配的指标中)。
new MeterFilter() {
@Override
public Meter.Id map(Meter.Id id) {
if(id.getName().startsWith("test")) {
return id.withName("extra." + id.getName()).withTag("extra.tag", "value");
}
return id;
}
}https://micrometer.io/docs/concepts#_common_tags
如果您试图根据从Kubernetes API检索的数据更新标记/标签值,则需要运行一个定期任务(例如,计划的任务),该任务将使用新的标记重新注册该表。
请注意,对于已被垃圾收集的量规,千分尺将省略或返回NaN (取决于所使用的注册表),因此,如果希望使用以前的标记值注册的量规保持不变,则需要使它们具有强大的引用。
https://stackoverflow.com/questions/66879334
复制相似问题