先在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查询结果样例: