After you collect NGINX access logs in SLS, you can add dashboard filters to query logs by status code or request method. This topic uses NGINX access logs as examples.
Prerequisites
-
You have collected NGINX access logs. For more information, see Collect text logs from servers.
-
You have created indexes. For more information, see Create indexes.
Use case 1: Filter logs with a status code of 200
When you filter logs with status code 200, the filter transforms the query into status: 200 AND [search query] | [sql query]. The key is status and the value is 200.
-
In the edit mode of the dashboard, click the Filter
icon in the upper-right corner. -
In the Filter panel, configure the following settings and click OK.
Name:
statusType: Filter
Key:
statusAdd dynamic list items: enabled; select
website_logfor Select LogstoreTime range: 15min Last 15 minutes
Query statement:
*|select DISTINCT status
-
The configured filter:
The filter displays a dropdown panel for the status field. Available status codes include 200, 306, 304, 202, 204, and 305. The panel supports search and select-all functions.
-
The following shows the raw data before filtering.
The following analytic statement is used.
* | select status, count(*) as c group by statusCount per status code:
The query results contain multiple status codes. The
statuscolumn shows values such as 204, 203, 307, 401, 501, 206, and 207. Theccolumn shows the corresponding request counts: 31, 29, 42, 24, 10, 35, and 27, for a total of 22 records displayed across 2 pages. -
Set
statusto200to display only logs with status code 200.The resulting analytic statement is as follows.
(*)and (status: 200)| select status, count(*) as c group by status
Use case 2: Filter NGINX logs by request method
To exclude GET and POST logs, the filter transforms the query into NOT (request_method: GET OR request_method: POST) AND [search query] | [sql query]. The key is request_method, and the values are GET and POST.
-
In the edit mode of the dashboard, click the Filter
icon in the upper-right corner. -
In the Filter panel, configure the following settings and click OK.
Name:
request_methodType: Filter
Key:
request_methodQuery mode: NOT mode
Add dynamic list items: enabled; select website_log for Logstore
Query statement:
*|select DISTINCT request_method; select 15min Last 15 minutes for Time RangeDynamic list items preview:
request_methodincludes POST, GET, PUT, and DELETE
-
The configured filter:
The request_method filter dropdown panel lists available HTTP request methods as checkboxes: POST, GET, PUT, DELETE, and HEAD. Multiple selections are supported.
-
The following shows the raw data before filtering.
The following analytic statement is used.
* | select request_method, count(*) as c group by request_methodCount per
request_method:GET: 2446
POST: 573
DELETE: 244
PUT: 609
HEAD: 12
-
Select
POSTandGETforrequest_method. Only POST and GET logs are displayed.The filtered table shows statistics for request methods other than POST and GET: PUT with 609 requests, DELETE with 244 requests, and HEAD with 12 requests.
The resulting analytic statement is as follows.
(*)not (request_method: POST OR request_method: GET) | select request_method, count(*) as c group by request_method