> ## Documentation Index
> Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# The metrics API Endpoint

> Explains Prometheus scraping of /metrics endpoints, the OpenMetrics text format, sample metrics, scrape configuration and metric types for collecting and storing time series

Prometheus stores metrics using a dimensional data model: each time series is identified by a metric name plus a set of key-value labels. Example metric samples:

```text theme={null}
http_requests_total{endpoint="/items", request_method="GET"} 10
http_requests_total{endpoint="/items", request_method="PUT"} 2
http_requests_total{endpoint="/search", request_method="GET"} 4
```

Prometheus obtains these samples by scraping targets according to scrape configurations (jobs). In many deployments Prometheus scrapes itself on `localhost:9090` and collects node-level metrics from exporters running on Kubernetes nodes.

But what exactly does Prometheus receive when it scrapes a target? What does that HTTP response look like?

Every scrape target exposes an HTTP endpoint—commonly `/metrics`. When Prometheus performs an HTTP GET against that path, the target returns a plain-text payload in the OpenMetrics format. This format is simple, human-readable, and intentionally not JSON or YAML.

Here is a compact OpenMetrics response example:

```text theme={null}
# HELP http_requests_total The total number of HTTP requests to the backend service.
# TYPE http_requests_total counter
http_requests_total{endpoint="/items",request_method="GET"} 10
http_requests_total{endpoint="/items",request_method="PUT"} 2
http_requests_total{endpoint="/search",request_method="GET"} 4
# HELP node_memory_usage_bytes Current memory usage in bytes.
# TYPE node_memory_usage_bytes gauge
node_memory_usage_bytes{instance="node01"} 536870912
node_memory_usage_bytes{instance="node02"} 268435456
```

Quick reference — the three primary line types in OpenMetrics:

| Line prefix | Purpose | Example |
| - | - | - |
| `# HELP` | Human-readable description of the metric. | `# HELP http_requests_total The total number of HTTP requests to the backend service.` |
| `# TYPE` | Declares the metric type (e.g., `counter`, `gauge`, `histogram`, `summary`). | `# TYPE http_requests_total counter` |
| Metric sample | A metric name, optional labels in `{}` as comma-separated `key="value"` pairs, a space, then the numeric value. | `http_requests_total{endpoint="/items",request_method="GET"} 10` |

Prometheus parses the OpenMetrics payload on every scrape and stores the resulting time series in its TSDB.

[OpenMetrics](https://openmetrics.io/) (the plain-text format shown above) is the expected format for endpoints that Prometheus scrapes. Many Kubernetes components (for example the kubelet and kube-apiserver) and many exporters expose metrics in exactly this format to be compatible with Prometheus.

This diagram illustrates Prometheus scraping Kubernetes components (GET /metrics) and ingesting OpenMetrics-formatted responses.

![A simple diagram titled "OpenMetrics...OpenMetrics Everywhere" showing Prometheus scraping metrics from Kubernetes (GET /metrics) with kubelet and kube-apiserver listed. Arrows indicate Prometheus querying the Kubernetes endpoints for /metrics.](https://mintcdn.com/kodekloud-c4ac6d9a/qM9vA-hQoWNCxcKa/images/Grafana-Prometheus-for-Metrics-Driven-Observability/Prometheus-and-Grafana-Introduction/The-metrics-API-Endpoint/openmetrics-prometheus-scraping-kubernetes-diagram.jpg?fit=max\&auto=format\&n=qM9vA-hQoWNCxcKa\&q=85\&s=9beefa64067180ec3356d5b4ae072779)

All targets listed in your scrape configuration must expose metrics in the OpenMetrics format so Prometheus can scrape and ingest them. A typical `scrape_configs` section in `prometheus.yml` may look like this:

```yaml theme={null}
scrape_configs:
  - job_name: "prometheus"
    static_configs:
      - targets: ["localhost:9090"]

  - job_name: "order-backend"
    metrics_path: "/metrics"
    scrape_interval: 15s
    static_configs:
      - targets: ["order-backend.default.svc.cluster.local:8080"]

  - job_name: "order-frontend"
    metrics_path: "/metrics"
    scrape_interval: 30s
    static_configs:
      - targets: ["order-frontend.default.svc.cluster.local:3000"]
```

Prometheus supports multiple metric types; here's a concise summary:

| Metric type | Typical use | Example |
| - | - | - |
| `counter` | Monotonically increasing value (e.g., request counts). | `http_requests_total{...} 42` |
| `gauge` | Value that can go up and down (e.g., current memory usage). | `node_memory_usage_bytes{instance="node01"} 536870912` |
| `histogram` | Buckets + count + sum for distributions (e.g., request durations). | `request_duration_seconds_bucket{le="0.5"} 240` |
| `summary` | Quantiles + count + sum for distributions (client-side quantiles). | `request_duration_seconds{quantile="0.95"} 0.123` |

Be careful exposing `/metrics` endpoints publicly. Metrics can contain sensitive metadata (hostnames, labels) and may become high-volume endpoints. Use network policies, authentication, or internal-only endpoints for production workloads.

Next steps:

* Read the Prometheus documentation for scrape configuration and relabeling rules.
* Explore PromQL to query and aggregate the time series Prometheus stores from these OpenMetrics responses.

Links and references:

* [Prometheus documentation](https://prometheus.io/docs/)
* [OpenMetrics specification](https://openmetrics.io/)

Following sections cover Prometheus metric types in more detail and introduce Prometheus's built-in query language for exploring and aggregating this data.

> [card] [Watch Video](https://learn.kodekloud.com/user/courses/grafana-prometheus-for-metrics-driven-observability/module/86c79392-532c-42b7-8908-18bf0a84210b/lesson/83a51b0a-8c46-4157-8fe8-e247b68730a9)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.