基于Python的Exalead for Prometheus
项目描述
exalead_exporter
描述
Prometheus的Exalead解决方案导出器
该导出器从Exalead HTTP API收集指标。
它是一个Python HTTP服务器,将指标暴露给http(默认端口9271),然后可以被Prometheus抓取。
可以通过将它们添加到YAML配置文件中,通过添加一个主机部分来轮询多个Exalead服务器
配置: (见config.yml)
exaleads:
- host: host.domain
port: 9398
# protocol: https
# verify_ssl: false
# timeout: 20
# keep_session: true # default
# default_labels:
# - name: veeam_em
# value: my_veeam_em_server.domain
# proxy:
# url: http://my.proxy.domain:port/
# protocol: https
weblisten:
address: 0.0.0.0
port: 9247
logger:
level: info
facility: syslog
metrics_file: "metrics/*_metrics.yml"
使用方法
导出器可以作为Unix命令运行,无需模块安装,也可以作为不带安装的独立Python脚本。
最简单的方法是使用pip安装
pip3 install --upgrade exalead-exporter
然后您可以使用模块安装器在/usr/local/bin/exalead_exporter或[venv]/bin/exalead_exporter中创建的入口点。命令行使用在venv中。
要使用导出器,需要安装一些软件包。这可以通过以下方式完成
pip3 install -r pip_requirements.txt
requirements.txt内容
xmltodict==0.12.0
tenacity==6.2.0
requests>=2.20.0
Jinja2==3.0.3
urllib3==1.24.2
prometheus_client==0.14.1
PyYAML>=5.3.1
python-dateutil>=2.7.0
- 考虑,在/tmp文件夹中提取存档文件;这将在/tmp文件夹中生成文件夹/tmp/exalead_exporter_[version]。
- 创建一个目录,例如/opt/exalead_exporter_[version],
- 将/tmp/exalead_exporter_[version]/exalead_exporter_package目录移动到/opt/eeam_exporter_[version]
- 在/opt/exalead_exporter_[version]目录中创建一个命令文件以启动导出器
vi /opt/exalead_exporter_X.Y.Z/exalead_exporter_cmd
#!/usr/libexec/platform-python
# -*- coding: utf-8 -*-
import re
import sys
from exalead_exporter.exalead_exporter import main
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
sys.exit(main())
- 然后编辑conf/config.yml文件并添加您的设置。
- 通过执行尝试模式的命令来尝试您的配置
使用默认的dumy配置文件的示例
python3 exalead_exporter_cmd -n -v
exalead_exporter[227114]: level=INFO - exalead_exporter 0.0.2 starting....
exalead_exporter[227114]: level=DEBUG - config is {'exaleads': [{'host': 'host.domain', 'port': 9398, 'verify_ssl': False, 'timeout': 20}], 'weblisten': {'address': '0.0.0.0', 'port': 9271}, 'logger': {'level': 'info', 'facility': 'syslog'}, 'metrics_file': 'metrics/*.yml'}
exalead_exporter[227114]: level=WARNING - [Errno 2] No such file or directory: '/home/users/d107684/python/exalead-exporter-package/exalead_exporter/metrics'
exalead_exporter[227114]: level=ERROR - no metrics found
exalead_exporter[227114]: level=INFO - exalead_exporter 0.0.2 stopped.
[ /home/users/d107684/python/exalead-exporter-package ]d107684@dal-v-survdadc $ python3 cli.py -v -n
exalead_exporter[228511]: level=INFO - exalead_exporter 0.0.2 starting....
exalead_exporter[228511]: level=DEBUG - config is {'exaleads': [{'host': 'host.domain', 'port': 9398, 'verify_ssl': False, 'timeout': 20}], 'weblisten': {'address': '0.0.0.0', 'port': 9271}, 'logger': {'level': 'info', 'facility': 'syslog'}, 'metrics_file': 'conf/metrics/*.yml'}
exalead_exporter[228511]: level=ERROR - Connection Exception: Host host.domain: HTTPConnectionPool(host='host.domain', port=9398): Max retries exceeded with url: /mami/ (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f02ab6be7f0>: Failed to establish a new connection: [Errno -2] Name or service not known',))
exalead_exporter[228511]: level=DEBUG - # HELP exalead_up probe success login status: 0 Down / 1 Up
exalead_exporter[228511]: level=DEBUG - # TYPE exalead_up gauge
exalead_exporter[228511]: level=DEBUG - exalead_up 0.0
exalead_exporter[228511]: level=INFO - exalead_exporter 0.0.2 stopped
导出器命令行选项
启动导出器
./exalead_exporter &
默认情况下,它将加载config.yml文件以执行操作。
详细选项
Usage: exalead_exporter [-h] [-b BASE_PATH] [-c CONFIG_FILE]
[-f LOGGER.FACILITY] [-l {error,warning,info,debug}]
[-o METRICS_FILE] [-m METRIC] [-n] [-t TARGET]
[-w WEB.LISTEN_ADDRESS] [-V] [-v]
collector for exalead.
optional arguments:
-h, --help show this help message and exit
-b BASE_PATH, --base_path BASE_PATH
set base directory to find default files.
-c CONFIG_FILE, --config_file CONFIG_FILE
path to config files.
-f LOGGER.FACILITY, --logger.facility LOGGER.FACILITY
logger facility (syslog or file path).
-l {error,warning,info,debug}, --logger.level {error,warning,info,debug}
logger level.
-o METRICS_FILE, --metrics_file METRICS_FILE
collect the metrics from the specified file instead of
config.
-m METRIC, --metric METRIC
collect only the specified metric name from the
metrics_file.
-n , --dry_mode collect the metrics then exit; display results to
stdout.
-t TARGET, --target TARGET
In dry_mode collect metrics on specified target.i
Default first from config file.
-w WEB.LISTEN_ADDRESS, --web.listen-address WEB.LISTEN_ADDRESS
Address to listen on for web interface and telemetry.
-V, --version display program version and exit..
-v , --verbose verbose mode; display log message to stdout.
要测试您的配置,您可以在dry_mode下启动导出器
./exalead_exporter -v -n -t host.domain
此命令将尝试连接到'host.domain' exaleas服务器,参数在config.yml中指定,暴露收集的指标,并最终警告或错误,然后退出。
Prometheus配置
由于可以在导出器中设置多个exalead服务器,Prometheus通过在URL中添加目标参数来识别每个服务器。"target"必须与导出器配置文件中的一致。
- job_name: "exalead"
scrape_interval: 120s
scrape_timeout: 60s
metrics_path: /metrics
static_configs:
- targets: [ exaleadhost.domain ]
labels:
environment: "PROD"
# file_sd_configs:
# - files: [ "/etc/prometheus/exalead_exp/*.yml" ]
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- source_labels: [__param_target]
target_label: instance
- target_label: __address__
replacement: "exalead-exporter-hostname.domain:9247" # The exalead exporter's real hostname.
指标
收集的指标定义在位于conf/metrics文件夹中的单独文件中。所有值、计算和标签都在指标文件中定义,这意味着导出器在值方面没有内部操作。配置完全控制值的呈现方式。
收集的指标
所有指标都在配置文件(conf/metrics/*.yml)中定义。您可以在此处检索所有指标名称。其中大多数都有帮助文本。所有指标都以前缀"exaled_"开头。
文件 | 域 | 指标 |
---|---|---|
无 | 默认 | exalead_up : 0或1。 定义exalead服务器是否可访问。 |
licence_status.yml | 通用许可证元素 | 前缀: exalead_license_ . (参见许可证仪表板) |
deploymentsStatus.yml | 通用索引过程 | 前缀: exalead_process_. (参见进程仪表板) |
connectorStatus.yml | 索引 | 前缀: exalead_connectors_. 按连接器名称进行度量 (参见进程仪表板) |
扩展指标
导出的指标在YAML配置文件中定义。值可以使用Jinja2模板语言。配置的格式灵感来自Ansible任务表示。因此,指标配置文件由执行操作的列表组成。
有五种可能的行为
- url: 从HTTP API收集指标
- set_fact: 将值分配给变量
- actions: 执行一系列(子)操作
- metrics: 定义要向Prometheus公开/返回的指标
- debug: 向记录器显示调试文本。
所有行为都有默认的"属性"
- name: 操作或指标计数的名称。
- vars: 将变量设置为全局符号表。
- with_items: 在当前操作上循环一个项目列表。
- loop_var: 设置将接收循环中当前值的变量的名称。默认为'item'。
- when: 必须检查并为真的一组条件(和)以执行操作。
"属性"按之前表格中指定的顺序分析;这意味着您不能在vars部分使用"item"变量(从'with_items'指令获得),因为它在'vars'部分评估时尚未定义。如果您需要该功能,您将不得不考虑在'actions'部分中包含'with_items'(参见metrics/connectorStatus.yml)。
操作 | 参数 | 描述 | 备注 |
---|---|---|---|
url | 表示要收集的实体的字符串,不包括'/api' | http://host.domain:port/api**[url]**. 例如:/reports/summary/overview | |
var_name | 存储结果的变量名称。默认为'_root',表示结果JSON对象直接存储在符号表中。 | ||
set_fact | 要定义的变量列表 | ||
var_name: value | |||
指标 | 定义要公开的指标列表 | ||
metric_prefix | 要添加到所有指标名称的前缀 | 最终名称将是[metric_prefix]_[metric_name] | |
'a metric' | name | 指标的名称 | |
help | 添加到指标(并在Grafana资源管理器中显示)的帮助信息 | ||
类型 'gauge' 或 'counter' | Prometheus指标的类型 | ||
值 | 数值本身 | ||
标签 | 一组用于限定指标的名称值对列表 |
项目详情
下载文件
下载适用于您的平台的文件。如果您不确定选择哪个,请了解有关安装包的更多信息。
源分布
构建分布
exalead_exporter-0.0.4.tar.gz的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | a709b066a875d7540db260d901a3601b9586a26495d737bba558fc417a3e4bb4 |
|
MD5 | 76c163dce93971e776d2357025aa2d4a |
|
BLAKE2b-256 | 2a23ae1e81f06d528e22e07aa1ff13398ba5697bca842f39c5cab1be597ea12f |
exalead_exporter-0.0.4-py3-none-any.whl的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | d63841bf2bf180e42f462f41bb2df91d185259faae35dfe12d34c113842c1c4e |
|
MD5 | 3453a32f82cdba2ea5b6cd001eaac770 |
|
BLAKE2b-256 | f470228b7e2893ff9d7dfcf7884426bc9c783815131737d21d372f8b02dc5e17 |