NGINX logs include important information that can be used for website O&M. Log Service provides the e_table_map function that you can use to enrich HTTP response status codes for NGINX log analysis. This topic describes how to use the data transformation feature of Log Service to enrich HTTP response status codes.
Prerequisites
Scenarios
For example, you have developed Application A and defined HTTP response status codes to maintain the application. The data volume is updated at irregular intervals. However, only the http_code field in raw NGINX logs indicates the status of HTTP requests. This field cannot help you identify issues in an efficient manner.
To meet the preceding requirements, you must use the e_table_map function to enrich the log field based on a mapping table of HTTP response status codes. Then, you can identify the status of HTTP requests in an efficient manner.
- Raw log
This raw log is stored in a Logstore named nginx-demo. The value of the http_code field is an HTTP response status code.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.103.10 remote_addr:203.0.103.10 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
- Mapping table of HTTP response status codes
The following table is a typical mapping table of HTTP response status codes.
code alias category desc 100 1xx Informational Continue 200 2xx Success OK 300 3xx Redirection Multiple Choices 400 4xx Client Error Bad Request - Enriched log
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.103.10 remote_addr:203.0.103.10 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
Solutions
Transformation process

- Convert an HTTP response status code to a table object.
- Use the e_table_map function to transform and enrich data.
Solutions
Solution | Supported data volume | Incremental update | Batch update | Scenario |
---|---|---|---|---|
Use a Logstore to enrich data (recommended) | Large | Supported | Supported | A mapping table that contains a large volume of data and is frequently updated |
Use a MySQL table to enrich data | Medium | Not supported | Supported | A mapping table that is frequently updated |
Use an Object Storage Service (OSS) object to enrich data | Medium | Not supported | Supported | A mapping table that is infrequently updated |
Encode responses to enrich data | Small | Not supported | Not supported | A simple mapping table of HTTP response status codes |