Operations 5 min read

Prometheus HTTP Service Discovery: Compare, Requirements & JSON Format

Prometheus HTTP Service Discovery (HTTP SD) offers a flexible, JSON‑based approach for dynamically locating targets, contrasting with file‑based SD in event handling, update frequency, format, transport, and security, while outlining endpoint requirements, response headers, and providing concrete JSON examples for practical implementation.

Java Architecture Diary
Java Architecture Diary
Java Architecture Diary
Prometheus HTTP Service Discovery: Compare, Requirements & JSON Format

1. HTTP SD Overview

Prometheus provides a generic HTTP service discovery that can discover targets at HTTP endpoints.

HTTP service discovery complements other mechanisms and serves as an alternative to file‑based discovery.

2. Comparison between File SD and HTTP SD

Based on events : File SD – yes (via inotify); HTTP SD – no.

Update frequency : File SD – immediate via inotify; HTTP SD – based on refresh_interval.

Format : File SD – YAML or JSON; HTTP SD – JSON.

Transport : File SD – local files; HTTP SD – HTTP/HTTPS.

Security : File SD – file‑based security; HTTP SD – TLS, Basic auth, Authorization header, OAuth2.

3. Requirements for HTTP SD Endpoints

If you implement an HTTP SD endpoint, note the following requirements.

Responses are used as‑is. At each refresh interval (default 1 minute), Prometheus sends a GET request with the header X-Prometheus-Refresh-Interval-Seconds.

The endpoint must return HTTP 200 with header Content-Type: application/json and UTF‑8 charset. If the target list is empty, it must still return HTTP 200 with an empty list []. The target list is unordered.

Prometheus caches the current target list; on errors it continues using the cached list. The list is not persisted across restarts.

Each request must return the full target list; incremental updates are not supported. The SD endpoint cannot know whether the request follows a restart.

The URL should consider security; authentication and API keys must be passed via appropriate mechanisms. Prometheus supports TLS, basic auth, OAuth2, and authorization headers.

4. HTTP SD JSON Format

[
  {
    "targets": ["<host>", ...],
    "labels": {
      "<labelname>": "<labelvalue>", ...
    }
  },
  ...
]

Example:

[
    {
        "targets": ["10.0.10.2:9100","10.0.10.3:9100","10.0.10.4:9100","10.0.10.5:9100"],
        "labels": {
            "__meta_datacenter": "london",
            "__meta_prometheus_job": "node"
        }
    },
    {
        "targets": ["10.0.40.2:9100","10.0.40.3:9100"],
        "labels": {
            "__meta_datacenter": "london",
            "__meta_prometheus_job": "alertmanager"
        }
    },
    {
        "targets": ["10.0.40.2:9093","10.0.40.3:9093"],
        "labels": {
            "__meta_datacenter": "newyork",
            "__meta_prometheus_job": "alertmanager"
        }
    }
]

Conclusion

Using Prometheus HTTP SD makes it easy to collect service lists from Spring Cloud, eliminating the need for Eureka or Nacos users to emulate Consul interfaces.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Cloud NativeJSONHTTP Service Discovery
Java Architecture Diary
Written by

Java Architecture Diary

Committed to sharing original, high‑quality technical articles; no fluff or promotional content.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.