Skip to main content

collectd-prometheus

A collectd Python plugin to read Prometheus metrics endpoints

Installation

  1. Find out which version of Python your collectd is built against to know which python/pip binary to use. So e.g. with Debian:
    $ dpkg -S python.so | grep collectd
    collectd-core: /usr/lib/collectd/python.so
    $ ldd /usr/lib/collectd/python.so | grep python
    libpython2.7.so.1.0 => /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0 (0x00007f953a5c2000)
    $
    
    which uses Python 2.7 still so I need to use pip2 when installing the dependencies.
  2. Install collectd-prometheus:
    # pip2 install collectd-prometheus
    

Usage

  1. Create a collectd configuration e.g. /etc/collectd/collectd.conf.d/prom-service.conf
LoadPlugin python
<Plugin python>
    Import "collectd_prometheus"
    <Module "collectd_prometheus">
       Interval 30 # How often to scrape metrics. This is the default, can be omitted
       <Process>
           Process "mycoolservice" # Name this instance, e.g. after what service you're scraping
           Protocol "http" # This is default, can be omitted
           Host "127.0.0.1" # This is default, can be omitted
           Port "8080" # This is default, can be omitted
           Filter "only|these" # A regex which matches the names of the metrics you only want to include
           Filter "metrics" # You can even specify multiple regexes
       </Process>
       # Scrape another another service as well, e.g.
       <Process>
           Process "anothercoolservice"
           # This time we use the defaults, except Port
           Port "8081"
       </Process>
    </Module>
</Plugin>

Using a virtualenv

In Python, using a virtual environment is the recommended way to isolate your applications dependencies from other applications. To use a virtualenv with collectd we have to create one, activate it, install our package into it.

  1. Using the steps listed Installation figure out which Python version collectd uses.

  2. If python3 use venv which is included in Python 3. When using Python 2.7, we have to install virtualenv which can be packaged in your OS/distribution (python-virtualenv in Debian) or you install it manually, see the linked documentation.

  3. Create your virtualenv where you want to store it, e.g:

    # python -m virtualenv /usr/lib/collectd/prom
    
  4. Activate it and install our package, e.g.:

    # source /usr/lib/collectd/prom/bin/activate
    (prom) # pip install collectd-prometheus
    
  5. Find your virtualenvs site-packages folder, e.g:

    # find /usr/lib/collectd/prom/ -type d -iname "site-packages"
    /usr/lib/collectd/prom/lib/python2.7/site-packages
    
  6. Configure collectd to look for collectd-prometheus and it's dependencies in the directory that you found in step 5. E.g:

    LoadPlugin python
    <Plugin python>
        ModulePath "/usr/lib/collectd/prom/lib/python2.7/site-packages" # Right here
        Import "collectd_prometheus"
    […]
    

Metadata

Release files for collectd-prometheus 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for collectd-prometheus 0.2.0
File Size Uploaded
collectd-prometheus-0.2.0.tar.gz 8.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for collectd-prometheus 0.2.0
File Interpreter ABI Platform
collectd_prometheus-0.2.0-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 16.1 kB

Release files / collectd-prometheus-0.2.0.tar.gz

Download URL collectd-prometheus-0.2.0.tar.gz
Size 8.0 kB
Tags Source
SHA-256 checksum
How to use checksums
ee05393200ab548227ebfddfb1954b1d649c0bb64ebf0a3415b9cc3965092fdb
BLAKE2b-256 checksum
How to use checksums
964d50019ccf2a8237d3a80626c95aebb87f5e4467cfc86bd65cd55db8e86f97
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.6 CPython/3.9.13 Linux/5.15.0-1017-azure

Release files / collectd_prometheus-0.2.0-py2.py3-none-any.whl

Download URL collectd_prometheus-0.2.0-py2.py3-none-any.whl
Size 8.1 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
49a23694e4faba58d716e49f960f717f0e7061683850f7ca0a20ac5c8278c1c7
BLAKE2b-256 checksum
How to use checksums
61227f325fd3215aced783bb0faea9ee74d4f93cbd4108667ccd9684cb140bd7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.6 CPython/3.9.13 Linux/5.15.0-1017-azure

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page