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

For now we Support Nautobot 1.6. All relevant target versions are tested in CI. Have a look at the Github Actions definition for the current build targets.

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-1.6.0.tar.gz (12.9 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-1.6.0-py3-none-any.whl (12.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: nautobot_prometheus_sd-1.6.0.tar.gz
  • Upload date:
  • Size: 12.9 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-1.6.0.tar.gz
Algorithm Hash digest
SHA256 37419601356c44e726d310b3f02d249178d3ba1425dcbbd32edf99ed4c93091e
MD5 16fbe3cece682d9e268bf445756a2f1c
BLAKE2b-256 07751d92dd70484ec670c10f9f7d93ac669713196f6c125f6de4173d5a6e0dea

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for nautobot_prometheus_sd-1.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 166a3bb631d855796b21b3b7797c5a975918d52afa01ca4d8c7b20783019f9aa
MD5 c4c81e749f22dd738a53f71023c29d28
BLAKE2b-256 9deccd9ffe5a816ca9524447e275eb8960bd7441e5985df5eba7eea844faf6c7

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