If you are using Spring boot 2.1.5.RELEASE then

  1. add dependencies actuator and micrometer-prometheus
  <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
  </dependency>
 <dependency> 
   <groupId>io.micrometer</groupId>
   <artifactId>micrometer-registry-prometheus</artifactId>
 </dependency>
  1. add config to enable access to endpoint /actuator/prometheus
management:
  endpoints:
    web:
      exposure:
       include: '*'
  1. try to request http://domain:port/actuator/prometheus

EDIT For kubernetes im using kind deployment:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: myAppName
spec:
  replicas: 1
  selector:
    matchLabels:
      app: myAppName
  template:
    metadata:
      labels:
        app: myAppName
      annotations:
        prometheus.io/scrape: "true"
        prometheus.io/port: "8091"
        prometheus.io/path: "/actuator/prometheus"
    spec:
      containers:
        - name: myAppName
          image: images.com/app-service:master
          imagePullPolicy: Always
          ports:
            - containerPort: 8091
          env:
            - name: INSTANCE_IP
              valueFrom:
                fieldRef:
                  fieldPath: status.podIP
            - name: SPRING_PROFILES_ACTIVE
              value: "prod"
            - name: CONFIG_SERVER_ADDRESS
              value: "http://config-server:8888"
          livenessProbe:
            failureThreshold: 3
            httpGet:
              path: /actuator/health
              port: 8091
              scheme: HTTP
            initialDelaySeconds: 45
            periodSeconds: 10
            successThreshold: 1
            timeoutSeconds: 5
          readinessProbe:
            failureThreshold: 5
            httpGet:
              path: /actuator/health
              port: 8091
              scheme: HTTP
            initialDelaySeconds: 30
            periodSeconds: 10
            successThreshold: 1
            timeoutSeconds: 5
      nodeSelector:
        servicetype: mvp-cluster
Answer from Sulaymon Hursanov on Stack Overflow
🌐
GitHub
github.com › jmazzitelli › prometheus-scraper
GitHub - jmazzitelli/prometheus-scraper: A Java API that can be used to scrape Prometheus endpoints. · GitHub
You must also implement createPrometheusMetricDataParser() to return an instance of the custom PrometheusMetricDataParser<T> class (see above). To use your extension, create an input stream to your endpoint that contains the custom-formatted metric data, create a walker instance to walk your data (say, use the prometheus.walkers.JSONPrometheusMetricsWalker to generate a JSON document of your metric data or prometheus.walkers.CollectorPrometheusMetricsWalker to simply obtain a list of all metric families) and pass the stream and walker to your extension processor's constructor then call the walk() method.
Author: jmazzitelli
🌐
Blogger
management-platform.blogspot.com › 2016 › 04 › prometheus-metric-endpoint-parser-for.html
Thoughts From A Management Platform Developer: Prometheus Metric Endpoint Parser for Java
April 18, 2016 - This will return a list of MetricFamily objects, which contain all the metric data found in the endpoint URL. See the code's Javadoc for more complete documentation. There are a few things still missing that would be nice to enhance for the future. First is histogram support for binary formatted data (but once the jar artifact "io.prometheus.client:model" version 0.0.3 is released by the Prometheus team, it would just be a matter of uncommenting one block of code for my Java-based parser to begin supporting it).
Top answer
1 of 1
1

If you are using Spring boot 2.1.5.RELEASE then

  1. add dependencies actuator and micrometer-prometheus
  <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
  </dependency>
 <dependency> 
   <groupId>io.micrometer</groupId>
   <artifactId>micrometer-registry-prometheus</artifactId>
 </dependency>
  1. add config to enable access to endpoint /actuator/prometheus
management:
  endpoints:
    web:
      exposure:
       include: '*'
  1. try to request http://domain:port/actuator/prometheus

EDIT For kubernetes im using kind deployment:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: myAppName
spec:
  replicas: 1
  selector:
    matchLabels:
      app: myAppName
  template:
    metadata:
      labels:
        app: myAppName
      annotations:
        prometheus.io/scrape: "true"
        prometheus.io/port: "8091"
        prometheus.io/path: "/actuator/prometheus"
    spec:
      containers:
        - name: myAppName
          image: images.com/app-service:master
          imagePullPolicy: Always
          ports:
            - containerPort: 8091
          env:
            - name: INSTANCE_IP
              valueFrom:
                fieldRef:
                  fieldPath: status.podIP
            - name: SPRING_PROFILES_ACTIVE
              value: "prod"
            - name: CONFIG_SERVER_ADDRESS
              value: "http://config-server:8888"
          livenessProbe:
            failureThreshold: 3
            httpGet:
              path: /actuator/health
              port: 8091
              scheme: HTTP
            initialDelaySeconds: 45
            periodSeconds: 10
            successThreshold: 1
            timeoutSeconds: 5
          readinessProbe:
            failureThreshold: 5
            httpGet:
              path: /actuator/health
              port: 8091
              scheme: HTTP
            initialDelaySeconds: 30
            periodSeconds: 10
            successThreshold: 1
            timeoutSeconds: 5
      nodeSelector:
        servicetype: mvp-cluster
Top answer
1 of 2
1

You can scrap metrics from your actuator endpiont in the same way as Prometheus do it. I use OkHttpClient for that. Example of my client:

OkHttpClient client = new OkHttpClient.Builder()
                .retryOnConnectionFailure(false)
                .followRedirects(false)
                .protocols(Collections.singletonList(Protocol.H2_PRIOR_KNOWLEDGE))
                .build();

All settings are optional. But pay attention to the protocol - it should be the same as on your application's server.

After that you need to build url:

String url = "http://localhost:9090/actuator/prometheus?includedNames=<nameOfThePropertyThatYouNeed>";

You can include here more than 1 property:

String url = "http://localhost:9090/actuator/prometheus?includedNames=<propertyNameOne>,<propertyNameTwo>,<propertyNameThree>";

After that you make request:

Request request =new Request.Builder()
                .url(url)
                .get()
                .build();
Response response = client.newCall(request).execute();
String responseBody = response.body().string();

Now you need to parse responseBody. Do it in the way as Prometheus does it and use classes of Prometheus:

InputStream inputStream = new ByteArrayInputStream(responseBody.getBytes())
CollectorPrometheusMetricsWalker walker = new CollectorPrometheusMetricsWalker();
PrometheusMetricsProcessor<MetricFamily> processor = new TextPrometheusMetricsProcessor(inputStream, walker);
processor.walk();
List<MetricFamily> metricList = walker.getAllMetricFamilies();

MetricFamily object stores all metrics with the same name but with different tags. Use metricFamily.getMetrics() to get List<Metric> Use metric.getValue() to get the value of metric.

2 of 2
0

You should use AlertManager that is part of Prometheus suit.

🌐
Baeldung
baeldung.com › home › devops › guide to prometheus java client
Guide to Prometheus Java Client | Baeldung
August 12, 2026 - The Prometheus Java client allows us to instrument our applications with minimal effort by exposing real-time metrics for Prometheus to scrape and monitor.
🌐
Java Code Geeks
javacodegeeks.com › home › core java
Guide to Prometheus Java Client - Java Code Geeks
December 27, 2024 - The provided Java code sets up a simple application that exposes JVM (Java Virtual Machine) metrics for Prometheus to scrape. The DefaultExports.initialize() method initializes default JVM metrics, such as memory usage, garbage collection statistics, and thread counts, which are collected by Prometheus.
🌐
Devon Burriss' Blog
devonburriss.me › prometheus-parser-fennel
Creating a Prometheus parser: Fennel - Devon Burriss' Blog
December 24, 2020 - A quick tour of using FParsec to write a Prometheus parser ... A year back I ran into the need for a library that provided a model for creating valid Prometheus log lines. The libraries I looked at sent these metrics for export rather than giving me access to the model or allowing me to create ...
Find elsewhere
🌐
Better Stack
betterstack.com › community › guides › monitoring › java-prometheus
Instrumenting Java Apps with Prometheus Metrics | Better Stack Community
February 20, 2025 - It explores key concepts, including instrumenting your application with various metric types, monitoring HTTP request activity, and exposing metrics for Prometheus to scrape. Let's get started! ... Better Stack lets you see inside any stack, debug any issue, and resolve any incident. Explore more · Prior experience with Java and Spring Boot, along with a recent JDK installed
🌐
Craftsman Nadeem
reachmnadeem.wordpress.com › 2020 › 12 › 04 › capturing-java-application-metrics-using-prometheus
Capturing Java Application Metrics Using Prometheus | Craftsman Nadeem
December 6, 2020 - Rather than storing every duration for every request, Prometheus will make an approximation by storing the frequency of requests that fall into particular buckets. By default, these buckets are: .005, .01, .025, .05, .075, .1, .25, .5, .75, 1, 2.5, 5, 7.5, 10. This is very much tuned to measuring request durations below 10 seconds, so if you’re measuring something else you may need to configure custom buckets. ... A histogram with a base metric name of “java_app_h“ exposes multiple time series during a scrape :
🌐
Sysdig
sysdig.com › blog › prometheus-metrics
Prometheus metrics / OpenMetrics code instrumentation. | Sysdig
March 27, 2026 - The Prometheus project includes a collection of client libraries which allow metrics to be published so they can then be collected (or "scraped" using Prometheus' terminology) by the metrics server. "How to instrument your #Golang #Java #Python and #Javascript code using #Prometheus metrics."
🌐
Prometheus
prometheus.io › docs › instrumenting › clientlibs
Client libraries | Prometheus
Choose a Prometheus client library that matches the language in which your application is written. This lets you define and expose internal metrics via an HTTP endpoint on your application’s instance: Go · Java or Scala · Python · Ruby · Rust · Unofficial third-party client libraries: Bash ·
🌐
GitHub
github.com › PawelJ-PL › prometheus-metrics-parser
GitHub - PawelJ-PL/prometheus-metrics-parser: Scala Prometheus metrics parser
val input: String = """ |# HELP some_metric First metric |# TYPE some_metric counter |some_metric{foo = "bar"} 123 999 """.stripMargin val eitherResult: Either[ParseError, List[Metric]] = parser.parseE(input) // Right(List(Counter(some_metric,Some(First metric),List(MetricValue(Map(foo -> bar),123.0,Some(999),None))))) val optionResult: Option[List[Metric]] = parser.parseOpt(input) // Some(List(Counter(some_metric,Some(First metric),List(MetricValue(Map(foo -> bar),123.0,Some(999),None))))) val result: List[Metric] = parser.unsafeParse(input) //List(Counter(some_metric,Some(First metric),List(MetricValue(Map(foo -> bar),123.0,Some(999),None)))) The last one is marked as unsafe, because it throws exception (com.github.pawelj_pl.prometheus_metrics_parser.parser.ParseException) on error.
Author: PawelJ-PL
🌐
client_java
prometheus.github.io › client_java › getting-started › metric-types
Metric Types | client_java
If the Prometheus server is started with --enable-feature=native-histogram and the scrape config has the option scrape_classic_histograms: true, it will request metrics in Prometheus protobuf format and ingest both, the classic and the native flavor.
🌐
OpenLogic
openlogic.com › blog › prometheus-java-monitoring-and-gathering-data
How to Use Prometheus Monitoring With Java to Gather Data | OpenLogic
August 7, 2025 - Click the Prometheus section to return to the main screen, and use the pull-down next to the “Execute” button to select a metric and view its contents: Recorded Webinar - Monitoring Java Applications With Prometheus and Grafana
🌐
client_java
prometheus.github.io › client_java › getting-started › quickstart
Quickstart | client_java
To scrape the metrics with a Prometheus server, download the latest Prometheus server release, and configure the prometheus.yml file as follows: global: scrape_interval: 10s # short interval for manual testing scrape_configs: - job_name: "java-example" static_configs: - targets: ["localhost:9400"]