Skip to main content

A Nautobot plugin to provide Netbox entires to Prometheus HTTP service discovery

Project description

I have found the following plugin: https://pypi.org/project/nautobot-plugin-prometheus-sd/ which is fork of https://github.com/FlxPeters/netbox-plugin-prometheus-sd, but without available source code, so copied the code to new repo, fixed the plugin for nautobot v1.6 and fixed tests. The most of the codebase belongs to user dubcl and Felix Peters.

nautobot-plugin-prometheus-sd

License: MIT CI PyPI

Provide Prometheus http_sd compatible API Endpoint with data from Nautobot.

HTTP SD is a new feature in Prometheus 2.28.0 that allows hosts to be found via a URL instead of just files. This plugin implements API endpoints in Nautobot to make devices, IPs and virtual machines available to Prometheus.

Compatibility

All relevant target versions are tested in CI. Have a look at the Github Actions definition for the current build targets. We can't ensure plugin will work with all versions of nautobot. But 1.. version should be fine for nautobot <2.., and 2.. should be compatible with respective nautobot 2.. versions.

Installation

Generic guide how to work with plugins can be found in Nautobot documentation: https://docs.nautobot.com/projects/core/en/v1.6.23/plugins/#installing-plugins

  1. pip install nautobot-plugin-prometheus-sd or add nautobot-plugin-prometheus-sd in local_requirements.txt of Nautobot.
  2. In Nautobot configuration add:
PLUGINS = ['nautobot_prometheus_sd']

Usage

The plugin only provides a new API endpoint on the Nautobot API. There is no further action required after installation.

API

The plugin reuses Nautobot API view sets with new serializers for Prometheus. This means that all filters that can be used on the Netbox api can also be used to filter Prometheus targets. Paging is disabled because Prometheus does not support paged results.

The plugin also reuses the Nautobot authentication and permission model. Depending on the Nautobot configuration, a token with valid object permissions must be passed to Nautobot.

GET        /api/plugins/prometheus-sd/devices/              Get a list of devices in a prometheus compatible format
GET        /api/plugins/prometheus-sd/virtual-machines/     Get a list of vms in a prometheus compatible format
GET        /api/plugins/prometheus-sd/ip-addresses/         Get a list of ip in a prometheus compatible format

Example

After Plugin is installed in Nautobot, the prometheus can start to retrieve endpoints for scrapping using the following scrape config:

scrape_configs:
  # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
  - job_name: "prometheus"

    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.

    static_configs:
      - targets: ["localhost:9090"]
       # The label name is added as a label `label_name=<label_value>` to any timeseries scraped from this config.
        labels:
          app: "prometheus"
  - job_name: "sql_exporter"
    http_sd_configs:
        - url: http://10.248.113.8:8080/api/plugins/prometheus-sd/virtual-machines?status=active&tag=psql
          refresh_interval: 15s
          authorization:
            type: "Token"
            credentials: "LcQ27bHXgrd0TKIfJ3LchLFsOkVkK38TWa6uYuuh"
    relabel_configs:
      # Labels which control scraping
      - source_labels: [__meta_netbox_name]
        target_label: instance
      - source_labels: [__meta_netbox_primary_ip4]
        regex: '(.+)'
        target_label: __address__
      - source_labels: [__address__]
        target_label: __address__
        replacement: '${1}:9399'
      # Optional extra metadata labels
      - target_label: 'exp_type'
        replacement: 'pg'
      - target_label: 'cluster_name'
        replacement: 'crunchy'

In the config above, we are retrieving lists of lists of key value pairs. Every list of kv pairs is transformed using relabel_configs in order to provide __address__ for the prometheus to scrape from. Additionally we are adding some static labels to the scraped targets. Excesive labels can be dropped.

Development

Generic guide how to develope plugin can be found in Nautobot documentation: https://docs.nautobot.com/projects/core/en/v1.6.18/plugins/development/

Currently, we do not have well automated way of plugin development environment.

  1. Install nautobot according to: https://docs.nautobot.com/projects/core/en/stable/user-guide/administration/installation/nautobot/
  2. Clone this repository to the local machine.
  3. The plugin should be installed in the same venv where Nautobot is running. Usually source /opt/nautobot/bin/activate (but could differ if you installed venv in different location).
  4. Install plugin with poetry install (poetry should be installed already).

Visit http://localhost:8000 and log in with the new user. You can now define Netbox entities and test around.

API endpoints for testing can be found at http://localhost:8000/api/plugins/prometheus-sd/

For tests the following command can be used: nautobot-server test .

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nautobot_prometheus_sd-2.4.13.tar.gz (12.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nautobot_prometheus_sd-2.4.13-py3-none-any.whl (12.6 kB view details)

Uploaded Python 3

File details

Details for the file nautobot_prometheus_sd-2.4.13.tar.gz.

File metadata

  • Download URL: nautobot_prometheus_sd-2.4.13.tar.gz
  • Upload date:
  • Size: 12.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for nautobot_prometheus_sd-2.4.13.tar.gz
Algorithm Hash digest
SHA256 e4ce3c04228f982528f6daf51fd6077396beade4512ce79f140e136fa482f8a7
MD5 d465eb8a66ec5acbf4a098956cf3cfc3
BLAKE2b-256 01be00bd074708828d526faf1416f2b2304cc2d023dd84075070c25289eef076

See more details on using hashes here.

File details

Details for the file nautobot_prometheus_sd-2.4.13-py3-none-any.whl.

File metadata

File hashes

Hashes for nautobot_prometheus_sd-2.4.13-py3-none-any.whl
Algorithm Hash digest
SHA256 9ffd370d0ac1df471bfd8894ae8bfd4bc95b57435edfccb6a2851e6b9b53bff3
MD5 204a58670875ead049d26ae54d899b29
BLAKE2b-256 3170418c29a7d7a61cd5014af78b5e4628132d3a207cbc0a64e74e848da3d900

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page