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 的格式匹配。向此组件发送有效请求的一种方法是使用另一个 Alloy 和一个prometheus.remote_write
组件。
参数
prometheus.receive_http
支持以下参数
名称 | 类型 | 描述 | 默认值 | 必需 |
---|---|---|---|---|
forward_to | list(MetricsReceiver) | 要将指标发送到的接收器列表。 | 是 |
块
prometheus.receive_http
的定义内部支持以下块
http | 名称 | 描述 | 必需 |
---|---|---|---|
http | http | 配置接收请求的 HTTP 服务器。 | 否 |
http
http
块配置 HTTP 服务器。
您可以使用以下参数来配置 http
块。任何省略的字段都将采用其默认值。
名称 | 类型 | 描述 | 默认值 | 必需 |
---|---|---|---|---|
conn_limit | int | 最大并发 HTTP 连接数。默认为无限制。 | 0 | 否 |
listen_address | 字符串 | 服务器监听新连接的网络地址。默认为接受所有传入连接。 | "" | 否 |
listen_port | int | 服务器监听新连接的端口号。 | 8080 | 否 |
server_idle_timeout | duration | HTTP 服务器的空闲超时。 | "120 秒" | 否 |
server_read_timeout | duration | HTTP 服务器的读取超时。 | "30 秒" | 否 |
server_write_timeout | duration | HTTP 服务器的写入超时。 | "30 秒" | 否 |
导出的字段
prometheus.receive_http
不导出任何字段。
组件健康状况
如果 prometheus.receive_http
被赋予无效配置,则报告为不健康。
调试指标
以下是使用此组件时公开的一些指标。请注意,这些指标包括诸如 status_code
等标签(如果相关),可用于衡量请求成功率。
prometheus_receive_http_request_duration_seconds
(直方图): 服务 HTTP 请求所花费的时间(以秒为单位)。prometheus_receive_http_request_message_bytes
(直方图): 请求中接收的消息大小(以字节为单位)。prometheus_receive_http_response_message_bytes
(直方图): 响应中发送的消息大小(以字节为单位)。prometheus_receive_http_tcp_connections
(仪表): 当前接受的 TCP 连接数。prometheus_fanout_latency
(直方图): 将指标发送到其他组件的写入延迟。prometheus_forwarded_samples_total
(计数器): 发送到下游组件的样本总数。
示例
通过 HTTP 接收指标
此示例创建一个 prometheus.receive_http
组件,该组件启动一个 HTTP 服务器,监听 0.0.0.0
和端口 9999
。服务器接收指标并将它们转发到 prometheus.remote_write
组件,该组件将这些指标写入指定的 HTTP 端点。
// 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
组件,另一个 Alloy 可以使用以下配置运行
// 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://127.0.0.1:9999/api/v1/metrics/write"
}
}
技术细节
prometheus.receive_http
使用 snappy 进行压缩。
兼容组件
prometheus.receive_http
可以接受来自以下组件的参数
- 导出 Prometheus
MetricsReceiver
的组件
注意
连接某些组件可能不合理,或者组件可能需要进一步配置才能使连接正常工作。有关更多详细信息,请参阅链接的文档。