Skip to main content

用于读取 Prometheus 指标端点的 collectd 插件

项目描述

收集普罗米修斯

用于读取 Prometheus 指标端点的 collectd Python 插件

安装

  1. 找出您的 collectd 是针对哪个版本的 Python 构建的,以了解要使用的 python/pip 二进制文件。因此,例如使用 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)
    $
    
    它仍然使用 Python 2.7,所以我需要pip2在安装依赖项时使用。
  2. 安装collectd-prometheus:
    # pip2 install collectd-prometheus
    

用法

  1. 创建一个collectd配置,例如 /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>

使用虚拟环境

在 Python 中,推荐使用虚拟环境将您的应用程序依赖项与其他应用程序隔离开来。要将 virtualenv 与 collectd 一起使用,我们必须创建一个,激活它,将我们的包安装到其中。

  1. 使用列出的安装步骤找出 collectd 使用的 Python 版本。

  2. 如果使用 Python 3 中包含的 python3 venv。使用 Python 2.7 时,我们必须安装 virtualenv,它可以打包在您的操作系统/发行版中(python-virtualenv在 Debian 中),或者您手动安装它,请参阅链接文档。

  3. 在您想要存储它的地方创建您的 virtualenv,例如:

    # python -m virtualenv /usr/lib/collectd/prom
    
  4. 激活它并安装我们的包,例如:

    # source /usr/lib/collectd/prom/bin/activate
    (prom) # pip install collectd-prometheus
    
  5. 找到您的 virtualenvs 站点包文件夹,例如:

    # find /usr/lib/collectd/prom/ -type d -iname "site-packages"
    /usr/lib/collectd/prom/lib/python2.7/site-packages
    
  6. 配置 collectd 以collectd-prometheus在您在步骤 5 中找到的目录中查找它的依赖项。例如:

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

项目详情


下载文件

下载适用于您平台的文件。如果您不确定要选择哪个,请了解有关安装包的更多信息。

源分布

collectd-prometheus-0.2.0.tar.gz (8.0 kB 查看哈希)

已上传 source

内置分布

collectd_prometheus-0.2.0-py2.py3-none-any.whl (8.1 kB 查看哈希)

已上传 py2 py3