Service Discovery consul : Only scrapped the node with check passed

74 views
Skip to first unread message

Alain delbot

unread,
Feb 19, 2021, 11:35:20 AM2/19/21
to Prometheus Users
Hi,

how configure the scrapping to call only nodes that the check service is passed ?

Like a use on API health/checks/w2-build-node_exporters  with filetring en Status.

Is it possible ?

Like : 
[
  {
    "CheckID": "node_exporter",
    "Name": "HTTP on port 9101",
    "Status": "passing",
    "Notes": "",
    "Output": "HTTP GET http://localhost:9101/health: 200 OK Output: {\"status\":\"ok\"}\n",
    "ServiceID": "w2-build-node_exporters",
    "ServiceName": "w2-build-node_exporters",
    "ServiceTags": [
      "prometheus",
      "windows",
      "60s"
    ],
    "Type": "http",
    "Definition": {},
    "CreateIndex": 63360,
    "ModifyIndex": 63360
  },
  {
    "CheckID": "node_exporter_check",
    "Name": "Check Health on Port 9100",
    "Status": "critical",
    "Notes": "",
    "Output": "Get \"http://wdya2747:9100/health\": dial tcp 10.10.10.10:9100: connect: connection refused",
    "ServiceID": "w2-build-node_exporters",
    "ServiceName": "w2-build-node_exporters",
    "ServiceTags": [
      "prometheus",
      "linux",
      "60s"
    ],
    "Type": "http",
    "Definition": {},
    "CreateIndex": 79172,
    "ModifyIndex": 79172
  }
]


BR

Alain

David Leadbeater

unread,
Feb 19, 2021, 12:32:49 PM2/19/21
to Alain delbot, Prometheus Users
On Fri, 19 Feb 2021 at 16:35, Alain delbot <alain....@gmail.com> wrote:
> how configure the scrapping to call only nodes that the check service is passed ?


Per
https://prometheus.io/docs/prometheus/latest/configuration/configuration/#consul_sd_config
there is a __meta_consul_health

Which you can use in the relevant scrape config with something like:

- job_name: consul-jobs
consul_sd_configs:
...
relabel_configs:
- source_labels: [__meta_consul_health]
action: keep
regex: passing

Although it may be better to action: drop with critical, rather than
only looking at passing ones depending on what you need to happen for
other states.

David
Reply all
Reply to author
Forward
0 new messages