APIG接入
云日志服务支持API网关(API Gateway)日志接入。
前提条件
创建并使用华为云APIG实例。
操作步骤
云日志服务接入方式为API网关 APIG时,按照如下操作完成接入配置。
- 登录云日志服务控制台。
- 在左侧导航栏中,选择“日志接入”,单击“API网关 APIG”进行APIG接入配置。
- 选择日志流。
- 单击“所属日志组”后的目标框,在下拉列表中选择具体的日志组,若没有所需的日志组,单击“所属日志组”目标框后的“新建”,在弹出的创建日志组页面创建新的日志组。
- 单击“所属日志流”后的目标框,在下拉列表中选择具体的日志流,若没有所需的日志流,单击“所属日志流”目标框后的“新建”,在弹出的创建日志流页面创建新的日志流。
- 单击“下一步”:APIG配置。
- APIG配置。
单击“前往APIG配置”。
- 在APIG控制台,选择API监控分析下的“日志分析”。
- 单击“配置访问日志”链接。
- 在弹出的配置访问日志页面中,选择对应的日志组和日志流。
APIG里具体的操作请参见日志分析。
- 单击下一步:日志流配置。
表1 日志流配置参数表 参数
说明
自动对日志流进行结构化配置和索引配置
开启该按钮,自动对日志流进行结构化配置和索引配置。日志流结构化配置为APIG系统模板;索引配置为所有APIG解析出来的字段打开快速分析按钮。配置结构化和索引后,才能对APIG日志进行SQL分析,并提供可视化图表。
自动为日志流添加标签:log_type=apig_layer_access
开启该按钮,自动为日志流添加标签(log_type=apig_layer_access)后,APIG仪表盘模板才能匹配该日志流。
自动为日志流创建仪表盘
开启该按钮,自动为日志流创建APIG仪表盘。
- 完成。
结构化模板日志详情
- 结构化模板示例
表2 结构化模板示例 模板名称
示例日志
APIG
100.125.7.59 f57f6523b675504a23887d0f5c1c8ef3 f5ea2360a2fa443cac236b76f4052ad6 - - [27/Jan/2022:15:56:44 +0800] 0.113 GET http://c965898968af48248ec7fac4ec0666f4.apic.cn-north-4.huaweicloudapis.com /api/echo HTTP/1.1 200 1443 408 "APIGatewayDebugClient/1.0" "-" "100.125.2.39:443" /v2/x/fgs/functions/urn:fss:cn-north-4:106506b9a92342df9a5025fc12351cfc:function:default:apigDemo_1640743997661:latest/invocations "200" "0.010" "0.083" "0.083" cn-north-4 0.083 0 - - - 0.03000020980835 - - "-" 486 HttpEchoDemo - - - "-" "-" "-" "-" "-" "-" "-" "-" "-" "-" remote [26/Dec/2022:12:21:40.000 +0000] [0.52]
- 结构化字段详情
表3 结构化字段 字段
示例
描述
类型
access_model1
-
认证模式1
string
access_model2
-
认证模式2,开启双重认证时,为自定义认证编号
string
all_upstream_response_time
0.083
从开始与后端建立连接到从后端获取到最后一个字节所用时间,单位秒。发生重试时,为所用时间总和
float
api_id
f5ea2360a2fa443cac236b76f4052ad6
API ID
string
api_name
HttpEchoDemo
API名称
string
app_id
-
当使用APP认证访问时,请求方提供的APP ID
string
app_name
-
当使用APP认证访问时,请求方使用的APP名称
string
auth_type
-
API认证类型
string
body_bytes_sent
486
API请求的Body体大小,单位字节
long
bytes_sent
1443
响应大小(单位:字节,包含状态行、响应头、响应体)
long
custom_data_log1
-
用户自定义日志字段值1
string
custom_data_log10
-
用户自定义日志字段值10
string
custom_data_log2
-
用户自定义日志字段值2
string
custom_data_log3
-
用户自定义日志字段值3
string
custom_data_log4
-
用户自定义日志字段值4
string
custom_data_log5
-
用户自定义日志字段值5
string
custom_data_log6
-
用户自定义日志字段值6
string
custom_data_log7
-
用户自定义日志字段值7
string
custom_data_log8
-
用户自定义日志字段值8
string
custom_data_log9
-
用户自定义日志字段值9
string
errorType
0
API请求的错误类型
- 0:非流控错误
- 1:流控错误
long
host
c965898968af48248ec7fac4ec0666f4.apic.cn-north-4.huaweicloudapis.com
请求域名
string
http_user_agent
APIGatewayDebugClient/1.0
用户代理标识
string
http_x_forwarded_for
-
X-Forwarded-For头
string
inner_time
0.03000020980835
apig的内部处理时长,单位秒
float
my_remote_addr
100.125.7.59
用户的客户端IP地址
string
provider_app_id
-
API所属的APP ID
string
provider_app_name
-
API所属的APP名称
string
proxy_protocol_addr
-
客户端源IP地址
string
proxy_protocol_vni
-
VPC终端节点的虚拟网络标识
string
proxy_protocol_vpce_id
-
VPC终端节点的ID
string
region_id
cn-north-4
云服务区ID
string
request_id
f57f6523b675504a23887d0f5c1c8ef3
请求ID
string
request_length
408
请求长度(单位:字节,包含起始行、请求头、请求体)
long
request_method
GET
HTTP请求方法
string
request_time
0.113
请求延迟
float
response_source
remote
请求响应来源
- local:APIG
- remote:后端服务
string
router_uri
/api/echo
请求URI
string
scheme
http
请求方式
string
server_protocol
HTTP/1.1
请求协议
string
start_time
26/Dec/2022:12:21:40
请求的开始时间
string
status
200
响应状态码
long
time_local
27/Jan/2022:15:56:44
请求时间
string
upstream_addr
100.125.2.39:443
请求的后端地址
string
upstream_connect_time
0.01
与后端建立连接所用时间
float
upstream_header_time
0.083
从开始与后端建立连接到从后端获取到首字节所用时间
float
upstream_response_time
0.083
从开始与后端建立连接到从后端获取到最后一个字节所用时间
float
upstream_status
200
后端响应状态码
long
upstream_uri
/v2/x/fgs/functions/urn:fss:cn-north-4:106506b9a92342df9a5025fc12351cfc:function:default:apigDemo_1640743997661:latest/invocations
请求后端的URI
string
user_name
-
用户名称
string