Thisトピック説明ケースのログデータ分析。

ケースリスト

過去5分間にエラー率が40% を超えたときにアラートをトリガーする

1分ごとにエラー500の割合を計算します。 過去5分間にエラー率が40% を超えると、アラートがトリガーされます。
ステータス: 500 | select __topic __, max_by(error_count,window_time)/1.0/sum(error_count) as error_ratio, sum(error_count) as total_error from ()
__topic __, count(*) をerror_count、__time__ - _time___time__ % を_topic __, window_timeによってロググループからwindow_timeとして300
)
グループby __topic__ having max_by(error_count,window_time)/1.0/sum(error_count) > 0.4とsum(error_count) > 500注文by total_error desc制限100

Count交通とアラート設定

Count交通毎分。 An警告はときにトリガ交通plunges。 直前にカウントされたトラフィックは1分をカバーしません。 したがって、正規化にmaximum (max(__time__) - min(__time__),1) を使用して統計値を除算し、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は特性によってカウントする必要があります。 この状況では、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 100