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.0.tar.gz (12.6 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.0-py3-none-any.whl (12.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: nautobot_prometheus_sd-2.4.0.tar.gz
  • Upload date:
  • Size: 12.6 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.0.tar.gz
Algorithm Hash digest
SHA256 6a92b1940faecb76f2312ac25f721914f2a04d51fbe9cfc1f3478509387cfc89
MD5 dc0004c03565f3c8dceb28a31192b710
BLAKE2b-256 1862faf5cb6a702442750db1fe2379ccf19313a36257f00e145d51c4df7dcd13

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for nautobot_prometheus_sd-2.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 db7809ffaeba3b4114610094bfd822c729a6a158ee125e2d5a38047833fe0a61
MD5 1395cea79dcda1eb4ea776d4ad09bb1a
BLAKE2b-256 93e6f3bb3bad912a65a9e3d00bac0c73c8363e601f6e6d7387eaf413afa4eb8a

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