Giter VIP home page Giter VIP logo

collectd-prometheus's Introduction

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"
    […]

collectd-prometheus's People

Contributors

ryarnyah avatar simmel avatar skob avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

skob

collectd-prometheus's Issues

Working configuration example

Hey!

Thanks for creating this, looks awesome!

I've been struggling to get it working the last couple of hours. I can't get it to change the default config.

This is the config I've been using:

LoadPlugin python
<Plugin python>
    ModulePath "/local/collectd/prom/lib/python2.7/site-packages"
    Import "collectd-prometheus"
    <Module "collectd-prometheus">
       Interval 5
       Protocol https
       SslIgnore True
       Port 2379
    </Module>
</Plugin>
systemd[1]: Starting Statistics collection and monitoring daemon...
[…]
collectd[29004]: plugin_load: plugin "python" successfully loaded.
collectd[29004]: Systemd detected, trying to signal readyness.
collectd[29004]: Initialization complete, entering read-loop.

and then nothing. Other metrics collected are sent fine, but not the prometheus-scraped ones.

I noticed that if I added the config:

       Process anythingreally

it started up but only using the default settings.

What am I doing wrong?

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.