🌐
Medium
medium.com › @hanxuyang0826 › exposing-metrics-the-right-way-prometheus-grafana-in-action-ed82ce5833df
Exposing Metrics the Right Way: Prometheus + Grafana in Action | by Lagu | Medium
September 15, 2025 - Prometheus offers PromQL, a powerful query language that makes aggregations, comparisons, and trend analysis straightforward. Metrics become cheap to expose: the application only needs to provide its current values at /metrics, and Prometheus ...
🌐
GitHub
github.com › prometheus-operator › prometheus-operator › blob › main › Documentation › exposing-metrics.md
prometheus-operator/Documentation/exposing-metrics.md at main · prometheus-operator/prometheus-operator
Those applications simply expose the metrics through an HTTP server. The Prometheus developers and the community are maintaining client libraries for various languages. If you want to monitor your own applications and instrument them natively, ...
Author: prometheus-operator
Discussions

maven - How to expose metrics to Prometheus from a Java (Spring boot) application - Stack Overflow
My Spring-Boot application simply has a counter metric. I just don't know how to send this information to Prometheus. I am using Maven (build tool) and Spring Boot (Java). More on stackoverflow.com
🌐 stackoverflow.com
python - Expose package metrics to Prometheus with prometheus_client - Stack Overflow
I have two files running the following code on their own: sandbox1.py from prometheus_client import Counter import time while True: my_counter1 = Counter('my_counter1', 'My counter) my_coun... More on stackoverflow.com
🌐 stackoverflow.com
Best way to expose custom metrics to Prometheus for a kubernetes cron job
Push metrics gateway is made for that. And you can see it as a global sidecar ;) More on reddit.com
🌐 r/PrometheusMonitoring
6
3
March 29, 2025
How to make docker container be able to communicate with my host's localhost
what do you mean - cannot communicate ? did you expose any prometheus ports for caddy ? More on reddit.com
🌐 r/docker
7
0
July 12, 2024
🌐
Medium
medium.com › @letathenasleep › exposing-python-metrics-with-prometheus-c5c837c21e4d
Exposing Python Metrics with Prometheus | by Adso | Medium | Medium
July 6, 2023 - Once the containers are running, you can access the API at http://localhost:5000 and the Prometheus dashboard at http://localhost:9090. The /metrics endpoint of the API will expose the metrics that Prometheus can scrape.
🌐
Prometheus
prometheus.io › docs › instrumenting › writing_exporters
Writing exporters | Prometheus
For process stats where you have ... request count and a failed request count, the best way to expose this is as one metric for total requests and another metric for failed requests....
🌐
Prometheus
prometheus.io › docs › prometheus › latest › getting_started
Getting started | Prometheus
To use Prometheus's built-in expression browser, navigate to http://localhost:9090/query and choose the "Graph" tab. As you can gather from localhost:9090/metrics , one metric that Prometheus exports about itself is named prometheus_target_interval_length_seconds (the actual amount of time ...
🌐
Medium
medium.com › rewire-to › how-to-expose-the-right-prometheus-metrics-for-your-custom-exporter-implementation-open-source-162815adc1b0
How to expose the right Prometheus metrics for your custom exporter implementation (Open Source) | by Or Kaplan | Remitly Israel (formerly Rewire) | Medium
December 27, 2022 - The service had to scrape the metrics from the Cloudflare analytics API, convert it to Prometheus format, and submit the response back to Prometheus. This task was really straightforward, as Cloudflare exposes the data using a GraphQL API.
🌐
Gravitee
documentation.gravitee.io › apim › 4.8 › kafka-gateway › expose-metrics-to-prometheus
Expose metrics to Prometheus | API Management 4.8 | Gravitee Documentation
June 25, 2025 - If you run the application in a Docker container, set the IP address to 0.0.0.0. For Prometheus to contain metrics to collect, you must either produce a Kafka message or consume a Kafka message.
🌐
Gravitee
documentation.gravitee.io › apim › analyze-and-monitor-apis › logging › expose-metrics-to-prometheus
Expose Metrics to Prometheus | API Management | Gravitee Documentation
June 10, 2026 - Prometheus support is activated and exposed using the component’s internal API. Use the tab that matches your deployment method. ... Add the following variables to the .env file loaded by your docker-compose.yml, or to the environment: block of the Gateway service: ... Set the gateway.services.metrics block in your values.yaml file.
Find elsewhere
Top answer
1 of 4
4

Prometheus, like Graphite, is a time-series storage engine.

Grafana can then query Prometheus to generate graphics and alerts.

https://prometheus.io/docs/introduction/faq/

As the documentation cites, Prometheus, unlike other metrics storage systems, uses a (debatable) "pull" model.

This means that there is a (stand-alone) Prometheus server that must be downloaded/installed. This server then periodically makes HTTP GET requests (pull) to a list of application servers - such as a Java SpringBoot server to fetch (in-memory) stored metrics.

Ref: https://prometheus.io/docs/introduction/faq/#why-do-you-pull-rather-than-push?

Thus the (Spring Boot) application must expose a metrics end-point that the Prometheus server can pull from (default is /metrics).

Ref: https://github.com/prometheus/client_java

Thus there is much documentation available on Google but that is the (arguably convoluted) topology - along with arguments from the SoundCloud and Prometheus folks as to why a "pull" model is preferred over "push" as every other metrics framework employs.

2 of 4
3

For Intergrating Prometheus, add the following dependencies in your POM.XML

<dependency>
    <groupId>io.prometheus</groupId>
    <artifactId>simpleclient_spring_boot</artifactId>
    <version>0.1.0</version>
</dependency>
<dependency>
    <groupId>io.prometheus</groupId>
    <artifactId>simpleclient_servlet</artifactId>
    <version>0.1.0</version>
</dependency>
<dependency>
    <groupId>io.prometheus</groupId>
    <artifactId>simpleclient_hotspot</artifactId>
    <version>0.1.0</version>
</dependency>

In your SpringBoot Application Class, add the Annonation @EnablePrometheusEndpoint

In your Controller, you can define a Custom Counter

private static final Counter myCounter = Counter.build()
        .name("CounterName")
        .labelNames("status")
        .help("Counter desc").register();

In your service, you can have appropriate logic for your Counter which would be automatically pulled by Prometheus

@RequestMapping("/myService")
    public void endpoint() {
           String processingResult = yourLogic(myCounter);
            myCounter.labels("label1",processingResult).inc();
            }
🌐
OneUptime
oneuptime.com › home › blog › how to create and expose custom prometheus metrics
How to Create and Expose Custom Prometheus Metrics
February 20, 2026 - # prometheus.yml # Configure Prometheus to scrape your custom metrics scrape_configs: # Scrape your application metrics - job_name: "my-application" scrape_interval: 15s metrics_path: /metrics static_configs: - targets: - "app-server-1:8000" - "app-server-2:8000" # Kubernetes service discovery for dynamic targets - job_name: "kubernetes-pods" kubernetes_sd_configs: - role: pod relabel_configs: # Only scrape pods with the annotation prometheus.io/scrape: "true" - source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_scrape] action: keep regex: true # Use the annotation for the metrics path - source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_path] action: replace target_label: __metrics_path__ regex: (.+)
🌐
Hughevans
hughevans.dev › exposing-metrics-to-prometheus
Exposing metrics to Prometheus with Service Monitors
October 20, 2025 - If you don’t have to access to ... the Prometheus configuration: one way to achieve this is via configuring a service monitor to expose your metric endpoints....
🌐
Kamon
kamon.io › docs › latest › reporters › prometheus
Exposing Metrics for Prometheus with Kamon | Kamon Documentation | Kamon
implementation 'io.kamon:kamon-prometheus_2.13:2.5.9' Once the reporter is on your classpath it will be automatically picked up by Kamon. When your application starts, you can go to http://localhost:9095/metrics to see your exposed metrics.
🌐
Medium
medium.com › daemon-engineering › exposing-metrics-to-prometheus-with-service-monitors-326f38b2daf1
Exposing metrics to Prometheus with Service Monitors | by Hugh Evans | daemon-engineering | Medium
May 13, 2022 - If you don’t have to access to ... the Prometheus configuration: one way to achieve this is via configuring a service monitor to expose your metric endpoints....
🌐
Labspractices
labspractices.com › learningpaths › application-observability › exposing-metrics-java-prometheus
Exposing Prometheus Metrics from Java | Labs Practices Site
June 15, 2021 - The Micrometer library is a popular way to expose application metrics to a service like Prometheus. Adding Dependencies To add the Micrometer dependency for Prometheus with Maven: io.micrometer micrometer-registry-prometheus ${micrometer.version} ...
Top answer
1 of 1
7

Prometheus server scrapes HTTP endpoints that provide metrics. This differs from some other metric systems where the metrics are pushed to the metric system. Because Prometheus scrapes metric endpoints, you need to do two things:

  1. Expose the metrics from your client using an HTTP server|endpoint
  2. Configure the Prometheus server to target this metric server|endpoint

If you run the Three Step Demo example on the page that you reference, and then browse http://localhost:8000, you should see something like:

# HELP python_gc_objects_collected_total Objects collected during gc
# TYPE python_gc_objects_collected_total counter
python_gc_objects_collected_total{generation="0"} 357.0
python_gc_objects_collected_total{generation="1"} 0.0
python_gc_objects_collected_total{generation="2"} 0.0
...
...
# HELP request_processing_seconds Time spent processing request
# TYPE request_processing_seconds summary
request_processing_seconds_count 4.0
request_processing_seconds_sum 2.0374009040533565
# HELP request_processing_seconds_created Time spent processing request
# TYPE request_processing_seconds_created gauge
request_processing_seconds_created 1.6004497426536365e+09

This is the page that your Prometheus server would be configured to scrape. You can see, e.g. python_gc_objects_collected_total counter is provided. Prometheus metrics are human readable which is useful.

If you combine, your sandbox1.py into this example:

from prometheus_client import start_http_server, Counter, Summary
import random
import time

# Create a metric to track time spent and requests made.
REQUEST_TIME = Summary('request_processing_seconds',
                       'Time spent processing request')


# Decorate function with metric.
@REQUEST_TIME.time()
def process_request(t):
    """A dummy function that takes some time."""
    time.sleep(t)


if __name__ == '__main__':
    my_counter1 = Counter('my_counter1', 'My counter')
    # Start up the server to expose the metrics.
    start_http_server(8000)
    # Generate some requests.
    while True:
        my_counter1.inc()
        process_request(random.random())

And run the code again, you should now see:

# HELP python_gc_objects_collected_total Objects collected during gc
# TYPE python_gc_objects_collected_total counter
python_gc_objects_collected_total{generation="0"} 357.0
python_gc_objects_collected_total{generation="1"} 0.0
python_gc_objects_collected_total{generation="2"} 0.0
...
...
# HELP my_counter1_total My counter
# TYPE my_counter1_total counter
my_counter1_total 13.0
# HELP my_counter1_created My counter
# TYPE my_counter1_created gauge
my_counter1_created 1.6004498408280134e+09

NOTE At the bottom of the page is my_counter1_total and my_counter1_created which correspond to your my_counter1 = Counter("my_counter1","My counter")

If you point a Prometheus server at this target (localhost:8000), you should be able to e.g. graph the my_counter1_total counter and the my_counter1_created gauge.

Create a file called prometheus.yml:

global:
  scrape_interval: 15s
  evaluation_interval: 15s

scrape_configs:
  # Self
  - job_name: "prometheus-server"
    static_configs:
      - targets:
          - "localhost:9090"

  # Python example
  - job_name: "63957470"
    static_configs:
      - targets:
          - "localhost:8000"

And then run Prometheus:

docker run \
--interactive --tty \
--net=host \
--volume=${PWD}/prometheus.yml:/etc/prometheus/prometheus.yml \
prom/prometheus@sha256:f3ada803723ccbc443ebea19f7ab24d3323def496e222134bf9ed54ae5b787bd

NOTE This assumes that prometheus.yml is in the working directory

The, you can browse Prometheus on http://localhost:9090

You can see your code configured as a target: http://localhost:9090/targets

And you can query|graph your metrics. Type e.g. my_counter1_ to see both and then my_counter1_total for the Counter:

🌐
Reddit
reddit.com › r/prometheusmonitoring › best way to expose custom metrics to prometheus for a kubernetes cron job
r/PrometheusMonitoring on Reddit: Best way to expose custom metrics to Prometheus for a kubernetes cron job
March 29, 2025 -

I have a kubernetes cron job that is relatively short lived (a few minutes). Through this cron job I expose to the prometheus scrapper a couple of custom metrics that encode the timestamp of the most recent edit of a file.

I then use these metrics to create alerts (alert triggers if time() - timestamp > 86400).

I realized that after the cronjob ends the metrics disappear which may affect alerting. So I researched the potential solutions. One seems to be to push the metrics to PushGateway and the other to have a sidecar-type of permanent kubernetes service that would just keep the prometheus HTTP server running to expose and update the metrics continually.

Is there a solution more preferable than the other? What is considered better practice?

🌐
DeepWiki
deepwiki.com › cloudflare › rust-prometheus › 4-exposing-metrics
Exposing Metrics | cloudflare/rust-prometheus | DeepWiki
May 13, 2025 - HTTP Endpoint for Services: For long-running services, expose an HTTP endpoint for Prometheus to scrape. Pushgateway for Batch Jobs: For short-lived batch jobs, push metrics to a Pushgateway.
🌐
Pierre Vincent
blog.pvincent.io › 2017 › 12 › prometheus-blog-series-part-3-exposing-and-collecting-metrics
Prometheus Blog Series (Part 3): Exposing and collecting metrics
December 26, 2017 - Clients have only one responsibility: make their metrics available for a Prometheus server to scrape. This is done by exposing an HTTP endpoint, usually /metrics, which returns the full list of metrics (with label sets) and their values.
🌐
Tigera
tigera.io › home › prometheus monitoring
Prometheus Monitoring: The Complete Guide
July 30, 2021 - Pull model: The Prometheus server periodically queries, or “scrapes,” designated HTTP endpoints to collect metrics, instead of applications pushing data to the server. Exporters: Lightweight services called exporters (such as Node Exporter for machine metrics) format and expose data for applications or hardware that do not natively emit Prometheus metrics.
🌐
Optimizely
support.optimizely.com › hc › en-us › articles › 4413200003597-Expose-Prometheus-metrics
Expose Prometheus metrics – Support Help Center
March 20, 2024 - The metrics are exposed at /api/v1/admin/metrics and require basic authentication. The MetricsUsername and MetricsPassword can be configured in .\B2B Commerce.Web\config\appSettings.config.