ケースリスト

エラー 500% が急上昇したときにアラームをトリガーする

毎分エラー 500 の割合を数えます。 過去 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 分間のデータは 1 分をカバーしません。 したがって、 1 分あたりの平均トラフィックをカウントするために、正規化のために統計値を (max(time) - min(time)) で割ってください。
* | SELECT SUM(inflow) / (max(__time__) - min(__time__)) 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

GROUP BY 結果のパーセントを返します。

異なる部署の集計結果と関連する割合を列挙します。 この問合せは、サブクエリ関数とウィンドウ関数を結合します。 sum(c) over()は、すべての行の値の合計を計算することを示します。

* | select department, c*1.0/ sum(c) over () from(select count(1) as c, department from log groupby 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 by time limit 100