菜单
文档breadcrumb arrow Grafana Alloybreadcrumb arrow 参考breadcrumb arrow 组件breadcrumb arrow lokibreadcrumb arrow loki.source.cloudflare
公开发布 (GA)

loki.source.cloudflare

loki.source.cloudflare 组件从 Cloudflare Logpull API 拉取日志,并将它们转发到其他 loki.* 组件。

这些日志包含与连接客户端、通过 Cloudflare 网络的请求路径以及来自源 Web 服务器的响应相关的数据,可用于丰富源服务器上的现有日志。

您可以通过为多个 loki.source.cloudflare 组件指定不同的标签。

用法

alloy
loki.source.cloudflare "<LABEL>" {
  zone_id   = "<ZONE_ID>"
  api_token = "<API_TOKEN>"

  forward_to = <RECEIVER_LIST>
}

参数

您可以将以下参数与 loki.source.cloudflare 一起使用

名称类型描述默认值必需
api_tokenstring用于身份验证的 API 令牌。
forward_tolist(LogsReceiver)要将日志条目发送到的接收器列表。
zone_idstring要使用的 Cloudflare 区域 ID。
additional_fieldslist(string)用于补充通过 fields_type 提供的字段的附加字段列表。
fields_typestring要为日志条目获取的字段集。"default"
labelsmap(string)要与传入日志条目关联的标签。{}
pull_rangeduration每次拉取请求要获取的时间范围。"1m"
workersint用于解析日志的工作程序数量。3

默认情况下,loki.source.cloudflare 使用 default 字段集获取日志。以下列表显示了可供选择的不同 fields_type 集,以及它们包含的字段

  • default 包括

    • "ClientIP"
    • "ClientRequestHost"
    • "ClientRequestMethod"
    • "ClientRequestURI"
    • "EdgeEndTimestamp"
    • "EdgeResponseBytes"
    • "EdgeRequestHost"
    • "EdgeResponseStatus"
    • "EdgeStartTimestamp"
    • "RayID"

    以及通过 additional_fields 参数提供的任何额外字段。

  • minimal 包括所有 default 字段并添加

    • "ZoneID"
    • "ClientSSLProtocol"
    • "ClientRequestProtocol"
    • "ClientRequestPath"
    • "ClientRequestUserAgent"
    • "ClientRequestReferer"
    • "EdgeColoCode"
    • "ClientCountry"
    • "CacheCacheStatus"
    • "CacheResponseStatus"
    • "EdgeResponseContentType"
    以及通过 additional_fields 参数提供的任何额外字段。

  • extended 包括所有 minimal 字段并添加

    • "ClientSSLCipher"
    • "ClientASN"
    • "ClientIPClass"
    • "CacheResponseBytes"
    • "EdgePathingOp"
    • "EdgePathingSrc"
    • "EdgePathingStatus"
    • "ParentRayID"
    • "WorkerCPUTime"
    • "WorkerStatus"
    • "WorkerSubrequest"
    • "WorkerSubrequestCount"
    • "OriginIP"
    • "OriginResponseStatus"
    • "OriginSSLProtocol"
    • "OriginResponseHTTPExpires"
    • "OriginResponseHTTPLastModified"
    以及通过 additional_fields 参数提供的任何额外字段。

  • all 包括所有 extended 字段并添加

    • "BotScore"
    • "BotScoreSrc"
    • "BotTags"
    • "ClientRequestBytes"
    • "ClientSrcPort"
    • "ClientXRequestedWith"
    • "CacheTieredFill"
    • "EdgeResponseCompressionRatio"
    • "EdgeServerIP"
    • "FirewallMatchesSources"
    • "FirewallMatchesActions"
    • "FirewallMatchesRuleIDs"
    • "OriginResponseBytes"
    • "OriginResponseTime"
    • "ClientDeviceType"
    • "WAFFlags"
    • "WAFMatchedVar"
    • "EdgeColoID"
    • "RequestHeaders"
    • "ResponseHeaders"
    • "ClientRequestSource"
    以及通过 additional_fields 参数提供的任何额外字段。如果通过 Cloudflare API 提供了新字段,但尚未包含在 all 中,则这种情况仍然相关。

  • custom 仅包括在 additional_fields 中定义的字段。

该组件将其位置文件中最后成功获取的时间戳保存下来。如果在文件中找到给定区域 ID 的位置,则该组件会从该时间戳重新开始拉取日志。如果未找到位置,则该组件会从当前时间开始拉取日志。

日志是使用多个 workers 获取的,这些工作程序会重复请求上次可用的 pull_range。由于每次拉取需要处理的日志行过多,因此可能会落后。添加更多工作程序、缩短拉取范围或减少获取的字段数量可以缓解此性能问题。

组件获取的最后一个时间戳记录在 loki_source_cloudflare_target_last_requested_end_timestamp 调试指标中。

所有传入的 Cloudflare 日志条目均为 JSON 格式。您可以使用 loki.process 组件和 JSON 处理阶段来提取更多标签或更改日志行格式。日志示例如下

json
{
    "CacheCacheStatus": "miss",
    "CacheResponseBytes": 8377,
    "CacheResponseStatus": 200,
    "CacheTieredFill": false,
    "ClientASN": 786,
    "ClientCountry": "gb",
    "ClientDeviceType": "desktop",
    "ClientIP": "100.100.5.5",
    "ClientIPClass": "noRecord",
    "ClientRequestBytes": 2691,
    "ClientRequestHost": "www.foo.com",
    "ClientRequestMethod": "GET",
    "ClientRequestPath": "/comments/foo/",
    "ClientRequestProtocol": "HTTP/1.0",
    "ClientRequestReferer": "https://www.foo.com/foo/168855/?offset=8625",
    "ClientRequestURI": "/foo/15248108/",
    "ClientRequestUserAgent": "some bot",
    "ClientRequestSource": "1"
    "ClientSSLCipher": "ECDHE-ECDSA-AES128-GCM-SHA256",
    "ClientSSLProtocol": "TLSv1.2",
    "ClientSrcPort": 39816,
    "ClientXRequestedWith": "",
    "EdgeColoCode": "MAN",
    "EdgeColoID": 341,
    "EdgeEndTimestamp": 1637336610671000000,
    "EdgePathingOp": "wl",
    "EdgePathingSrc": "macro",
    "EdgePathingStatus": "nr",
    "EdgeRateLimitAction": "",
    "EdgeRateLimitID": 0,
    "EdgeRequestHost": "www.foo.com",
    "EdgeResponseBytes": 14878,
    "EdgeResponseCompressionRatio": 1,
    "EdgeResponseContentType": "text/html",
    "EdgeResponseStatus": 200,
    "EdgeServerIP": "8.8.8.8",
    "EdgeStartTimestamp": 1637336610517000000,
    "FirewallMatchesActions": [],
    "FirewallMatchesRuleIDs": [],
    "FirewallMatchesSources": [],
    "OriginIP": "8.8.8.8",
    "OriginResponseBytes": 0,
    "OriginResponseHTTPExpires": "",
    "OriginResponseHTTPLastModified": "",
    "OriginResponseStatus": 200,
    "OriginResponseTime": 123000000,
    "OriginSSLProtocol": "TLSv1.2",
    "ParentRayID": "00",
    "RayID": "6b0a...",
    "RequestHeaders": [],
    "ResponseHeaders": [
      "x-foo": "bar"
    ],
    "SecurityLevel": "med",
    "WAFAction": "unknown",
    "WAFFlags": "0",
    "WAFMatchedVar": "",
    "WAFProfile": "unknown",
    "WAFRuleID": "",
    "WAFRuleMessage": "",
    "WorkerCPUTime": 0,
    "WorkerStatus": "unknown",
    "WorkerSubrequest": false,
    "WorkerSubrequestCount": 0,
    "ZoneID": 1234
}

loki.source.cloudflare 组件不支持任何块。您可以使用参数配置此组件。

导出的字段

loki.source.cloudflare 不导出任何字段。

组件健康状况

仅当 loki.source.cloudflare 配置无效时,才会被报告为不健康。

调试信息

loki.source.cloudflare 公开以下调试信息

  • 目标是否已准备就绪并正在从 API 读取日志。
  • Cloudflare 区域 ID。
  • 最后报告的错误(如果有)。
  • 存储的位置文件条目,作为 zone_id、标签和上次获取的时间戳的组合。
  • 上次获取的时间戳。
  • 正在获取的字段集。

调试指标

  • loki_source_cloudflare_target_entries_total (计数器):通过 cloudflare 目标发送的成功条目总数。
  • loki_source_cloudflare_target_last_requested_end_timestamp (仪表):上次获取的 cloudflare 请求结束时间戳,用于计算目标落后多少。

示例

此示例从 Cloudflare 的 API 拉取日志,并将它们转发到 loki.write 组件。

alloy
loki.source.cloudflare "dev" {
  zone_id   = sys.env("CF_ZONE_ID")
  api_token = local.file.api.content

  forward_to = [loki.write.local.receiver]
}

loki.write "local" {
  endpoint {
    url = "loki:3100/api/v1/push"
  }
}

兼容组件

loki.source.cloudflare 可以接受来自以下组件的参数

  • 导出 Loki LogsReceiver 导出器的组件

注意

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