7 Mart 2023 Salı

Prometheus Blackbox Exporter

Giriş
Açıklaması şöyle
The blackbox-exporter is an exporter that can monitor various endpoints — URLs on the Internet, your LoadBalancers in AWS, or Services in a Kubernetes cluster, such as MySQL or PostgreSQL databases.

Blackbox Exporter can give you HTTP response time statistics, response codes, information on SSL certificates, etc.
Açıklaması şöyle
The Prometheus Blackbox Exporter is an open-source tool developed under the Prometheus umbrella. Once installed, it opens an HTTP port 9115 and exposes two metric paths
1. The /metrics endpoint returns metrics about the Blackbox Exporter running
2. The /probe endpoint retrieves metrics from a target supplied as a request parameter.

The latter is the more interesting endpoint, allowing us to check multiple targets. Targets can be HTTP endpoints, but ICMP (Ping), DNS, or raw TCP is also permitted (see the documentation for details).
probe Endpoint
Açıklaması şöyle
The /probe endpoint accepts the following parameters :
target - the HTTP endpoint to check (e.g. https://ping7.io)
module - the response check we want to conduct. OOTB, the Blackbox exporter comes with the http_2xx and the http_post_2xx module. Both check for a 2xx HTTP response code and query the target via HTTP GET or POST request.
debug - can be set to true to retrieve debug information for the current probe.

You can verify your Blackbox Exporter installation by calling it via 
curl:curl "http://localhost:9115/probe?target=https://ping7.io&module=http_2xx"
relabel_configs 
Açıklaması şöyle
Using the magic of relabel_configs in Prometheus, you can query multiple search terms in a single scrape job definition.
Örnek
Şöyle yaparız
scrape_configs:
- job_name: 'blackbox'
    metrics_path: /blackbox/probe
    scheme: https
    authorization:
      # Your ping7.io API token stored in this file
      credentials_file: ping7io-api-token
    params:
      module: [http_2xx]
      target: ["https://www.zalando.de/katalog/"]
    static_configs:
      - targets:
        - schuhe
        - hose
    - schwarz
    - sale
    relabel_configs:
      # store target as search_term
      - source_labels: [__address__]
        regex: '(.*)'
        target_label: search_term

      # build new target by concatenating
      # target param and static target config
      - source_labels: [__param_target, __address__]
        separator: "?q="
        target_label: __param_target

      # store new target as instance
      - source_labels: [__param_target]
        target_label: instance

      # use the ping7.io exporter endpoint
      - target_label: __address__
        replacement: check.ping7.io
Açıklaması şöyle
... you list the search terms to query as targets. In the relabel_configs we append them to the target parameter and query the Blackbox Exporter for response time metrics for this specific search term.

In the example below, we query https://www.zalando.de/katalog/?q=schuhe as a first target for response times. After relabeling, the Prometheus is scraping the URL https://check.ping7.io/blackbox/probe?target=https://www.zalando.de/katalog/?q=schuhe&module=http_200 for metrics. And the best thing is: you can add as many search terms as you like.





Hiç yorum yok:

Yorum Gönder