Nginx service discovery to use with Prometheus and the Blackbox Exporter
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Gaël Berthaud-Müller 2820348ec5 update readme 4 days ago
nginx_site_discovery update readme 4 days ago
.gitignore first commit 1 year ago
LICENSE add basic readme 11 months ago
README.md update readme 4 days ago
setup.py bump version 11 months ago

README.md

Nginx site discovery

This repo provides a tool to use as both a service discovery sidecar for Prometheus and a discovery agent. The tool watches Nginx configuration file for changes and either write the service discovery file to the provided path or send it to a server for centralisation.

Configuration

  • To disable a single website from being scraped append # monitoring:ignore after the listen directive.
    listen 10.114.1.1:8032; # monitoring:ignore
    
  • To configure the healthcheck URL, that is used for example with the Blackbox exporter
    server_name example.com; # monitoring:healthcheck_url=/health
    

Command line usage

usage: nginx-sites-discovery [-h] [-l [LABELS [LABELS ...]]] [-s [LISTEN]] [-o OUTPUT_FILE] [-d OUTPUT_DIR] [-u SERVER_URL] [-e SITES_ENABLED] [-n] [-x EXTENSION]

Watch Nginx configuration to create files for service discovery

optional arguments:
  -h, --help            show this help message and exit
  -l [LABELS [LABELS ...]], --labels [LABELS [LABELS ...]]
                        Optional, extra labels to add to the jobs in the format key=value
  -s [LISTEN], --listen [LISTEN]
                        Optional, start a web server to listen for discovery files, if no listening address is provided the default is 127.0.0.1:4567
  -o OUTPUT_FILE, --output-file OUTPUT_FILE
                        Optional, output the discovery file to the provided path
  -d OUTPUT_DIR, --output-dir OUTPUT_DIR
                        Only valid with --listen, the directory in wich the files are dumped, default to current working directory
  -u SERVER_URL, --server-url SERVER_URL
                        Optional, post the discovery file to the provided url, should be https://<server>/<service name>/<key>.
  -e SITES_ENABLED, --sites-enabled SITES_ENABLED
                        Path to the Nginx configuration file directory, default to /etc/nginx/sites-enabled
  -n, --no-watch        Disable watching, useful for the server only mode
  -x EXTENSION, --extension EXTENSION
                        Configuration file extension, default to empty string

Prometheus config

scrape_configs:
  - job_name: 'blackbox-http'
    metrics_path: /probe
    params:
      module: [http_ok]
    file_sd_configs:
      - files:
        - '/var/lib/prometheus/discovery/nginx-*.json'

    relabel_configs:
      - source_labels: [__address__, healthcheck_url]
        separator: ''
        target_label: __param_target
      - source_labels: [__param_target]
        target_label: instance
      - target_label: __address__
        replacement: 127.0.0.1:9115