# 访问数据采集
# 概述
用户访问网站的数据采集和分析,用于分析访问的基本信息,包括时间,地理位置等
# http 网站采集
主要用于基础环境场景
# 采集字段说明
| 序号 | nginx 标识 | 字段名称 | 备注 |
|---|---|---|---|
| 1 | $remote_addr | 客户端 IP | |
| 1 | $time_local | 通用日志格式下的本地时间 | |
| 1 | $status | 状态码 | |
| 1 | $body_bytes_sent | 发送给客户端的字节数,不包括响应头的大小 | |
| 1 | $http_user_agent | 客户端浏览器信息 | |
| 1 | $http_referer | 请求的 referer 地址。 | |
| 1 | $request | 完整的原始请求 | |
| 1 | $request_method | HTTP 请求方法,通常为"GET"或"POST" | |
| 1 | $request_time | 请求处理时长 | |
| 1 | $request_uri | 完整的请求地址 | |
| 1 | $server_protocol | 服务器的 HTTP 版本,通常为 "HTTP/1.0" 或 "HTTP/1.1" | |
| 1 | $request_body | POST 请求参数,参数需放 form 中 | |
| 1 | token $http_token | (自定义 header 字段前加 http_,即可将指定的自定义 header 字段打印到 log 中) |
# 采集格式
log_format user_log_format "$remote_addr,
$time_local,
$status,
$body_bytes_sent,
$http_user_agent,
$http_referer,
$request_method,
$request_time,
$request_uri,
$server_protocol,
$request_body,$http_token";
# 对应的 hive 数据表结构
CREATE TABLE ods_nginx_access_log(
remote_addr string,
time_local string,
status string,
body_bytes_sent string,
http_user_agent string,
http_referer string,
request_method string,
request_time string,
request_uri string,
server_protocol string,
request_body string,
http_token string,
id string,
appkey string,
sing string,
VERSION string) clustered BY (id) INTO 5 buckets stored AS orc TBLPROPERTIES ('transactional'='true');
# proxy 代理数据采集
主要用于 k8s 访问日志场景,代理 ingress 数据访问
# 采集字段说明
| 序号 | nginx 标识 | 字段名称 | 备注 |
|---|---|---|---|
| 1 | $remote_addr | 客户端 IP | |
| 1 | $time_local | 通用日志格式下的本地时间 | |
| 1 | $status | 状态码 | |
| 1 | $binary_remote_addr | 二进制格式的客户端地址 | |
| 1 | $bytes_received | 从客户端接收的字节数(1.11.4) | |
| 1 | $bytes_sent | 发送到客户端的字节数 | |
| 1 | $connection | 连接序列号 | |
| 1 | $hostname | 主机名 | |
| 1 | $msec | 当前时间在秒和毫秒分辨率 | |
| 1 | $nginx_version | nginx 版本 | |
| 1 | $pid | 工作进程的 PID | |
| 1 | $protocol | 协议用于与客户沟通: TCP 或 UDP(1.11.4) | |
| 1 | $proxy_protocol_addr | 客户端地址从代理协议头,否则或空字符串(1.11.4) | |
| 1 | $proxy_protocol_port | 代理协议之前必须通过设置启用 proxy_protocol 参数听指令 | |
| 1 | $remote_addr | 客户端地址 | |
| 1 | $remote_port | 客户端端口 | |
| 1 | $server_addr | 接受连接过来的服务器的地址 | |
| 1 | $server_port | 接受了一个连接端口的服务器 | |
| 1 | $session_time | 会话持续时间在秒和毫秒分辨率(1.11.4); | |
| 1 | $status | 会话状态 | |
| 1 | $time_iso8601 | 当地时间的 ISO 8601 标准格式 |
# 采集格式
log_format proxy_format "$remote_addr,
$time_local,
$status,
$upstream_bytes_sent,
$protocol,
$upstream_addr,
$bytes_sent,
$bytes_received,
$session_time,
$upstream_bytes_received,
$upstream_connect_time";
# 对应的 hive 数据表结构
CREATE TABLE ods_nginx_proxy_log(
remote_addr string,
time_local string,
status string,
upstream_bytes_sent string,
protocol string ,
upstream_addr string ,
bytes_sent string ,
bytes_received string ,
session_time string ,
upstream_bytes_received string ,
upstream_connect_time string ,
id string,
appkey string,
sing string,
VERSION string) clustered BY (id) INTO 5 buckets stored AS orc TBLPROPERTIES ('transactional'='true');
# 其它
- 略