Prometheus 数据源¶
概要¶
Prometheus 数据源允许 Watcher 使用 Prometheus 服务器作为收集的指标的来源,这些指标被 Watcher 决策引擎使用。 部署者至少必须配置 Prometheus 服务器正在监听的 host 和 port。
需求¶
Prometheus 指标需要包含一个标签来标识指标收集自哪个导出器的主机名。 这用于与 Watcher 集群模型 ComputeNode.hostname 进行匹配。 此标签的默认值为 fqdn,在 Prometheus scrape 配置中看起来如下
scrape_configs:
- job_name: node
static_configs:
- targets: ['10.1.2.3:9100']
labels:
fqdn: "testbox.controlplane.domain"
如果部署者使用不同的标签来标识导出器主机(例如 hostname 或 host,或任何其他标识主机的标签),则可以覆盖此默认值。
在内部,此标签用于创建 fqdn_instance_labels,其中包含 Prometheus 目标中分配给该标签的值列表。 结果 fqdn_instance_labels 的元素预计与 Watcher 决策引擎集群模型中使用的 ComputeNode.hostname 匹配。 一个示例 fqdn_instance_labels 如下
[
'ena.controlplane.domain',
'dio.controlplane.domain',
'tria.controlplane.domain',
]
对于实例指标,Prometheus 需要在每个相关指标中包含 OpenStack 实例的 uuid 的标签。 默认情况下,数据源将查找标签 resource。 watcher.conf 中的 instance_uuid_label 配置选项允许部署者将其默认值覆盖为存储 uuid 的任何其他标签名称。
限制¶
当前实现不支持 Watcher class DataSourceBase 的 statistic_series 函数。 预计实现(已实现)的 statistic_aggregation 函数足以提供集群中托管资源的 当前 状态。 statistic_aggregation 函数默认查询过去 300 秒的数据,从当前时间开始(时间段是函数参数,可以根据需要设置为所需的值)。 如果感兴趣的各方自愿提供必要的工作周期,则可以随时重新访问实现 statistic_series。
关于已实现 statistic_aggregation 函数的一个进一步说明。 此函数定义了一个 granularity 参数,用于在查询 Watcher DataSourceBase 指标提供程序中的任何一个时使用。 在 Prometheus 的情况下,我们不会在指定的时间段内获取然后处理单个指标。 相反,我们使用 PromQL 查询运算符和函数,以便服务器本身处理指定参数中的请求,然后返回结果。 因此,granularity 参数是多余的,并且对于 Prometheus 实现的 statistic_aggregation 仍然未使用。 Prometheus 服务器获取的数据的粒度在配置中指定为服务器 scrape_interval(当前默认值为 15 秒)。
配置¶
部署者必须将 datasources 参数设置为包含 prometheus 在 watcher.conf 的 watcher_datasources 部分下(或者,如果需要,可以在特定策略的 datasources 中添加 prometheus,例如在 [watcher_strategies.workload_stabilization] 部分下)。
watcher.conf 配置文件还用于设置 Watcher Prometheus 数据源所需的参数值。 配置可以添加到 [prometheus_client] 部分,并且可用的选项如下所示,它们是自文档化的
cfg.StrOpt('host',
help="The hostname or IP address for the prometheus server."),
cfg.StrOpt('port',
help="The port number used by the prometheus server."),
cfg.StrOpt('fqdn_label',
default="fqdn",
help="The label that Prometheus uses to store the fqdn of "
"exporters. Defaults to 'fqdn'."),
cfg.StrOpt('instance_uuid_label',
default="resource",
help="The label that Prometheus uses to store the uuid of "
"OpenStack instances. Defaults to 'resource'."),
cfg.StrOpt('username',
help="The basic_auth username to use to authenticate with the "
"Prometheus server."),
cfg.StrOpt('password',
secret=True,
help="The basic_auth password to use to authenticate with the "
"Prometheus server."),
cfg.StrOpt('cafile',
help="Path to the CA certificate for establishing a TLS "
"connection with the Prometheus server."),
cfg.StrOpt('certfile',
help="Path to the client certificate for establishing a TLS "
"connection with the Prometheus server."),
cfg.StrOpt('keyfile',
help="Path to the client key for establishing a TLS "
"connection with the Prometheus server."),
host 和 port 是 必需 的配置选项,没有设置默认值。 这些指定 Prometheus 服务器正在监听的主机名(或 IP)和端口。 fqdn_label 允许部署者覆盖用于将 Prometheus 节点导出器与 Watcher 决策引擎集群数据模型中的 Watcher ComputeNodes 匹配的必需指标标签。 默认值为 fqdn,部署者可以指定任何其他值(例如,如果他们具有等效但不同的标签,例如 host)。
因此,配置为使用 Prometheus 服务器在 10.2.3.4:9090 的示例 watcher.conf 如下所示
[watcher_datasources]
datasources = prometheus
[prometheus_client]
host = 10.2.3.4
port = 9090
fqdn_label = fqdn