Skip to content

Service discovery

Mikhail Grigorev edited this page Jan 27, 2025 · 6 revisions

Starting with pgSCV 0.10.0, it has become possible to split the /metrics endpoint into a per-service version in the form of /metrics?target=service_name endpoints, and the /targets endpoint is also available, which contains a list of all endpoints in json format for setting up automatic endpoint discovery in using VictoriaMetrics (http_sd_configs).

Example configuration for VictoriaMetric:

global:
  scrape_interval: 30s

scrape_configs:
  - job_name: 'pgscv'
    http_sd_configs:
      - url: http://X.X.X.X:9890/targets

The output of the /targets endpoint will be a list of all active URLs in json format for each service. For example, for a configuration /etc/pgscv.yaml of this type:

listen_address: 0.0.0.0:9890
services:
  "postgres1":
    service_type: "postgres"
    conninfo: "postgres://pgscv:pa$$w0rd@127.0.0.1:5432/postgres"
  "postgres2": 
    service_type: "postgres"
    conninfo: "postgres://pgscv:pa$$w0rd@127.0.0.1:5433/postgres"
  "postgres3": 
    service_type: "postgres"
    conninfo: "postgres://pgscv:pa$$w0rd@127.0.0.1:5434/postgres"

For example, a /targets output

# curl -sL http://127.0.0.1:9890/targets | jq .
[
  {
    "targets": [
      "127.0.0.1:9890/metrics?target=system:0",
      "127.0.0.1:9890/metrics?target=postgres1",
      "127.0.0.1:9890/metrics?target=postgres2",
      "127.0.0.1:9890/metrics?target=postgres3"
    ]
  }
]
Clone this wiki locally