14
构造请求日志分析系统
source link: https://studygolang.com/articles/31493
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
请求日志记录哪些数据
time_local remote_addr request_method request_schema request_host request_path request_query request_size referer user_agent status request_time bytes_sent
很多时候我们会使用负载网关去代理转发请求给实际的后端服务,这时候请求日志还会包括以下数据:
upstream_host upstream_addr upstream_url upstream_status proxy_time
数据衍生
客户端 IP 地址可以衍生出以下数据:
-
asn 相关信息:
asn_asn as_org
-
geo 地址位置信息:
geo_location geo_country geo_country_code geo_region geo_city
user_agent
可以解析出以下信息:
ua_device ua_os ua_name
数据分析
-
PV
/QPS
: 页面浏览次数 / 每秒请求数 -
UV
: 访问的用户人数,很多网站用户无序登录也能访问,这时可以根据 IP + user_agent 的唯一性确定用户 -
IP
数 : 访问来源有多少个 IP 地址
<br/>
- 网络流量 : 根据
request_size
请求的大小计数网络流入流量,bytes_sent
响应大小计算网络流出流量
<br/>
-
referer
来源分析
<br/>
- 客户请求的地理位置分析:根据 IP 地址衍生的
geo
数据
<br/>
- 客户设备分析:根据
user_agent
提取数据
<br/>
-
请求耗时统计:根据
request_time
数据- p99、p95、p90 延迟(前多少百分比请求的耗时,比如 p99 就是前 99% 请求的耗时)
- 长耗时异常监控
<br/>
-
响应状态监控:根据
status
数据- 各个状态码的响应占比
- 5xx 服务端异常数量
<br/>
-
结合业务分析:请求的
request_path
地址和request_query
参数一定是对应具体业务的,例如- 请求某个相册的地址是 /album/:id ,那么日志中的
request_path
对应的就是对相册进行了一次访问 - 进行站内搜索的地址是
/search?q=<关键词>
,那么统计request_path
是/search
的日志条数就可以知道进行了多少次搜索,统计request_query
中q
的参数就可以知道搜索关键词的情况
- 请求某个相册的地址是 /album/:id ,那么日志中的
通用架构
日志系统使用 ELK + kafka 构建是业界比较主流的方案,beats、 logstash 进行日志采集搬运,kafka 存储日志等待消费,elasticsearch 进行数据的聚合分析,grafana 和 kibana 进行图形化展示。
有疑问加站长微信联系(非本文作者)
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK