菜单
文档breadcrumb arrow Grafana Alloybreadcrumb arrow 参考breadcrumb arrow 组件breadcrumb arrow prometheusbreadcrumb arrow prometheus.receive_http
开源

prometheus.receive_http

prometheus.receive_http 监听包含 Prometheus 指标样本的 HTTP 请求,并将它们转发到能够接收指标的其他组件。

公开的 HTTP API 与 Prometheus remote_write API 兼容。这意味着其他 prometheus.remote_write 组件可以用作客户端,并将请求发送到 prometheus.receive_http,从而使 Alloy 能够用作 Prometheus 指标的代理。

用法

alloy
prometheus.receive_http "LABEL" {
  http {
    listen_address = "LISTEN_ADDRESS"
    listen_port = PORT
  }
  forward_to = RECEIVER_LIST
}

该组件将启动一个 HTTP 服务器,支持以下端点

  • POST /api/v1/metrics/write - 将指标发送到组件,组件反过来会将指标转发到 forward_to 参数中配置的接收器。请求格式必须与 Prometheus remote_write API 的格式匹配。向此组件发送有效请求的一种方法是使用另一个 Alloy 和一个 prometheus.remote_write 组件。

参数

prometheus.receive_http 支持以下参数

名称类型描述默认值必需
forward_tolist(MetricsReceiver)要将指标发送到的接收器列表。

prometheus.receive_http 的定义内部支持以下块

http名称描述必需
httphttp配置接收请求的 HTTP 服务器。

http

http 块配置 HTTP 服务器。

您可以使用以下参数来配置 http 块。任何省略的字段都将采用其默认值。

名称类型描述默认值必需
conn_limitint最大并发 HTTP 连接数。默认为无限制。0
listen_address字符串服务器监听新连接的网络地址。默认为接受所有传入连接。""
listen_portint服务器监听新连接的端口号。8080
server_idle_timeoutdurationHTTP 服务器的空闲超时。"120 秒"
server_read_timeoutdurationHTTP 服务器的读取超时。"30 秒"
server_write_timeoutdurationHTTP 服务器的写入超时。"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 端点。

alloy
// 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 可以使用以下配置运行

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 可以接受来自以下组件的参数

注意

连接某些组件可能不合理,或者组件可能需要进一步配置才能使连接正常工作。有关更多详细信息,请参阅链接的文档。