ロギング問合せ言語仕様
処理モデル
ロギング問合せ言語の処理は、データ・フロー・モデルに基づきます。各問合せは1つ以上のログを参照し、結果として表データ・セットを生成する必要があります。問合せ言語には、構造化ログと非構造化ログを検索、フィルタ処理および集計するための演算子がいくつか用意されています。
ログ・ストリーム
search "compartmentOcid/logGroupNameOrOcid/logNameOrOcid"
問合せ言語は、指定したスコープからログ・エントリをフェッチし、フィルタ、集計および視覚化できるログ・ストリームを作成します。
フィールド
search "..."
| select event as EventName
データ型
次のキー・データ型が問合せ言語でサポートされています。対応する型の値の表現については、リテラルを参照してください。
- 文字列
- 数値(整数、浮動小数点)
- アレイ
- ブール値
- タイムスタンプ
- 間隔
ステートメント
問合せは、1つ以上の文で構成されます。最後の文はデータを生成する必要があります。次の文タイプがサポートされています。
- パラメータの設定
- ストリーム式
ストリーム式
ストリームを生成するすべての式はストリーム式です。ストリーム式は、次の演算子を使用して作成できます。
- ストリーミング演算子
- 集計演算子
パイプ(|)
パイプは左側の演算子を右側のストリーム式に適用します。パイプ式はストリーム式です。
パイプの右側の演算子は、1つのストリームのみを消費する必要があります(集合演算、フィルタなど)。
search "application"
| where level = 'ERROR'
>>
{"timestamp": "2019-01-03T00:04:01", "level":"ERROR", "host":"host1", "message":"download failed...", "impact":2}
{"timestamp": "2019-01-03T00:06:39", "level":"ERROR", "host":"host2", "message":"reached 90% file size limit... ", "impact":4}
{"timestamp": "2019-01-03T00:06:59", "level":"ERROR", "host":"host2", "message":"reached 95% file size limit... ", "impact":5}
演算子
- ストリーム演算子
- スカラー演算子
- 集約
ストリーム演算子
ストリーム演算子は、ログ・エントリをフィルタで除外または変更することで、ログ・ストリームを作成または変更します。
search
search "loggroup1/logname1" "loggroup2/logname2" "compartmentOCID/loggroup3/logname3"
where
search "application"
| where level = 'ERROR'
>>
{"timestamp": "2019-01-03T00:04:01", "level":"ERROR", "host":"host1", "message":"download failed...", "impact":2}
{"timestamp": "2019-01-03T00:06:39", "level":"ERROR", "host":"host2", "message":"reached 90% file size limit... ", "impact":4}
{"timestamp": "2019-01-03T00:06:59", "level":"ERROR", "host":"host2", "message":"reached 95% file size limit... ", "impact":5}
search "application"
| where ( level = 'ERROR' or level = 'INFO' )
and host='host1' and "opc-request-id" ~ '.*AAAA.*'
>>
{"timestamp": "2019-01-03T00:04:01", "level":"ERROR", "host":"host1", "message":"download failed...", "impact":2}
{"timestamp": "2019-01-03T00:04:05", "level":"INFO", "host":" host1", "message":"host list updated..."}
where
はオプションです。search "application"
| level = 'ERROR'
ログの内容全体にフィルタを指定すると、全文検索を実行できます。logContent
を検索すると、値が文字列と一致するログ行が返されます。この機能ではワイルドカードがサポートされています。search "application"
| where logContent = 'ERROR' -- returns log lines with a value matching "ERROR"
search "application"
| where logContent = '*ERROR*' -- returns log lines with a value containing "ERROR"
top
search "application"
| top 3 by impact
>>
{"timestamp": "2019-01-03T00:06:59", "level":"ERROR", "host":"host2", "message":"reached 95% file size limit... ", "impact":5}
{"timestamp": "2019-01-03T00:06:39", "level":"ERROR", "host":"host2", "message":"reached 90% file size limit... ", "impact":4}
{"timestamp": "2019-01-03T00:04:01", "level":"ERROR", "host":"host1", "message":"download failed...", "impact":2}
sort
search "application"
| sort by impact desc
>>
{"timestamp": "2019-01-03T00:06:59", "level":"ERROR", "host":"host2", "message":"reached 95% file size limit... ", "impact":5}
{"timestamp": "2019-01-03T00:06:39", "level":"ERROR", "host":"host2", "message":"reached 90% file size limit... ", "impact":4}
{"timestamp": "2019-01-03T00:04:01", "level":"ERROR", "host":"host1", "message":"download failed...", "impact":2}
{"timestamp": "2019-01-03T00:05:33", "level":"WARNING", "host":"host2", "message":"reached 70% file size limit... ", "impact":1}
{"timestamp": "2019-01-03T00:04:05", "level":"INFO", "host":" host1", "message":"host list updated..."}
{"timestamp": "2019-01-03T00:06:59", "level":"INFO", "host":" host2", "message":"fs clean up started..."}
search "application"
| sort by host, impact desc
>>
{"timestamp": "2019-01-03T00:06:59", "level":"ERROR", "host":"host2", "message":"reached 95% file size limit... ", "impact":5}
{"timestamp": "2019-01-03T00:06:39", "level":"ERROR", "host":"host2", "message":"reached 90% file size limit... ", "impact":4}
{"timestamp": "2019-01-03T00:05:33", "level":"WARNING", "host":"host2", "message":"reached 70% file size limit... ", "impact":1}
{"timestamp": "2019-01-03T00:06:59", "level":"INFO", "host":" host2", "message":"fs clean up started..."}
{"timestamp": "2019-01-03T00:04:01", "level":"ERROR", "host":"host1", "message":"download failed...", "impact":2}
{"timestamp": "2019-01-03T00:04:05", "level":"INFO", "host":" host1", "message":"host list updated..."}
dedup
search "application"
| dedup host
>>
{"timestamp": "2019-01-03T00:04:01", "level":"ERROR", "host":"host1", "message":"download failed...", "impact":2}
{"timestamp": "2019-01-03T00:05:33", "level":"WARNING", "host":"host2", "message":"reached 70% file size limit... ", "impact":1}
search "application"
| dedup host, impact
{"timestamp": "2019-01-03T00:04:01", "level":"ERROR", "host":"host1", "message":"download failed...", "impact":2}
{"timestamp": "2019-01-03T00:05:33", "level":"WARNING", "host":"host2", "message":"reached 70% file size limit... ", "impact":1}
{"timestamp": "2019-01-03T00:06:39", "level":"ERROR", "host":"host2", "message":"reached 90% file size limit... ", "impact":4}
{"timestamp": "2019-01-03T00:06:59", "level":"ERROR", "host":"host2", "message":"reached 95% file size limit... ", "impact":5}
select
select
の集計バージョンについては、summarize
を参照してください。search "application"
| select level, host, impact+10 as impact, timestamp
>>
{"level":"ERROR", "host":"host1", "impact": 12, "timestamp": "2019-01-03T00:04:01"}
{"level":"INFO", "host":" host1", "timestamp": "2019-01-03T00:04:05"}
{"level":"WARNING", "host":"host2", "impact": 11, "timestamp": "2019-01-03T00:05:33"}
{"level":"ERROR", "host":"host2", "impact": 14, "timestamp": "2019-01-03T00:06:39"}
{"level":"ERROR", "host":"host2", "impact": 15, "timestamp": "2019-01-03T00:06:59"}
{"level":"INFO", "host":" host2", "timestamp": "2019-01-03T00:06:59"}
extend
search "application"
| extend concat(host, 'us.oracle.com') as fqn
>>
{"timestamp": "2019-01-03T00:04:01", "level":"ERROR", "host":"host1", "message":"download failed...", "impact":2, "fqn": "host1.us.oracle.com"}
{"timestamp": "2019-01-03T00:04:05", "level":"INFO", "host":" host1", "message":"host list updated...", "fqn": "host1.us.oracle.com"}
{"timestamp": "2019-01-03T00:05:33", "level":"WARNING", "host":"host2", "message":"reached 70% file size limit... ", "impact":1, "fqn": "host2.us.oracle.com"}
{"timestamp": "2019-01-03T00:06:39", "level":"ERROR", "host":"host2", "message":"reached 90% file size limit... ", "impact":4, "fqn": "host2.us.oracle.com"}
{"timestamp": "2019-01-03T00:06:59", "level":"ERROR", "host":"host2", "message":"reached 95% file size limit... ", "impact":5, "fqn": "host2.us.oracle.com"}
{"timestamp": "2019-01-03T00:06:59", "level":"INFO", "host":" host2", "message":"fs clean up started...", "fqn": "host2.us.oracle.com"}
rex
search "application"
| rex(raw, /reached (?<percentage>[0-9]+)%/)
| where !isnull(percentage)
| select host, percentage
>>
{"host": 'host2', percentage: '70'}
{"host": 'host2', percentage: '90'}
{"host": 'host2', percentage: '95'}
explode
search "application"
| select host
| dedup by host
| explode([1,2,3]) as num
>>
{"host": "host1", "num": "1"}
{"host": "host1", "num": "2"}
{"host": "host1", "num": "3"}
{"host": "host2", "num": "1"}
{"host": "host2", "num": "2"}
{"host": "host2", "num": "3"}
スカラー演算子
Arithmetic operations:
: - <expr>
: <expr1> + <expr2>
: <expr1> * <expr2>
: <expr1> - <expr2>
: <expr1> / <expr2>
Boolean operations:
: <expr1> OR <expr2>
: <expr1> AND <expr2>
: NOT <expr1>
Functions/UDFs:
: <func>(<arg1>[, ...])
: CAST(<expr> AS <type>)
String operations:
: <expr> ~ /regex/ # regex matching
: <expr> = <string> # substring matching
集計演算子
count
search "application"
| count
>>
{"count": 6}
summarize
指定された列および時間間隔で現在のログ・ストリームをグループ化し、名前付き式を使用して集計します。列のグループ化が指定されていない場合、summarize
はストリーム全体を集計します。
search "application"
| summarize avg(impact) as impact by level interval 1m
>>
{"timestamp": "2019-01-03T00:04:00", "level":"ERROR", "impact": 2}
{"timestamp": "2019-01-03T00:04:00", "level":"INFO", "impact": 0}
{"timestamp": "2019-01-03T00:05:00", "level":"WARNING", "impact":1}
{"timestamp": "2019-01-03T00:06:00", "level":"ERROR", "impact":4.5}
{"timestamp": "2019-01-03T00:06:00", "level":"INFO", "impact": 0}
interval
はオプションです。search "application"
| summarize max(impact)
>>
{"impact": 5}
特殊列
raw
raw
は、元のメッセージ全体のテキストを表す特殊な列です。search "application"
| select *, command=regex('<([^>]*)>', raw)
| where command = 'rm'
ts
ログのエントリのタイムスタンプ。
index_ts
収集タイムスタンプ。ts
とは対照的です。
コメント
search "application"
| count -- this is a single line comment
/* this is a
multi-line
comment
*/
識別子
name: \$?[a-zA-Z_][a-zA-Z_0-9]*
例: level
、app_severity
、$level
。
name: "[^"]+"
例: "opc-request-id"
、"-level"
。すべてのパラメータ参照は、ドル記号($
)で始まります(例: $level
)。
リテラル
タイプ | 例 |
---|---|
文字列 | 'hello ',' world \'! ' |
ワイルドカードのパターン | "acc -*" |
integer | -1, 0, +200 |
float | 1.2、0.0001、1.2e10 |
配列 | [1,2,3,4], [] |
interval | 3 h、2 m |
nULL値可能 | null |
関数
名前 | 説明 |
---|---|
has(field1) |
field1が行に存在するかどうかをチェックします(isnull() とは異なります。 |
isnull(expr1) |
|
concat(expr1, ...) |
|
coalesce(expr1, expr2) |
expr1 がnull の場合はexpr2 、それ以外の場合はexpr1 を戻します。 |
join(delim1, val1, val2, ...) |
デリミタjoin(',','a',b') => 'a,b' を使用して複数の値を結合します。 |
split(delim1, str1) |
デリミタsplit(',', 'a,b') => ['a', 'b'] によって、文字列をサブ文字列に分割します。 |
array_append(val1, ...) |
渡された値から配列を作成します。値は配列またはスカラー値です。 |
array_count(arr1) |
配列の要素の数を返します。 |
time_format(time, format) |
指定された書式に基づいて時間から文字列を生成します。 |
if(pred, val1, val2) |
pred がtrueの場合はval1 を戻し、それ以外の場合はval2 を戻します。 |
名前 | 説明 |
---|---|
sum(expr1) |
|
avg(expr1) |
|
min(expr1) |
|
max(expr1) |
|
values(expr1) |
値を配列に蓄積します。 |
count() |
行数をカウントします。 |
count(expr) |
Nullでないexpr 値の数を数えます。 |
count(distinct(expr)) |
個別のexpr 値の数を数えます。 |
percentile(expr, percentile1[, percentile2...] |
最も近いランクのパーセンタイル:渡されたパーセンタイルnごとに複数の列を作成します。 |
システム・パラメータ
prefex
query.を含むすべてのパラメータは予約されています。次のパラメータがサポートされています。
名前 | タイプ | 例 | 説明 |
---|---|---|---|
query.from |
ISO 8601形式の日時を含む文字列。 | '2007 -04-05T14: 30' | 問合せウィンドウの開始時間を指定します。 |
query.lookupfolder |
パスを含む文字列。 | 'lookup - ucket/dynamic' | 参照CSVファイルを含むオブジェクト・ストレージ・バケットである必要があります。 |
query.to |
ISO 8601の日時を含む文字列。 | '2007 -04-05T14: 30 +05:00' | 問合せウィンドウの終了時間を指定します。 |
フィルタ処理の例
search "auditd_syscall"
| type='SYSCALL' OR type='PATH' OR type='PROCTITLE' OR type='EXECVE'
明示的な時間ウィンドウの例
set query.from=-30m;
set query.to=now;
search audit_authentication
集計の例
search StormEvents
| isnotempty('EndLocation')
| summarize count() as event_count by EndLocation
| top 10 by event_count