すべてのプロダクト
Search
ドキュメントセンター

Simple Log Service:ログデータ分析の一般的な例

最終更新日:Aug 26, 2024

このトピックでは、ログデータ分析の例をいくつか示します。

前の5分以内にエラー率が40% を超えたときにアラートをトリガーする

HTTP 500エラーが1分ごとに返されるレートを計算し、エラーレートが過去5分以内に40% を超えたときにアラートをトリガーします。

status:500 | select __topic__, max_by(error_count,window_time)/1.0/sum(error_count) as error_ratio, sum(error_count) as total_error  from (
select __topic__, count(*) as error_count , __time__ - __time__ % 300  as window_time  from log group by __topic__, window_time
) 
group by __topic__  having  max_by(error_count,window_time)/1.0/sum(error_count)   > 0.4  and sum(error_count) > 500 order by total_error desc limit 100

トラフィック統計の収集とアラートの設定

毎分トラフィック統計を収集し、トラフィック量が特定のしきい値を下回ったときにアラートをトリガーします。 前の分に収集された統計は、1分をカバーしません。 1分あたりの平均トラフィック統計を収集するには、統計値をmaximum (max(__time__) - min(__time__),1) で割り、正規化します。

* | SELECT SUM(inflow) / greatest(max(__time__) - min(__time__),1) as inflow_per_minute, date_trunc('minute',__time__)  as minute group by minute

データサイズで平均レイテンシを計算する

データサイズに基づいて複数のバケットにデータを分配し、各バケットのデータの平均レイテンシを計算します。

* | select avg(latency) as latency , case when originSize < 5000 then 's1' when originSize < 20000 then 's2' when originSize < 500000 then 's3' when originSize < 100000000 then 's4' else 's5' end as os group by os

異なる結果の割合を返す

異なる部門のカウント結果と結果の割合を返します。 このクエリには、サブクエリとウィンドウ関数が含まれます。 sum(c) over() は、すべての行の値の合計を示します。

* |  select   department, c*1.0/ sum(c) over ()  from(select  count(1) as c, department   from log group by department)

クエリ条件を満たすURLの数を数える

特性に基づいてURLの数を数えるには、CASE WHEN句またはCOUNT_IF句を使用できます。 後者の条項はより簡単です。

* | select  count_if(uri like '%login') as login_num, count_if(uri like '%register') as register_num, date_format(date_trunc('minute', __time__), '%m-%d %H:%i') as time  group by time order by time limit 100