prometheus-java - How to update label value in promethues java implementation
问题描述
I have to update the label values in prometheus histogram where one of the label is the response status and that can only be updated once I get the response. Below is my Implementation of the histogram metric. How can I update the labels
Histogram
public class CustomHistogram implements CountryHistogram{
private final Histogram histogram;
CustomHistogram(SampleRegistry registry) {
histogram = Histogram.build().name("custom_metric").help("Sample metrics")
.labelNames("name", "status").register(registry);
}
@Override
public Histogram.Timer startTimer() {
return histogram.labels("name","dummy").startTimer();
}
@Override
public void observeDuration(Histogram.Timer timer) {
//need to update label here
timer.observeDuration();
}
}
Usage
public void executeCall() {
CustomHistogram hist = MetricFactory.getHistogram();
Histogram.Timer timer = hist.startTimer();
try{
//do external call here
} finally {
hist.observeDuration(timer);
}
}
How can I update the status
label in the observeDuration
method?
解决方案
推荐阅读
- r - 单撇号的 Dplyr SELECT 问题
- kubernetes - 使用 gcloud 和 kubectl 切换帐户是否有更好的工作流程?
- ios - iphone部分机型inputAccessoryView和安全区底部重叠
- bazel - 将 maven 工件下载到存储库的推荐规则(maven_install vs jvm_import_external)
- windows - 为什么表头的字体在 SQL Shell (psql) 中不能正确显示?
- javascript - 一个函数,用于计算元素的出现或频率并返回一个对象,但删除出现一个的元素并返回其余元素
- ssas - MDX 合并两个查询
- python - 在字符的第一次和最后一次出现时拆分?
- angular - SyntaxError:无法在 Angular/Nx/jest 应用程序中使用 @ionic-native/health 的模块外部使用 import 语句
- python - super() 可打印表示