ロギング問合せ言語仕様
ロギング・検索ページで、拡張モード・カスタム検索で問合せ構文コンポーネントを使用します。
詳細は、「拡張検索問合せ」および「保存済検索」も参照してください。
問合せの構成要素
ロギング問合せ言語処理は、データ・フロー・モデルに基づいています。各問合せは、1つ以上のログを参照し、結果として表データセットを生成できます。問合せ言語には、構造化および非構造化ログの検索、フィルタリングおよび集計を行うための複数の演算子があります。
ロギング問合せには、次の構成要素が含まれます:
ログ・ストリーム
search <log_stream> (,? <log_stream>)*問合せ言語は、指定された範囲からログ・エントリをフェッチし、フィルタ、集計およびビジュアル化が可能なログ・ストリームを構成します。
ログ・ストリーム:
<log_stream> := "<compartment_ocid> ( /<log_goup_ocid> ( /<log_object_ocid> )? )?"
例:
search "compartmentOcid/logGroupNameOrOcid/logNameOrOcid"
search "compartmentOcid/logGroupNameOrOcid"
search "compartmentOcid"
search "compartmentOcid/logGroupNameOrOcid/logNameOrOcid", "compartmentOcid_2/logGroupNameOrOcid_2", "compartmentOcid_3"
フィールド
search "..."
| select event as EventNameフィールドはJSON表記であるため、特殊文字は引用符で囲む必要があります。
Fields: <field_name> := <identifier> (DOT <identifier>)*
識別子の場合:
<identifier> := a-zA-Z_[a-zA-Z_0-9]* | ('"' (~'"' | '""')* '"')
例:
- type
- data.message
- data.request.URL
- "type"
- "data"."message"
- "data.message" ("data"."message"とは異なります)
- data."$event"
- data."first name"
- data."an example of escaped ("") double quotes"
データ型
問合せ言語では、次の主要なデータ型がサポートされます。これらは(longおよびdouble) 8バイトです。
対応する型の値の表現の詳細は、リテラルを参照してください。
- 文字列
- 数値(整数、浮動小数点)
- 配列
- ブール
- タイムスタンプ
- 時間隔
ストリーム式
ストリームを生成するすべての式は、ストリーム式です。ストリーム式は、次の演算子を使用して構成できます:
パイプ式
パイプ(|)は、左側の演算子を右側のストリーム式に適用します。パイプ式はストリーム式です。
パイプの右側の演算子は、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}演算子
表演算子
表演算子は、ログ・エントリを除外または変更して、ログ・ストリームを作成または変更します。BNF構文表記法も参照してください。次に、表演算子を示します:
searchwhereブール式を使用して現在のログ・ストリームをフィルタします。
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}whereはオプションです:
search "application"
| level = 'ERROR'数値およびブール・フィールドとの比較例は次のとおりです:
| data.statusCode = 200| data.isParログのコンテンツ全体に対するフィルタを指定することで、全文検索を実行できます。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<top> := top [0-9]+ by <expr>例:
top 3 by datetimetop 3 by *top 3 by (a + b)
行数は、定数の正の整数である必要があり、ソート式を指定する必要があります。
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指定された列に基づいて現在のログ・ストリームを昇順(デフォルト)または降順でソートします。演算子では、"DESC"および"ASC"キーワードを使用して順序のタイプを指定します。デフォルトのソート順序はascです。
<sort> := sort by <sort_expr> (, <sort_expr>)*
<sort_expr> := <expr> (asc | desc)?例:
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指定された列ですべての重複を除外して、現在のログ・ストリームを処理します。複数の列を指定する場合は、すべての列をカンマで区切る必要があります。
<dedup> := dedup <expr> (, <expr>)例:
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を参照してください。
<select> := select <select_expr> (, <select_expr>)*
<select_expr> := ( * | <expr> (as <identifier>)? )例:
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現在のログ・ストリームを計算列で拡張します。
<extend> := extend <expr> (as <identifier>)?例:
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"}スカラー演算子
スカラー演算子は、個々の値に適用できます。
算術演算子は次のとおりです:
+-*/
ブール演算子は次のとおりです:
andor
単項演算子:
-(<expr>)
比較演算子は次のとおりです(数式のみ):
<expr> > <expr><expr> >= <expr><expr> <= <expr><expr> < <expr><expr> = <expr><expr> != <expr>
文字列比較:
<expr> = <expr>
ファンクション:
not (<expr>)contains_ci/contains_cs (<expr>, <expr>, (true | false))最後のパラメータでは、大/小文字が区別されます。
rounddown (<expr>, '[0-9]+(d | h | m | s)')最後のパラメータは、日、時間、分または秒単位の時間間隔です。
time_format(datetime, <format>)時刻を文字列に書式設定します
concat (<axpr>, <expr>)upper (<expr>)lower (<expr>)substr (<expr>, [0-9]+ (, [0-9]+)?)第2引数は開始索引で、第3引数(使用する文字数)はオプションです。
isnull (<expr>)isnotnull (<expr>)
集計演算子
count現在のログ・ストリームの行数を計算します:
search "application"
| count
>>
{"count": 6}summarize現在のログ・ストリームを指定された列と時間間隔でグループ化し、名前付きの式を使用して集計します。グループ化列が指定されない場合、summarizeはストリーム全体を集計します。
search "application"
| summarize count(impact) as impact by level, rounddown(datetime, '1m') as timestamp特殊列
logContentlogContentは、元のメッセージ全体のテキストを表す特別な列です。例:
search "application"
| where logContent = '*ERROR*' -- returns log lines with a value containing "ERROR"コメント
単一行コメントと複数行コメントの両方がサポートされます。例:
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-*" |
| 整数 | -1, 0, +200 |
| 浮動小数点 | 1.2, 0.0001, 1.2e10 |
| 配列 | [1,2,3,4], [] |
| 時間隔 | 3h, 2m |
| NULL値可能 | null |
ファンクション
スカラー・ファンクションは次のとおりです:
isnull(expr1)concat(expr1, ...)
集計ファンクションは次のとおりです:
sum(expr1)avg(expr1)min(expr1)max(expr1)count(): 行数をカウントします。count(expr): null以外のexpr値の数をカウントします。first(expr1)last(expr1)
システム・パラメータ
prefex "query."のすべてのパラメータは、予約されています。次のパラメータがサポートされます:
| 名前 | タイプ | 例 | 説明 |
|---|---|---|---|
query.from |
ISO 8601フォーマットの日時の文字列。 | '2007-04-05T14:30' | 問合せウィンドウの開始時間を指定します。 |
query.to |
ISO 8601の日時の文字列。 | '2007-04-05T14:30+05:00' | 問合せウィンドウの終了時間を指定します。 |