prometheus.exporter.blackbox
prometheus.exporter.blackbox
组件嵌入了 blackbox_exporter
。blackbox_exporter
允许您收集黑盒指标(探测)并将其作为 Prometheus 指标暴露。
用法
prometheus.exporter.blackbox "<LABEL>" {
target {
name = "<NAME>"
address = "<EXAMPLE_ADDRESS>"
}
}
或
prometheus.exporter.blackbox "<LABEL>" {
targets = <TARGET_LIST>
}
参数
您可以将以下参数用于 prometheus.exporter.blackbox
名称 | 类型 | 描述 | 默认值 | 必需 |
---|---|---|---|---|
config_file | string | blackbox_exporter 配置文件的路径。 | 否 | |
config | string 或 secret | 将 blackbox_exporter 配置作为内联字符串。 | 否 | |
probe_timeout_offset | duration | 探测目标时从超时时间中减去的秒数偏移量。 | "0.5s" | 否 |
targets |
| 黑盒目标。 | 否 |
必须指定 config_file
或 config
中的一个。config_file
参数指向一个 YAML 文件,该文件定义要使用的 blackbox_exporter
模块。config
参数必须是一个 YAML 文档字符串,该字符串定义要使用的 blackbox_exporter
模块。config
通常通过使用另一个组件的导出项来加载。例如
local.file.LABEL.content
remote.http.LABEL.content
remote.s3.LABEL.content
在 config
或 config_file
中的 timeout
属性的有效上限为 10 秒。有关更多信息,请参阅 Prometheus blackbox exporter 问题 #751。
在同一配置文件中,不能同时使用 targets
参数和 target 块。当黑盒目标不能作为 target 块传递,因为它们是由另一个组件提供的时,必须使用 targets
参数。
您可以为目标设置以下标签
name
: 要探测的目标名称(必需)。address
: 要探测的目标地址(必需)。module
: 用于探测的黑盒模块。
该组件会将任何附加标签传递给导出的目标。
有关生成配置文件的更多信息,请参阅 blackbox_exporter
。
块
您可以将以下块用于 prometheus.exporter.blackbox
名称 | 描述 | 必需 |
---|---|---|
target | 配置一个黑盒目标。 | 否 |
target
名称 | 类型 | 描述 | 默认值 | 必需 |
---|---|---|---|---|
address | string | 要探测的目标地址。 | 是 | |
name | string | 要探测的目标名称。 | 是 | |
labels |
| 要添加到目标的标签。 | 否 | |
module | string | 用于探测的黑盒模块。 | "" | 否 |
target
块定义一个单独的黑盒目标。可以多次指定 target
块以定义多个目标。name
属性是必需的,并用于目标的 job
标签中。
在 labels
参数中指定的标签不会覆盖由 blackbox_exporter
设置的标签。
导出字段
以下字段是导出的,可以被其他组件引用。
名称 | 类型 | 描述 |
---|---|---|
targets |
| 可用于收集 exporter 指标的目标。 |
例如,targets
可以传递给 discovery.relabel
组件来重写目标的标签集,或者传递给 prometheus.scrape
组件来收集暴露的指标。
导出的目标使用由 run 命令 指定的配置好的内存流量地址。
组件健康状态
prometheus.exporter.blackbox
仅在给定无效配置时报告不健康。在这些情况下,导出字段保留其最后一个健康值。
调试信息
prometheus.exporter.blackbox
不暴露任何组件特定的调试信息。
调试指标
prometheus.exporter.blackbox
不暴露任何组件特定的调试指标。
示例
使用 blackbox exporter 配置文件收集指标
此示例使用 prometheus.scrape
组件 从 prometheus.exporter.blackbox
收集指标。它向由 grafana
目标发出的指标添加了一个额外标签 env="dev"
。example
目标没有添加任何标签。
config_file
参数定义要使用的 blackbox_exporter
模块。您可以使用 blackbox 示例配置文件。
prometheus.exporter.blackbox "example" {
config_file = "blackbox_modules.yml"
target {
name = "example"
address = "https://example.com"
module = "http_2xx"
}
target {
name = "grafana"
address = "https://grafana.org.cn"
module = "http_2xx"
labels = {
"env" = "dev",
}
}
}
// Configure a prometheus.scrape component to collect blackbox metrics.
prometheus.scrape "demo" {
targets = prometheus.exporter.blackbox.example.targets
forward_to = [prometheus.remote_write.demo.receiver]
}
prometheus.remote_write "demo" {
endpoint {
url = "<PROMETHEUS_REMOTE_WRITE_URL>"
basic_auth {
username = "<USERNAME>"
password = "<PASSWORD>"
}
}
}
替换以下内容
<PROMETHEUS_REMOTE_WRITE_URL>
: 要将指标发送到的 Prometheusremote_write
兼容服务器的 URL。<USERNAME>
: 用于向remote_write
API 进行身份验证的用户名。<PASSWORD>
: 用于向remote_write
API 进行身份验证的密码。
使用嵌入式配置收集指标
此示例使用嵌入式配置
prometheus.exporter.blackbox "example" {
config = "{ modules: { http_2xx: { prober: http, timeout: 5s } } }"
target {
name = "example"
address = "https://example.com"
module = "http_2xx"
}
target {
name = "grafana"
address = "https://grafana.org.cn"
module = "http_2xx"
labels = {
"env" = "dev",
}
}
}
// Configure a prometheus.scrape component to collect blackbox metrics.
prometheus.scrape "demo" {
targets = prometheus.exporter.blackbox.example.targets
forward_to = [prometheus.remote_write.demo.receiver]
}
prometheus.remote_write "demo" {
endpoint {
url = PROMETHEUS_REMOTE_WRITE_URL
basic_auth {
username = USERNAME
password = PASSWORD
}
}
}
从动态目标集合收集指标
此示例与上面相同,但黑盒目标通过 discovery.file
组件发现并发送到 prometheus.exporter.blackbox
discovery.file "example" {
files = ["targets.yml"]
}
prometheus.exporter.blackbox "example" {
config = "{ modules: { http_2xx: { prober: http, timeout: 5s } } }"
targets = discovery.file.example.targets
}
prometheus.scrape "example" {
targets = prometheus.exporter.blackbox.example.targets
forward_to = [prometheus.remote_write.example.receiver]
}
prometheus.remote_write "example" {
endpoint {
url = "<PROMETHEUS_REMOTE_WRITE_URL>"
basic_auth {
username = "<USERNAME>"
password = "<PASSWORD>"
}
}
}
此示例中的 YAML 文件如下所示
- targets:
- localhost:9009
labels:
name: t1
module: http_2xx
other_label: example
- targets:
- localhost:9009
labels:
name: t2
module: http_2xx
替换以下内容
<PROMETHEUS_REMOTE_WRITE_URL>
: 要将指标发送到的 Prometheusremote_write
兼容服务器的 URL。<USERNAME>
: 用于向remote_write
API 进行身份验证的用户名。<PASSWORD>
: 用于向remote_write
API 进行身份验证的密码。
将 instance 标签设置为目标 URL
一些仪表盘可能期望 Blackbox 指标上的 instance
标签包含目标 URL 的值。以下示例演示了如何使用 Prometheus 重打标签来实现这一点。
prometheus.exporter.blackbox "example" {
config = "{ modules: { http_2xx: { prober: http, timeout: 5s } } }"
target {
name = "example"
address = "example.com"
module = "http_2xx"
}
}
discovery.relabel "example" {
targets = prometheus.exporter.blackbox.example.targets
rule {
source_labels = ["__param_target"]
target_label = "instance"
}
}
prometheus.scrape "example" {
targets = discovery.relabel.example.output
forward_to = [prometheus.remote_write.metrics_service.receiver]
}
兼容组件
prometheus.exporter.blackbox
具有可由以下组件使用的导出项
- 消耗 Targets 的组件
注意
连接某些组件可能不合理,或者组件可能需要进一步配置才能使其连接正常工作。有关更多详细信息,请参阅链接文档。