English 中文(简体)
Prometheus Java client manually exposing prometheus end point
原标题:

I have a spring boot application where for certain legacy reasons I cannot use spring actuator.

I was able to expose a prometheus end point and see a lot of default metrics. But I am not able to see the metrics that I am myself adding.

The code below works.

@Configuration
public class PrometheusMonitoringConfig {

    @Bean
    public PrometheusMeterRegistry prometheusMeterRegistry() {
        PrometheusMeterRegistry prometheusMeterRegistry=new PrometheusMeterRegistry(PrometheusConfig.DEFAULT);
        Metrics.globalRegistry.add(prometheusMeterRegistry);
        return prometheusMeterRegistry;
    }

}

@Autowired
PrometheusMeterRegistry prometheusRegistry;


//This is the prometheus http end point
@Override
public Response getPrometheus(HttpHeaders headers, HttpServletRequest request) {
    Response response = Response.status(Response.Status.OK).entity(prometheusRegistry.scrape()).build();

    return response;
}

At this point when I hit this, I see a lot of data https://localhost:8003/prometheus

But if I add this, even though I can see the counter go up when I put a breakpoint in the code, I do not see it in the metrics end point

How can I see the metric requests_total in my https://localhost:8003/prometheus endpoint

static final Counter requests = Counter.build()
                                           .name("requests_total").help("Total requests.").register();

someMethod(){
 requests.inc();
}

These are the dependencies I added in my maven pom

<dependency>
    <groupId>io.micrometer</groupId>
    <artifactId>micrometer-registry-prometheus</artifactId>
    <version>1.11.2</version>
</dependency>
<!-- Hotspot JVM metrics-->
<dependency>
    <groupId>io.prometheus</groupId>
    <artifactId>simpleclient_hotspot</artifactId>
    <version>0.16.0</version>
</dependency>
问题回答

暂无回答




相关问题
Prometheus Java client manually exposing prometheus end point

I have a spring boot application where for certain legacy reasons I cannot use spring actuator. I was able to expose a prometheus end point and see a lot of default metrics. But I am not able to see ...

Grafana interval variable: minimum threshold function?

I m adding an interval variable to a dashboard to allow averaging some prometheus time series over an interval to get cleaner looking graphs. But I want to leave in the base sample rate (15s) so the ...

How to specify time range in {aggregate}_over_time?

I have a Grafana chart that makes use of the sum_over_time(data_source[$__interval]) and count_over_time(data_source[$__interval]) command in Prometheus. Normally, it is working fine. But, the ...

how to regex path in prometheus relabel_configs

i have a metric and label like this: namedprocess_namegroup_num_procs{groupname:"/data/home/user01/app.service.1/service"}, i want to get the last field: service, and the number in last but ...

Omit labels from series results PromQL

Suppose I write a basic PromQL query like this Query: kube_deployment_spec_replicas{} Result: kube_deployment_spec_replicas{deployment="mydeployment",endpoint="myendpoint",instance="myinstance",...

Last known timestamp of a metric sample?

How do I get the timestamp of the last known sample of a metric? I want to display a table that lists when was the last time a specific service was running before it disappeared (died or whatever). ...

热门标签