prometheus.receive_http
prometheus.receive_http
监听包含 Prometheus 指标样本的 HTTP 请求,并将它们转发给能够接收指标的其他组件。
公开的 HTTP API 与 Prometheus remote_write
API 兼容。这意味着其他 prometheus.remote_write
组件可以用作客户端,并将请求发送到 prometheus.receive_http
,从而可以将 Alloy 用作 Prometheus 指标的代理。
用法
prometheus.receive_http "<LABEL?" {
http {
listen_address = "<LISTEN_ADDRESS>"
listen_port = <PORT>
}
forward_to = <RECEIVER_LIST>
}
该组件启动一个 HTTP 服务器,支持以下端点:
POST /api/v1/metrics/write
: 将指标发送到该组件,然后该组件会根据forward_to
参数的配置转发给接收器。请求格式必须与 Prometheusremote_write
API 兼容。向该组件发送有效请求的一种方法是使用另一个带有prometheus.remote_write
组件的 Alloy 实例。
参数
您可以将以下参数与 prometheus.receive_http
一起使用:
名称 | 类型 | 描述 | 默认值 | 必需 |
---|---|---|---|---|
forward_to | list(MetricsReceiver) | 要发送指标的接收器列表。 | 是 |
块
您可以将以下块与 prometheus.receive_http
一起使用:
名称 | 描述 | 必需 |
---|---|---|
http | 配置接收请求的 HTTP 服务器。 | 否 |
http
http
块配置 HTTP 服务器。
您可以使用以下参数配置 http
块。任何省略的字段都将采用其默认值。
名称 | 类型 | 描述 | 默认值 | 必需 |
---|---|---|---|---|
conn_limit | int | 同时进行的 HTTP 连接的最大数量。默认为无限制。 | 0 | 否 |
listen_address | string | string | "" | 否 |
服务器监听新连接的网络地址。默认为接受所有传入连接。 | int | listen_port | 8080 | 否 |
int | 服务器监听新连接的端口号。 | server_idle_timeout | duration | 否 |
HTTP 服务器的空闲超时时间。 | 服务器监听新连接的端口号。 | "120s" | server_read_timeout | 否 |
duration | 服务器监听新连接的端口号。 | HTTP 服务器的读取超时时间。 | server_read_timeout | 否 |
"30s"
server_write_timeout
duration
HTTP 服务器的写入超时时间。
"30s"
导出的字段
prometheus.receive_http
不导出任何字段。- 组件健康状况
- 如果
prometheus.receive_http
的配置无效,则其健康状况会报告为不健康。 - 调试指标
- 以下是使用此组件时公开的一些指标。相关指标包括诸如
status_code
等标签,可用于衡量请求成功率。 prometheus_fanout_latency
(histogram):将指标发送到其他组件的写入延迟。
prometheus_forwarded_samples_total
(counter):发送到下游组件的样本总数。
prometheus_receive_http_request_duration_seconds
(histogram):处理 HTTP 请求所花费的时间(秒)。
prometheus_receive_http_request_message_bytes
(histogram):请求中接收到的消息大小(字节)。
// Receives metrics over HTTP
prometheus.receive_http "api" {
http {
listen_address = "0.0.0.0"
listen_port = 9999
}
forward_to = [prometheus.remote_write.local.receiver]
}
// Send metrics to a locally running Mimir.
prometheus.remote_write "local" {
endpoint {
url = "http://mimir:9009/api/v1/push"
basic_auth {
username = "example-user"
password = "example-password"
}
}
}
prometheus_receive_http_response_message_bytes
(histogram):响应中发送的消息大小(字节)。
prometheus_receive_http_tcp_connections
(gauge):当前接受的 TCP 连接数。
// Collects metrics of localhost:12345
prometheus.scrape "self" {
targets = [
{"__address__" = "localhost:12345", "job" = "alloy"},
]
forward_to = [prometheus.remote_write.local.receiver]
}
// Writes metrics to localhost:9999/api/v1/metrics/write - e.g. served by
// the prometheus.receive_http component from the example above.
prometheus.remote_write "local" {
endpoint {
url = "https://:9999/api/v1/metrics/write"
}
}
示例
通过 HTTP 接收指标
兼容的组件
以下示例创建了一个 prometheus.receive_http
组件,该组件启动一个 HTTP 服务器,在所有网络接口的端口 9999
上监听。该服务器接收指标,并将它们转发到 prometheus.remote_write
组件,该组件将这些指标写入指定的 HTTP 端点。
- 代理指标
要将指标发送到前面示例中定义的
prometheus.receive_http
组件,另一个 Alloy 实例可以运行以下配置:技术详情