Skip to content

tomcat错误请求占比

关键词

网站日志分析,嵌套子查询,通用聚合分析,错误请求分布

相关函数

case when,round,count

先在SQL内部获取到请求status超过400的错误请求数量,以及总的请求数量,然后再外部计算比值, 展示时使用单值图中的刻度盘,单位改为 %

SQL
* |
select
  round((errorCount * 100.0 / totalCount), 2) as errorRatio
from
  (
    select
      sum(
        case
          when status >= 400 then 1
          else 0
        end
      ) as errorCount,
      count(1) as totalCount
    from
      log
  )

SQL查询结果样例:

样例图片