Spring boot not registering on promethes end point

985 Views Asked by At

I am trying to configure Prometheus and Grafana with spring boot.

@Configuration
@EnableSpringBootMetricsCollector
public class MetricsConfiguration {

    /**
     * Register common tags application instead of job. This application tag is
     * needed for Grafana dashboard.
     *
     * @return registry with registered tags.
     */

    @Value("${spring.application.name}")
    private String applicationName;

    @Value("${spring.profiles.active}")
    private String environment;


    @Bean
    public MeterRegistryCustomizer<MeterRegistry> metricsCommonTags() {
        return registry -> {
            registry.config().commonTags("application", applicationName, "environment", environment)
                    .meterFilter(getDefualtConfig());
        };
    }

    private MeterFilter getDefualtConfig() {
        return new MeterFilter() {
            @Override
            public DistributionStatisticConfig configure(Meter.Id id, DistributionStatisticConfig config) {
                return DistributionStatisticConfig.builder().percentilesHistogram(true).percentiles(0.95, 0.99).build()
                        .merge(config);
            }
        };
    }

}

while running the application I am able to see traing on localhost:8080/prometheus url.

but same I am not able to see on localhost:9090/metrics url which is Prometheus URL.

I have added the configuration in prometheus.yml and restarted the Prometheus.

- job_name: 'my-api'
    scrape_interval: 10s
    metrics_path: '/prometheus'
    target_groups:
       - targets: ['localhost:8080']
1

There are 1 best solutions below

3
Ravat Tailor On BEST ANSWER

After spending 2 hours found the solution, we were using basic auth for all health points also The issue was that I was not setting up basic auth in my proemtheus.yml

- job_name: 'my-api'
    scrape_interval: 10s
    metrics_path: '/prometheus'
    target_groups:
       - targets: ['localhost:8080']
    basic_auth:
      username: test
      password: test