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

Simple Log Service:e_table_map 関数を使用した HTTP 応答ステータスコードのエンリッチ

最終更新日:Jun 17, 2026

e_table_map 関数を使用して、Nginx ログの HTTP 応答ステータスコードをエンリッチします。各ステータスコードは、エイリアス、カテゴリ、および説明にマッピングされ、ログ分析とトラブルシューティングを簡素化します。

前提条件

Nginx のログデータが収集済みであること。 詳細については、「データ収集」をご参照ください。

シナリオ

ある企業が、アプリケーション用に定期的に更新される HTTP ステータスコードのマッピングテーブルを管理しています。Nginx の生ログでは、http_code フィールドのみがリクエストステータスを示しており、トラブルシューティングのための十分なコンテキストが提供されていません。

この問題に対処するため、e_table_map 関数を使用して HTTP ステータスコードのマッピングテーブルに基づいてログフィールドをエンリッチし、HTTP 応答ステータスをより読みやすくします。

  • 生ログのサンプル:

    body_bytes_sent:1750
    host:www.example.com
    http_referer:www.example.aliyundoc.com
    http_user_agent:Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_6; it-it) AppleWebKit/533.20.25 (KHTML, like Gecko) Version/5.0.4 Safari/533.20.27
    http_x_forwarded_for:203.0.XXX.XX
    remote_addr:203.0.XXX.XX
    remote_user:p288
    request_length:13741
    request_method:GET
    request_time:71
    request_uri:/request/path-1/file-1
    http_code:200
    time_local:11/Aug/2021:06:52:27
    upstream_response_time:0.66

    生ログは nginx-demo という名前の Logstore に保存されます。http_code フィールドは HTTP ステータスコードを示します。

  • HTTP ステータスコードのマッピングテーブル:

    次のテーブルに、HTTP ステータスコードマッピングのサンプルを示します。

    code

    alias

    category

    description

    100

    1xx

    Informational

    Continue

    200

    2xx

    Success

    OK

    300

    3xx

    Redirection

    Multiple Choices

    400

    4xx

    Client Error

    Bad Request

  • エンリッチされたログのサンプル:

    body_bytes_sent:1750
    host:www.example.com
    http_code:200
    http_code_alias:2xx
    http_code_category:Success
    http_code_desc:OK
    http_referer:www.example.aliyundoc.com
    http_user_agent:Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_6; it-it) AppleWebKit/533.20.25 (KHTML, like Gecko) Version/5.0.4 Safari/533.20.27
    http_x_forwarded_for:203.0.XXX.XX
    remote_addr:203.0.XXX.XX
    remote_user:p288
    request_length:13741
    request_method:GET
    request_time:71
    request_uri:/request/path-1/file-1
    time_local:11/Aug/2021:06:52:27
    upstream_response_time:0.66

ソリューション

処理フロー

image
  1. HTTP ステータスコードをテーブルオブジェクトに変換します。

  2. e_table_map 関数を使用してログデータをエンリッチします。

推奨ソリューション

データソースと更新要件に基づいて、データエンリッチのために次のいずれかのソリューションを選択します。

ソリューション

データ量サポート

増分更新

バッチ更新

最適なシナリオ

Logstore を使用したデータエンリッチ (推奨)

サポート

サポート

頻繁に更新される大規模なマッピングテーブル。

MySQL テーブルを使用したデータエンリッチ

非サポート

サポート

頻繁に更新されるマッピングテーブル。

OSS ファイルを使用したデータエンリッチ

非サポート

サポート

更新頻度の低い、比較的静的なマッピングテーブル。

マッピングテーブルのコードへの埋め込み

非サポート

非サポート

データ量が少ない標準的な HTTP ステータスコードのマッピングテーブル。

ソリューション1:Logstore を使用したデータエンリッチ (推奨)

  1. SDK を使用して、HTTP ステータスコードのマッピングデータを http_code という名前の Logstore に書き込みます。

    次のサンプルは、Logstore 内の HTTP ステータスコードログを示しています。

    __source__:203.0.XXX.XX
    __tag__:__receive_time__:1595424194
    __topic__:
    code:200
    alias:2xx
    description:OK
    category:Success

    詳細については、「SDK リファレンス」をご参照ください。

  2. HTTP ステータスコードのマッピングデータを保存する Logstore の Logstore 名、エンドポイント、および AccessKey ペアを取得します。

    エンドポイントと AccessKey ペアの詳細については、「エンドポイント」および「AccessKey ペア」をご参照ください。

  3. 生ログを保存する nginx-demo Logstore を開き、データ変換ページに移動します。

    詳細については、「データ変換タスクの作成」をご参照ください。

  4. エディターに、データ変換ステートメントを入力します。

    http_code Logstore からデータを読み取り、e_table_map 関数を使用して、一致するフィールドの値を返します。

    e_table_map( res_log_logstore_pull("cn-hangzhou-intranet.log.aliyuncs.com",
            res_local("AK_ID"),res_local("AK_KEY"),"live-demo","http_code",
            ["code","alias","description","category"]),
                  [("http_code","code")],
                  [("alias","http_code_alias"), ("description","http_code_desc"),
                  ("category","http_code_category")])
    重要

    データセキュリティのため、AccessKey ペアは高度なパラメーター設定で設定します。 詳細については、「データ変換タスクの作成」をご参照ください。

    • res_log_logstore_pull 関数は、別の Logstore からデータをプルします。 詳細については、「res_log_logstore_pull」をご参照ください。

    • e_table_map 関数は、入力フィールド値に基づいてテーブル内の一致する行を検索し、指定されたフィールドの値を返します。 詳細については、「e_table_map」をご参照ください。

  5. [データプレビュー] をクリックします。

    エンリッチ後、Nginx ログには次の HTTP ステータスコードフィールドが含まれます。

    body_bytes_sent:1750
    host:www.example.com
    http_code:200
    http_code_alias:2xx
    http_code_category:Success
    http_code_desc:OK
    http_referer:www.example.aliyundoc.com
    http_user_agent:Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_6; it-it) AppleWebKit/533.20.25 (KHTML, like Gecko) Version/5.0.4 Safari/533.20.27
    http_x_forwarded_for:203.0.XXX.XX
    remote_addr:203.0.XXX.XX
    remote_user:p288
    request_length:13741
    request_method:GET
    request_time:71
    request_uri:/request/path-1/file-1
    time_local:11/Aug/2021:06:52:27
    upstream_response_time:0.66
  6. データ変換タスクを作成します。

    詳細については、「データ変換タスクの作成」をご参照ください。

ソリューション2:MySQL テーブルを使用したデータエンリッチ

  1. HTTP ステータスコードを ApsaraDB RDS for MySQL データベースに保存します。

    次の例は、ApsaraDB RDS for MySQL の HTTP ステータスコードのマッピングテーブルを示しています。

    MySQL [etl-test]> select * from http_code limit 10;
    +------+-------+---------------+-----------------------------------+
    | code | alias | category      | description                       |
    +------+-------+---------------+-----------------------------------+
    | 100  | 1xx   | Informational | Continue                          |
    | 101  | 1xx   | Informational | Switching Protocols               |
    | 102  | 1xx   | Informational | Processing (WebDAV)               |
    | 200  | 2xx   | Success       | OK                                |
    | 201  | 2xx   | Success       | Created                           |
    | 202  | 2xx   | Success       | Accepted                          |
    | 203  | 2xx   | Success       | Non-Authoritative Information     |
    | 204  | 2xx   | Success       | No Content                        |
    | 205  | 2xx   | Success       | Reset Content                     |
    | 206  | 2xx   | Success       | Partial Content                   |
    +------+-------+---------------+-----------------------------------+
    10 rows in set (0.04 sec)
  2. ApsaraDB RDS for MySQL データベースのホストアドレス、ユーザー名、パスワード、データベース名、およびテーブル名を取得します。

  3. 生ログを保存する nginx-demo Logstore を開き、データ変換ページに移動します。

    詳細については、「データ変換タスクの作成」をご参照ください。

  4. エディターに、データ変換ステートメントを入力します。

    MySQL データベースからデータを読み取り、e_table_map 関数を使用して、一致するフィールドの値を返します。

    e_table_map(res_rds_mysql(address="MySQL host address",
                      username="username", password="password",
                      database="database",table="table name", refresh_interval=300),
                  [("http_code","code")],
                  [("alias","http_code_alias"), ("description","http_code_desc"),
                  ("category","http_code_category")])
    重要

    データセキュリティのため、AccessKey ペアは高度なパラメーター設定で設定します。 詳細については、「データ変換タスクの作成」をご参照ください。

    • res_rds_mysql 関数は、ApsaraDB RDS for MySQL データベースからテーブルコンテンツをプルします。 詳細については、「res_rds_mysql」をご参照ください。

    • e_table_map 関数は、入力フィールド値に基づいてテーブル内の一致する行を検索し、指定されたフィールドの値を返します。 詳細については、「e_table_map」をご参照ください。

  5. [データプレビュー] をクリックします。

    エンリッチ後、Nginx ログには次の HTTP ステータスコードフィールドが含まれます。

    body_bytes_sent:1750
    host:www.example.com
    http_code:200
    http_code_alias:2xx
    http_code_category:Success
    http_code_desc:OK
    http_referer:www.example.aliyundoc.com
    http_user_agent:Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_6; it-it) AppleWebKit/533.20.25 (KHTML, like Gecko) Version/5.0.4 Safari/533.20.27
    http_x_forwarded_for:203.0.XXX.XX
    remote_addr:203.0.XXX.XX
    remote_user:p288
    request_length:13741
    request_method:GET
    request_time:71
    request_uri:/request/path-1/file-1
    time_local:11/Aug/2021:06:52:27
    upstream_response_time:0.66
  6. データ変換タスクを作成します。

    詳細については、「データ変換タスクの作成」をご参照ください。

ソリューション3:OSS ファイルを使用したデータエンリッチ

  1. HTTP ステータスコードを http_code.csv という名前のファイルに保存し、Object Storage Service (OSS) バケットにアップロードします。

    詳細については、「ファイルのアップロード」をご参照ください。

  2. http_code.csv ファイルが格納されている OSS バケットのバケット名、エンドポイント、および AccessKey ペアを取得します。

    OSS のエンドポイントの詳細については、「リージョンとエンドポイント」をご参照ください。

  3. 生ログを保存する nginx-demo Logstore を開き、データ変換ページに移動します。

    詳細については、「データ変換タスクの作成」をご参照ください。

  4. エディターに、データ変換ステートメントを入力します。

    OSS バケットからデータを読み取り、e_table_map 関数を使用して、一致するフィールドの値を返します。

    e_table_map(
          tab_parse_csv(
               res_oss_file(endpoint="oss-cn-shanghai-internal.aliyuncs.com",
                  ak_id=res_local("AK_ID"), ak_key=res_local("AK_KEY"),
                  bucket="ali-sls-etl-test",
                  file="http_code.csv", format='text')),
                  [("http_code","code")],
                  [("alias","http_code_alias"),
                   ("description","http_code_desc"),
                   ("category","http_code_category")])
    重要

    データセキュリティのため、AccessKey ペアは高度なパラメーター設定で設定します。 詳細については、「データ変換タスクの作成」をご参照ください。

    • res_oss_file 関数は、OSS バケットからファイルコンテンツを取得し、定期的な更新をサポートします。 詳細については、「res_oss_file」をご参照ください。

    • tab_parse_csv 関数は、CSV 形式のテキストからテーブルを作成します。 詳細については、「tab_parse_csv」をご参照ください。

    • e_table_map 関数は、入力フィールド値に基づいてテーブル内の一致する行を検索し、指定されたフィールドの値を返します。 詳細については、「e_table_map」をご参照ください。

  5. [データプレビュー] をクリックします。

    エンリッチ後、Nginx ログには次の HTTP ステータスコードフィールドが含まれます。

    body_bytes_sent:1750
    host:www.example.com
    http_code:200
    http_code_alias:2xx
    http_code_category:Success
    http_code_desc:OK
    http_referer:www.example.aliyundoc.com
    http_user_agent:Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_6; it-it) AppleWebKit/533.20.25 (KHTML, like Gecko) Version/5.0.4 Safari/533.20.27
    http_x_forwarded_for:203.0.XXX.XX
    remote_addr:203.0.XXX.XX
    remote_user:p288
    request_length:13741
    request_method:GET
    request_time:71
    request_uri:/request/path-1/file-1
    time_local:11/Aug/2021:06:52:27
    upstream_response_time:0.66
  6. データ変換タスクを作成します。

    詳細については、「データ変換タスクの作成」をご参照ください。

ソリューション4:マッピングテーブルのコードへの埋め込み

  1. CSV 形式で HTTP ステータスコードのマッピングテーブルを準備します。

  2. 生ログを保存する nginx-demo Logstore を開き、データ変換ページに移動します。

    詳細については、「データ変換タスクの作成」をご参照ください。

  3. エディターに、データ変換ステートメントを入力します。

    tab_parse_csv 関数を使用して CSV 形式の HTTP ステータスコードをテーブルに変換し、e_table_map 関数を使用して一致するフィールドの値を返します。

    e_table_map(tab_parse_csv("code,alias,category,description\n100,1xx,Informational,Continue\n101,1xx,Informational,Switching Protocols\n102,1xx,Informational,Processing (WebDAV)\n200,2xx,Success,OK\n201,2xx,Success,Created\n202,2xx,Success,Accepted\n203,2xx,Success,Non-Authoritative Information\n204,2xx,Success,No Content\n205,2xx,Success,Reset Content\n206,2xx,Success,Partial Content\n207,2xx,Success,Multi-Status (WebDAV)\n208,2xx,Success,Already Reported (WebDAV)\n226,2xx,Success,IM Used\n300,3xx,Redirection,Multiple Choices\n301,3xx,Redirection,Moved Permanently\n302,3xx,Redirection,Found\n303,3xx,Redirection,See Other\n304,3xx,Redirection,Not Modified\n305,3xx,Redirection,Use Proxy\n306,3xx,Redirection,(Unused)\n307,3xx,Redirection,Temporary Redirect\n308,3xx,Redirection,Permanent Redirect (experimental)\n400,4xx,Client Error,Bad Request\n401,4xx,Client Error,Unauthorized\n402,4xx,Client Error,Payment Required\n403,4xx,Client Error,Forbidden\n404,4xx,Client Error,Not Found\n405,4xx,Client Error,Method Not Allowed\n406,4xx,Client Error,Not Acceptable\n407,4xx,Client Error,Proxy Authentication Required\n408,4xx,Client Error,Request Timeout\n409,4xx,Client Error,Conflict\n410,4xx,Client Error,Gone\n411,4xx,Client Error,Length Required\n412,4xx,Client Error,Precondition Failed\n413,4xx,Client Error,Request Entity Too Large\n414,4xx,Client Error,Request-URI Too Long\n415,4xx,Client Error,Unsupported Media Type\n416,4xx,Client Error,Requested Range Not Satisfiable\n417,4xx,Client Error,Expectation Failed\n418,4xx,Client Error,I'm a teapot (RFC 2324)\n420,4xx,Client Error,Enhance Your Calm (Twitter)\n422,4xx,Client Error,Unprocessable Entity (WebDAV)\n423,4xx,Client Error,Locked (WebDAV)\n424,4xx,Client Error,Failed Dependency (WebDAV)\n425,4xx,Client Error,Reserved for WebDAV\n426,4xx,Client Error,Upgrade Required\n428,4xx,Client Error,Precondition Required\n429,4xx,Client Error,Too Many Requests\n431,4xx,Client Error,Request Header Fields Too Large\n444,4xx,Client Error,No Response (Nginx)\n449,4xx,Client Error,Retry With (Microsoft)\n450,4xx,Client Error,Blocked by Windows Parental Controls (Microsoft)\n451,4xx,Client Error,Unavailable For Legal Reasons\n499,4xx,Client Error,Client Closed Request (Nginx)\n500,5xx,Server Error,Internal Server Error\n501,5xx,Server Error,Not Implemented\n502,5xx,Server Error,Bad Gateway\n503,5xx,Server Error,Service Unavailable\n504,5xx,Server Error,Gateway Timeout\n505,5xx,Server Error,HTTP Version Not Supported\n506,5xx,Server Error,Variant Also Negotiates (Experimental)\n507,5xx,Server Error,Insufficient Storage (WebDAV)\n508,5xx,Server Error,Loop Detected (WebDAV)\n509,5xx,Server Error,Bandwidth Limit Exceeded (Apache)\n510,5xx,Server Error,Not Extended\n511,5xx,Server Error,Network Authentication Required\n598,5xx,Server Error,Network read timeout error\n599,5xx,Server Error,Network connect timeout error\n"),
                  [("http_code","code")],
                  [("alias","http_code_alias"), ("description","http_code_desc"), 
                  ("category","http_code_category")])
    重要

    データセキュリティのため、AccessKey ペアは高度なパラメーター設定で設定します。 詳細については、「データ変換タスクの作成」をご参照ください。

    • tab_parse_csv 関数は、CSV 形式のテキストからテーブルを作成します。 詳細については、「tab_parse_csv」をご参照ください。

    • e_table_map 関数は、入力フィールド値に基づいてテーブル内の一致する行を検索し、指定されたフィールドの値を返します。 詳細については、「e_table_map」をご参照ください。

  4. [データプレビュー] をクリックします。

    エンリッチ後、Nginx ログには次の HTTP ステータスコードフィールドが含まれます。

    body_bytes_sent:1750
    host:www.example.com
    http_code:200
    http_code_alias:2xx
    http_code_category:Success
    http_code_desc:OK
    http_referer:www.example.aliyundoc.com
    http_user_agent:Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_6; it-it) AppleWebKit/533.20.25 (KHTML, like Gecko) Version/5.0.4 Safari/533.20.27
    http_x_forwarded_for:203.0.XXX.XX
    remote_addr:203.0.XXX.XX
    remote_user:p288
    request_length:13741
    request_method:GET
    request_time:71
    request_uri:/request/path-1/file-1
    time_local:11/Aug/2021:06:52:27
    upstream_response_time:0.66
  5. データ変換タスクを作成します。

    詳細については、「データ変換タスクの作成」をご参照ください。