Cloudflare Logpush 支持通过 Cloudflare 仪表板或 API 将日志直接推送到 New Relic。
-
在 Cloudflare 仪表板中,前往账户或域名(也称为 zone)级别的 Logpush(日志推送) 页面。
账户级别:Go to Logpush ↗
域名(也称为 zone)级别:Go to Logpush ↗
-
根据你的选择,可分别访问账户范围数据集与 zone 范围数据集。
-
选择 Create a Logpush job(创建 Logpush 作业)。
-
在 Select a destination(选择目标) 中,选择 New Relic。
-
输入 New Relic Logs Endpoint(New Relic 日志端点):
"https://log-api.newrelic.com/log/v1?Api-Key=<NR_LICENSE_KEY>&format=cloudflare"
"https://log-api.eu.newrelic.com/log/v1?Api-Key=<NR_LICENSE_KEY>&format=cloudflare"
请使用与你 New Relic 账户所设区域相匹配的区域。License key(许可证密钥) 字段可在 New Relic 仪表板中找到,并可通过这些步骤 ↗获取。
输入完目标详细信息后,选择 Continue(继续)。
-
选择要推送到存储服务的数据集。
-
在下一步中,需要配置你的 Logpush 任务:
- 输入 Job name(作业名称)。
- 在 If logs match(如果日志匹配) 下,可以选择要包含和/或从日志中排除的事件。更多信息请参阅 Filters。并非所有数据集都提供此选项。
- 在 Send the following fields(发送以下字段) 中,可以选择将所有日志推送到存储目标,或有选择地指定要推送的日志。
-
在 Advanced Options(高级选项) 中,你可以:
- 选择日志中时间戳字段的格式(
RFC3339(默认)、Unix或UnixNano)。 - 为日志选择采样率,或推送随机采样的一定百分比日志。
- 启用针对
CVE-2021-44228的脱敏。该选项会将每一次出现的${替换为x{。
- 选择日志中时间戳字段的格式(
-
配置完 Logpush 任务后,选择 Submit(提交)。
在尝试读取或配置 Logpush 任务之前,请确保已启用 Log Share 权限。更多信息请参阅角色部分。
要创建任务,请向 Logpush jobs 端点发送 POST 请求,并包含以下字段:
-
name(可选)- 使用你的域名作为任务名称。
-
output_options(可选)- 要配置字段、采样率和时间戳格式,请参阅 Log Output Options。
-
destination_conf - 由端点 URL、license key 和 format 组成的日志目标,格式如下所示的字符串。
-
<NR_ENDPOINT_URL>:New Relic HTTP logs 接收端点,US 为
https://log-api.newrelic.com/log/v1,EU 为https://log-api.eu.newrelic.com/log/v1,取决于你 New Relic 账户所设区域。 -
<NR_LICENSE_KEY>:此密钥可在 New Relic 仪表板中找到,并可通过这些步骤 ↗获取。
-
format:格式为
cloudflare。US:
"https://log-api.newrelic.com/log/v1?Api-Key=<NR_LICENSE_KEY>&format=cloudflare"EU:
"https://log-api.eu.newrelic.com/log/v1?Api-Key=<NR_LICENSE_KEY>&format=cloudflare"
-
-
max_upload_records(可选)- 每批日志的最大行数。必须至少为 1,000 行或更多。请注意,无法指定每批日志的最小行数。这意味着日志文件可能包含远少于指定数量的行。
-
max_upload_bytes(可选)- 一批日志的最大未压缩文件大小。必须至少为 5 MB。请注意,无法设置最小文件大小。这意味着日志文件可能远小于此批大小。尽管如此,建议将此参数设为 5,000,000。
-
dataset - 你希望接收的日志类别。完整的受支持数据集列表请参阅 Datasets。
使用 cURL 的示例请求:
Required API token permissions
At least one of the following token permissions is required:Logs Write
curl "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/logpush/jobs" \
--request POST \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--json '{
"name": "<DOMAIN_NAME>",
"output_options": {
"field_names": [
"ClientIP",
"ClientRequestHost",
"ClientRequestMethod",
"ClientRequestURI",
"EdgeEndTimestamp",
"EdgeResponseBytes",
"EdgeResponseStatus",
"EdgeStartTimestamp",
"RayID"
],
"timestamp_format": "unix"
},
"destination_conf": "https://log-api.newrelic.com/log/v1?Api-Key=<NR_LICENSE_KEY>&format=cloudflare",
"max_upload_bytes": 5000000,
"dataset": "http_requests",
"enabled": true
}'响应:
{
"errors": [],
"messages": [],
"result": {
"id": <JOB_ID>,
"dataset": "http_requests",
"kind": "",
"max_upload_bytes": 5000000,
"enabled": true,
"name": "<DOMAIN_NAME>",
"output_options": {
"field_names": ["ClientIP", "ClientRequestHost", "ClientRequestMethod", "ClientRequestURI", "EdgeEndTimestamp","EdgeResponseBytes", "EdgeResponseStatus", "EdgeStartTimestamp", "RayID"],
"timestamp_format": "unix"
},
"destination_conf": "https://log-api.newrelic.com/log/v1?Api-Key=<NR_LICENSE_KEY>&format=cloudflare",
"last_complete": null,
"last_error": null,
"error_message": null
},
"success": true
}请参阅 使用 cURL 管理 Logpush,了解如何更新任务(包括启用和禁用)。