当前位置: 首页 > 科技观察

日志服务-Nginx访问日志15分钟分析

时间:2023-03-16 21:34:55 科技观察

15分钟你能做什么?也许你只能读一本书的一章,慢慢地喝半杯咖啡,或者玩一局炉石。日志服务于11月发布了数据访问向导功能。如果一首歌曲的平均时长按3分钟计算,那么给我们5首歌曲,让我们使用日志服务的数据访问向导快速分析NGINX访问日志。~数据存取精灵(Wizard)1.概述日志服务于12月推出数据存取精灵(Wizard)功能,快速完成数据采集、存储、分析、离线传递,降低用户使用日志服务的门槛。目前支持的数据源和支持配置如下:2.使用指南如果您没有使用过阿里云日志服务功能,可以参考五分钟快速入门。下面我们从最常见的NGINX访问日志分析开始,尝试一下如何快速访问这类数据源。首先,您可以使用以下两种方法进入数据访问向导。要创建新项目,请在创建项目和日志存储库后单击数据访问向导。对于已有的Logstore,点击列表中的数据访问向导图标进入。1、选择数据类型,选择自建软件>NGINX。2.数据源设置根据实际情况填写配置名称和日志路径,将实际的log_format信息填写成NGINX日志格式。日志服务会自动提取对应的键名。注意:$request将被提取为两个键,request_method和request_uri。b.申请机器组如果您之前没有创建过机器组,请根据页面提示创建机器组。Note:Ittakesupto3minutesfortheLogtailconfigurationpushtotakeeffect,pleasewaitpatiently3.QueryAnalysis&VisualizationToensurethattheheartbeatofthelogmachinegroupisnormal,youcanclickthepreviewbuttonontherighttoobtainthecollecteddataLogserviceprovidespresets的数据键名称以便分析使用,可以选择实际数据键名称(根据预览数据生成)和默认数据键名称形成映射关系,nginx访问日志提供的预设数据键如下:body_bytes_sentbytes_sentconnectionconnection_requestsmsecstatustime_iso8601time_localcontent_lengthcontent_typehosthostnameremote_addrremote_portremote_userrequest_lengthrequest_methodrequest_timeupstream_response_timerequest_urischemeserver_addrserver_nameserver_portserver_protocolhttp_user_agenthttp_referer各数据键释义可参考NGINX相关文档ClickNext,andLogServicewillsettheindexpropertiesforyouandcreateannginx-dashboarddashboardforanalysis.3.1AnalyzingtheaccesslogAfterthedashboardisestablished,wecanquicklyanalyzetheaccesslog.Youcanentertheanalysispagethroughtheleftnavigationdashboard.PV/UVstatistics(pv_uv)countsthenumberofPVsandUVsinthelastday.Statisticalstatement:*|selectapprox_distinct(remote_addr)asuv,count(1)aspv,date_format(date_trunc('hour',__time__),'%m-%d%H:%i')astimegroupbydate_format(date_trunc('hour',__time__),'%m-%d%H:%i')orderbytimelimit1000Statisticsofpopularvisitedpages(top_page)Statisticsofthe20mostvisitedpagesinthelastday.统计语句:*|selectcount(1)aspv,split_part(request_uri,'?',1)aspathgroupbysplit_part(request_uri,'?',1)orderbypvdesclimit20请求方式统计(http_method_percentage)统计最近一天各种请求方式的占比。统计语句:*|selectcount(1)aspv,request_methodgroupbyrequest_methodhttp状态码统计(http_status_percentage)统计最近一天各种http状态码的占比。统计语句:*|selectcount(1)aspv,statusgroupbystatus客户端类型统计(user_agent)统计最近一天各种浏览器的占比。统计语句:*|selectcount(1)aspv,casewhenhttp_user_agentlike'%Android%'then'Android'whenhttp_user_agentlike'%iPhone%'then'iOS'else'unKnown'endashttp_user_agentgroupbycasewhenhttp_user_agentlike'%Android%'then'Android'whenhttp_user_agentlike'%iPhone%'then'iOS'else'unKnown'endorderbypvdesclimit10源页面统计(top_10_referer)统计最近一天来自不同域名的前十名referer的比例。统计语句:*|selectcount(1)aspv,http_referergroupbyhttp_refererorderbypvdesc4。Delivery&ETL也提供交付到MaxCompute(原ODPS)、OSS和ETL服务。有兴趣的同学可以参考相应的帮助链接总结一下日志服务数据访问向导(Wizard)旨在帮助用户快速访问各种日志场景。NGINX访问日志只是其中的一小部分。对各种数据源的访问也在不断更新。请拭目以待~