Blackbox exporter: Difference between revisions

From wikinotes
m (Will moved page Prometheus blackbox exporter to Blackbox exporter without leaving a redirect)
 
(13 intermediate revisions by the same user not shown)
Line 1: Line 1:
Prometheus exporter that probes endpoints over HTTP/HTTPS/DNS/TCP/ICMP.
[[prometheus]] exporter that probes endpoints over HTTP/HTTPS/DNS/TCP/ICMP.


= Documentation =
= Documentation =
Line 18: Line 18:
|-
|-
| <code>9115</code> || default port
| <code>9115</code> || default port
|-
| <code>http://localhost:9115</code> || simple web-ui, with sample probe to prometheus.io
|-
|-
| <code>${PREFIX}/etc/blackbox_exporter.yml</code> || config
| <code>${PREFIX}/etc/blackbox_exporter.yml</code> || config
Line 24: Line 26:
</blockquote><!-- Locations -->
</blockquote><!-- Locations -->


= Install =
= Notes =
<blockquote>
<blockquote>
<syntaxhighlight lang="bash">
{| class="wikitable"
pacman -S prometheus-blackbox-exporter  # Archlinux
|-
pkg install blackbox_exporter          # FreeBSD
| [[blackbox_exporter install]]
</syntaxhighlight>
|-
</blockquote><!-- Install -->
| [[blackbox_exporter configuration]]
 
|-
= Configuration =
| [[blackbox_exporter usage]]
<blockquote>
|-
* You define your own test-modules (endpoints test-conditions) in <code>blackbox_exporter.yml</code>.
| [[blackbox_exporter debugging]]
* You configure test-modules to test endpoints with in your <code>prometheus.yml</code>.
|-
 
|}
== Define Test-Modules ==
</blockquote><!-- Notes -->
<blockquote>
<syntaxhighlight lang="yaml">
# /usr/local/etc/blackbox_exporter.yml
 
modules:
  https_2xx:
    prober: http
    timeout: 5s
    http:
      valid_status_codes: [2]  # any 2xx status
      fail_if_not_ssl: true
      no_follow_redirects: true
      preferred_ip_protocol: ip4
 
  http_401:
    prober: http
    timeout: 5s
    http:
      valid_status_codes: [401]
      method: GET
      fail_if_not_ssl: true
      no_follow_redirects: true
      preferred_ip_protocol: ip4
</syntaxhighlight>
 
Here we configure two test-modules.<br>
The first tests for a HTTP-2XX return-code, the second for an HTTP-401.
 
See the sample config where all options/types are documented.
</blockquote><!-- Define Test-Modules -->
 
== Use Modules ==
<blockquote>
<syntaxhighlight lang="yaml">
# /usr/local/etc/prometheus.yml
 
global:
  scrape_interval: 120s
 
scrape_configs:
  - job_name: https_2xx
    params:
      module: [https_2xx]
    static_configs:
      - targets:
        - https://foo.com
        - https://bar.net
    relabel_configs:
      - source_labels: [__address__]
        target_label: __param_target
      - source_labels: [__param_target]
        target_label: instance
      - target_label: __address__
        replacement: 127.0.0.1:9115
 
</syntaxhighlight>
 
This config creates a scrape-job that uses our <code>http_2xx</code> module to test both <code>https://foo.com</code> and <code>https://bar.net</code>.
</blockquote><!-- Use Modules -->
</blockquote><!-- Configuration -->
 
= Testing =
<blockquote>
<syntaxhighlight lang="bash">
/usr/bin/env /usr/local/bin/blackbox_exporter \
  --web.listen-address=127.0.0.1:9115 \
  --config.file=/usr/local/etc/blackbox_exporter.yml
</syntaxhighlight>
</blockquote><!-- Testing -->
 
= Usage =
<blockquote>
== Routes ==
<blockquote>
When debugging, it's worth it to look at the debug logs.<br>
Your relabeling rules may cause you to query the incorrect domain!
 
<syntaxhighlight lang="bash">
# query metrics for target/module
curl -v 'localhost:9115/probe\?module=http_2xx\&target=https://willpittman.net\&debug=true'
 
w3m 'http://localhost:9115/probe\?module=http_2xx\&target=https://willpittman.net\&debug=true'
</syntaxhighlight>
</blockquote><!-- Routes -->
 
== Metrics ==
<blockquote>
The docs suggest <code>probe_success</code> but I don't have it on FreeBSD-13.<br>
Instead, I have:
 
* <code>up</code>
* <code>promhttp_metric_handler_requests_total</code>
 
<syntaxhighlight lang="promql">
up{instance="https://willpittman.net"}
absent_over_time(promhttp_metric_handler_requests_total{instance="https://willpittman.net", code="200"}[1s])
</syntaxhighlight>
</blockquote><!-- Rules -->
</blockquote><!-- Usage -->
 
= Debugging =
<blockquote>
The best method of testing seems to be from a web-browser (not w3m).<br>
The query target seems fixed against <code>prometheus.io</code>, if that works it should work for most simple cases.
 
<syntaxhighlight lang="yaml">
- open:  http://${IP}:9115/probe?target=https://willpittman.net&module=http_2xx&debug=true
- click: 'Logs' in a failed recent probe
- see:  request logs are at the top
- see:  at the very bottom, you're looking for 'probe_success 1'
</syntaxhighlight>
</blockquote><!-- Debugging -->

Latest revision as of 14:31, 20 February 2022

prometheus exporter that probes endpoints over HTTP/HTTPS/DNS/TCP/ICMP.

Documentation

github https://github.com/prometheus/blackbox_exporter
config syntax https://github.com/prometheus/blackbox_exporter/blob/master/CONFIGURATION.md
example config https://github.com/prometheus/blackbox_exporter/blob/master/example.yml

Locations

9115 default port
http://localhost:9115 simple web-ui, with sample probe to prometheus.io
${PREFIX}/etc/blackbox_exporter.yml config

Notes

blackbox_exporter install
blackbox_exporter configuration
blackbox_exporter usage
blackbox_exporter debugging