用于读取 Prometheus 指标端点的 collectd 插件
项目描述
收集普罗米修斯
用于读取 Prometheus 指标端点的 collectd Python 插件
安装
- 找出您的 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在安装依赖项时使用。 - 安装
collectd-prometheus:# pip2 install collectd-prometheus
用法
- 创建一个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 一起使用,我们必须创建一个,激活它,将我们的包安装到其中。
-
使用列出的安装步骤找出 collectd 使用的 Python 版本。
-
如果使用 Python 3 中包含的 python3
venv。使用 Python 2.7 时,我们必须安装 virtualenv,它可以打包在您的操作系统/发行版中(python-virtualenv在 Debian 中),或者您手动安装它,请参阅链接文档。 -
在您想要存储它的地方创建您的 virtualenv,例如:
# python -m virtualenv /usr/lib/collectd/prom
-
激活它并安装我们的包,例如:
# source /usr/lib/collectd/prom/bin/activate (prom) # pip install collectd-prometheus
-
找到您的 virtualenvs 站点包文件夹,例如:
# find /usr/lib/collectd/prom/ -type d -iname "site-packages" /usr/lib/collectd/prom/lib/python2.7/site-packages
-
配置 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-py2.py3-none-any.whl 的哈希值
| 算法 | 哈希摘要 | |
|---|---|---|
| SHA256 | 49a23694e4faba58d716e49f960f717f0e7061683850f7ca0a20ac5c8278c1c7 |
|
| MD5 | 0a048e85108a90791597e446472f39e6 |
|
| 布莱克2-256 | 61227f325fd3215aced783bb0faea9ee74d4f93cbd4108667ccd9684cb140bd7 |