阿里云SLS日志实用查询语句

本文涉及的产品
日志服务 SLS,月写入数据量 50GB 1个月
简介: 比较实用的阿里云SLS查询语句,通过该语句能掌握应用的运行情况、例如:状态码走势和分布、响应时间走势和分布、搜索引擎的分布情况。内外网请求情况等,对于故障分析、应用健康都能比较好的了解。
  1. 状态码分布走势:
(*)| SELECT sum(IF (status < 600 AND status > 499, 1, 0)) AS code_50x, sum(IF(status < 500 AND status > 399, 1, 0))  AS code_40x, sum(IF(status < 400 AND status > 299, 1, 0))  AS code_30x, sum(IF(status < 300, 1, 0))  AS code_20x, date_format( from_unixtime(__time__ -__time__%60),'%m-%d %H:%i' )  as time group by __time__ - __time__% 60 order by time limit 10000 

参考图:codeline.png

2.搜索引擎分布走势图:

(*)| SELECT sum(IF (http_user_agent LIKE '%pider%' OR http_user_agent LIKE '%bot%', 1, 0))  AS allSpider, sum(IF (http_user_agent LIKE '%Baiduspider%', 1, 0))  AS Baiduspider, sum(IF (http_user_agent LIKE '%Bytespider%', 1, 0))  AS Bytespider, sum(IF (http_user_agent LIKE '%bingbot%', 1, 0))  AS bingbot, sum(IF (http_user_agent LIKE '%Googlebot%', 1, 0))  AS Googlebot,  sum(IF (http_user_agent LIKE '%YisouSpider%', 1, 0))  AS YisouSpider, sum(IF (http_user_agent LIKE '%Applebot%', 1, 0))  AS Applebot,date_format( from_unixtime(__time__ -__time__%60),'%m-%d %H:%i' )  as time group by __time__ - __time__% 60 order by time limit 10000 

参考图:spiderline.png

3.请求时间分布走势:

(*)| SELECT sum(IF (request_time < 1, 1, 0)) AS less1, sum(IF(request_time < 3 AND request_time > 1, 1, 0))  AS Range1To3, sum(IF(request_time < 5 AND request_time > 3, 1, 0))  AS Range3To5, sum(IF(request_time < 10 AND request_time > 5, 1, 0))  AS Range5To10, sum(IF(request_time < 15 AND request_time > 10, 1, 0))  AS Range10To15, sum(IF(request_time > 15, 1, 0))  AS gt15, date_format( from_unixtime(__time__ -__time__%60),'%m-%d %H:%i' )  as time group by __time__ - __time__% 60 order by time limit 10000 

参考图:timedistline.png

4.请求时间分布:

(*)| SELECT  CASE    WHEN request_time < 1 then '<1s'    WHEN request_time < 3 then '<3s'    WHEN request_time < 5 then '<5s'    WHEN request_time < 10 then '<10s'    WHEN request_time < 20 then '<20s'    ELSE 'large'  END AS request_time,  count(*) AS pvGROUP BY  request_time 

参考图:timedist.png

5.内外网请求走势:

(*)| SELECT sum(IF ( ip_to_domain(remote_addr)='intranet', 1, 0))  AS lan,sum(IF( ip_to_domain(remote_addr)='internet', 1, 0))  AS wan,date_format( from_unixtime(__time__ -__time__%60),'%m-%d %H:%i' )  as time group by __time__ - __time__% 60 order by time limit 10000 

参考图:neiwaiwang.png

6.内网请求IPtop分布:

(*)| select count(1) as pv, remote_addr as client_ip where ip_to_domain(remote_addr)='intranet' group by client_ip order by pv desc limit 20 

参考图:neiwangIptop.png

7.公网IPtop分布:

(*)| select count(1) as pv, split_part(http_x_forwarded_for,',',1) as realip  where ip_to_domain(split_part(http_x_forwarded_for,',',1))='internet' AND request_method != 'POST' group by realip order by pv desc limit 20 

参考图:gwipTop.png

8.异常状态码的后端服务器:

(*)| select count(1) as pv,status, upstream_addr as backend_ip where status > 399 group by backend_ip,status order by pv desc limit 20 

参考图:exception_ups.png

相关实践学习
日志服务之使用Nginx模式采集日志
本文介绍如何通过日志服务控制台创建Nginx模式的Logtail配置快速采集Nginx日志并进行多维度分析。
相关文章
|
12天前
|
XML JSON Java
Logback 与 log4j2 性能对比:谁才是日志框架的性能王者?
【10月更文挑战第5天】在Java开发中,日志框架是不可或缺的工具,它们帮助我们记录系统运行时的信息、警告和错误,对于开发人员来说至关重要。在众多日志框架中,Logback和log4j2以其卓越的性能和丰富的功能脱颖而出,成为开发者们的首选。本文将深入探讨Logback与log4j2在性能方面的对比,通过详细的分析和实例,帮助大家理解两者之间的性能差异,以便在实际项目中做出更明智的选择。
87 3
|
13天前
|
存储 缓存 关系型数据库
MySQL事务日志-Redo Log工作原理分析
事务的隔离性和原子性分别通过锁和事务日志实现,而持久性则依赖于事务日志中的`Redo Log`。在MySQL中,`Redo Log`确保已提交事务的数据能持久保存,即使系统崩溃也能通过重做日志恢复数据。其工作原理是记录数据在内存中的更改,待事务提交时写入磁盘。此外,`Redo Log`采用简单的物理日志格式和高效的顺序IO,确保快速提交。通过不同的落盘策略,可在性能和安全性之间做出权衡。
1576 12
|
9天前
|
Web App开发 存储 监控
iLogtail 开源两周年:UC 工程师分享日志查询服务建设实践案例
本文为 iLogtail 开源两周年的实践案例分享,讨论了 iLogtail 作为日志采集工具的优势,包括它在性能上超越 Filebeat 的能力,并通过一系列优化解决了在生产环境中替换 Filebeat 和 Logstash 时遇到的挑战。
|
12天前
|
SQL 存储 人工智能
阿里云日志服务的傻瓜式极易预测模型
预测服务有助于提前规划,减少资源消耗和成本。阿里云日志服务的AI预测服务简化了数学建模,仅需SQL操作即可预测未来指标,具备高准确性,并能处理远期预测。此外,通过ScheduledSQL功能,可将预测任务自动化,定时执行并保存结果。
31 3
|
8天前
|
Python
log日志学习
【10月更文挑战第9天】 python处理log打印模块log的使用和介绍
15 0
|
10天前
|
数据可视化
Tensorboard可视化学习笔记(一):如何可视化通过网页查看log日志
关于如何使用TensorBoard进行数据可视化的教程,包括TensorBoard的安装、配置环境变量、将数据写入TensorBoard、启动TensorBoard以及如何通过网页查看日志文件。
44 0
|
13天前
|
存储 分布式计算 NoSQL
大数据-136 - ClickHouse 集群 表引擎详解1 - 日志、Log、Memory、Merge
大数据-136 - ClickHouse 集群 表引擎详解1 - 日志、Log、Memory、Merge
20 0
|
13天前
|
监控 网络协议 CDN
阿里云国际监控查询流量、用量查询流量与日志统计流量有差异?
阿里云国际监控查询流量、用量查询流量与日志统计流量有差异?
|
2月前
|
Kubernetes Ubuntu Windows
【Azure K8S | AKS】分享从AKS集群的Node中查看日志的方法(/var/log)
【Azure K8S | AKS】分享从AKS集群的Node中查看日志的方法(/var/log)
110 3
|
13天前
|
缓存 Linux 编译器
【C++】CentOS环境搭建-安装log4cplus日志组件包及报错解决方案
通过上述步骤,您应该能够在CentOS环境中成功安装并使用log4cplus日志组件。面对任何安装或使用过程中出现的问题,仔细检查错误信息,对照提供的解决方案进行调整,通常都能找到合适的解决之道。log4cplus的强大功能将为您的项目提供灵活、高效的日志管理方案,助力软件开发与维护。
32 0