Logtail sends HTTP requests to specified URLs at regular intervals based on your Logtail configuration. Then, Logtail uploads the bodies of the responses as data sources to Log Service. This topic describes how to create a Logtail configuration in the Log Service console and use the Logtail configuration to collect HTTP data.

Prerequisites

Logtail is installed on your server. For more information, see Install Logtail on a Linux server or Install Logtail on a Windows server.
Note Linux Logtail V0.16.0 and later are supported. Windows Logtail V1.0.0.8 and later are supported.

Implementation

Logtail sends HTTP requests to specified URLs based on the URLs, methods, headers, and bodies that are specified in your Logtail configuration. Then, Logtail uploads the response status codes, response bodies, and response time as data sources to Log Service.

Implementation

Features

  • You can specify multiple URLs.
  • You can specify HTTP request methods.
  • You can specify an interval at which requests are sent.
  • You can specify custom request headers.
  • You can use HTTPS.
  • You can check whether the body of a response matches a fixed pattern.

Scenarios

  • You can monitor service status by using HTTP API operations. For example, you can monitor the following types of services:
    • NGINX
    • Docker that supports monitoring by using HTTP API operations
    • Elasticsearch
    • HAProxy
    • Other services that support monitoring by using HTTP API operations
  • You can monitor service availability.

    Logtail monitors the availability of a service by sending requests to the service at regular intervals and checking the response status codes and request latency.

  • You can pull data such as Weibo comments and the number of followers at regular intervals.

Limits

  • A URL must start with http or https.
  • Custom certificates are not supported.
  • Interactive communications are not supported.

Procedure

The following procedure shows how to collect HTTP data from the NGINX status module. Requests are sent to the URL http://127.0.0.1/ngx_status at intervals of 1,000 milliseconds. A regular expression is used to extract the status information from the body of a response.

  1. Log on to the Log Service console.
  2. In the Import Data section, click Custom Data Plug-in.
  3. Select the project and Logstore. Then, click Next.
  4. Create a machine group.
    • If a machine group is available, click Use Existing Machine Groups.
    • If no machine groups are available, perform the following steps to create a machine group. In this example, an Elastic Compute Service (ECS) instance is used.
      1. On the ECS Instances tab, select Manually Select Instances. Then, select the ECS instance that you want to use and click Create.

        For more information, see Install Logtail on ECS instances.

        Important If you want to collect logs from an ECS instance that belongs to a different Alibaba Cloud account, a server in an on-premises data center, or a server of a third-party cloud service provider, you must manually install Logtail. For more information, see Install Logtail on a Linux server or Install Logtail on a Windows server.

        After you manually install Logtail, you must configure a user identifier for the server. For more information, see Configure a user identifier.

      2. After Logtail is installed, click Complete Installation.
      3. In the Create Machine Group step, configure the Name parameter and click Next.

        Log Service allows you to create IP address-based machine groups and custom identifier-based machine groups. For more information, see Create an IP address-based machine group and Create a custom identifier-based machine group.

  5. Select the new machine group from Source Server Groups and move the machine group to Applied Server Groups. Then, click Next.
    Important If you apply a machine group immediately after you create the machine group, the heartbeat status of the machine group may be FAIL. This issue occurs because the machine group is not connected to Log Service. To resolve this issue, you can click Automatic Retry. If the issue persists, see What do I do if no heartbeat connections are detected on Logtail?
  6. In the Specify Data Source step, configure the Config Name and Plug-in Config parameters. Then, click Next.
    • inputs specifies the collection configurations of your data source. This parameter is required.
      Important You can specify only one type of data source in the inputs parameter.
    • processors specifies the processing configurations that are used to parse data. You can extract fields, extract log time, desensitize data, and filter logs. This parameter is optional. You can specify one or more processing methods. For more information, see Overview.
    {
     "inputs": [
         {
             "type": "metric_http",
             "detail": {
                 "IntervalMs": 1000,
                 "Addresses": [
                     "http://127.0.0.1/ngx_status"
                 ],
                 "Headers": {"key":"value"},
                 "IncludeBody": true
             }
         }
     ],
     "processors" : [
         {
             "type": "processor_regex",
             "detail" : {
                 "SourceKey": "content",
                 "Regex": "Active connections: (\\d+)\\s+server accepts handled requests\\s+(\\d+)\\s+(\\d+)\\s+(\\d+)\\s+Reading: (\\d+) Writing: (\\d+) Waiting: (\\d+).*",
                 "Keys": [
                     "connection",
                     "accepts",
                     "handled",
                     "requests",
                     "reading",
                     "writing",
                     "waiting"
                 ],
                 "FullMatch": true,
                 "NoKeyError": true,
                 "NoMatchError": true,
                 "KeepSource": false
             }
         }
     ]
    }
    ParameterTypeRequiredDescription
    typestringYesThe type of the data source. Set the value to metric_http.
    Addressesstring arrayYesThe URLs.
    Note A URL must start with http or https.
    IntervalMsintYesThe interval between two consecutive requests. Unit: milliseconds.
    MethodstringNoThe request method. Default value: GET. The value must be in uppercase.
    BodystringNoThe body of an HTTP request. This parameter is empty by default.
    Headerskey: string, value: string mapNoThe headers of an HTTP request. This parameter is empty by default. Example: {"key":"value"}. Configure this parameter based on your business requirements.
    PerAddressSleepMsintNoThe interval at which requests are sent to the URLs specified by the Addresses parameter. Unit: milliseconds. Default value: 100.
    ResponseTimeoutMsintNoThe timeout period for a request. Unit: milliseconds. Default value: 5000.
    IncludeBodybooleanNoSpecifies whether to collect the request body. Default value: false. If you set this parameter to true, the request body is stored in the field that is named content.
    FollowRedirectsbooleanNoSpecifies whether to automatically process URL redirects. Default value: false.
    InsecureSkipVerifybooleanNoSpecifies whether to skip the HTTPS security check. Default value: false.
    ResponseStringMatchstringNoSpecifies whether to match the response body against a regular expression. The match result is stored in the field that is named _response_match_. If the response body matches the regular expression, the value of the field is yes. Otherwise, the value is no.
  7. Preview data, configure indexes, and then click Next.
    By default, full-text indexing is enabled for Log Service. You can also configure field indexes based on collected logs in manual mode or automatic mode. To configure field indexes in automatic mode, click Automatic Index Generation. This way, Log Service automatically creates field indexes. For more information, see Create indexes.
    Important If you want to query and analyze logs, you must enable full-text indexing or field indexing. If you enable both full-text indexing and field indexing, the system uses only field indexes.

Troubleshooting

If no data is displayed on the preview page or query page after logs are collected by using Logtail, you can troubleshoot the errors based on the instructions that are provided in What do I do if errors occur when I use Logtail to collect logs?

Result

After data is collected, you can view the data in the Log Service console. For a request, you can view the data that is parsed by using the specified regular expression. You can also view the HTTP request method, requested URL, response time, status code, and request result.
"Index" : "7"  
"connection" : "1"  
"accepts" : "6079"  
"handled" : "6079"  
"requests" : "11596"  
"reading" : "0"  
"writing" : "1"  
"waiting" : "0"
"_method_" : "GET"  
"_address_" : "http://127.0.0.1/ngx_status"  
"_response_time_ms_" : "1.320"  
"_http_response_code_" : "200"  
"_result_" : "success"
By default, the following fields are uploaded for each request.
FieldDescription
_address_The request URL.
_method_The request method.
_response_time_ms_The response latency. Unit: milliseconds.
_http_response_code_The status code.
_result_The request result. Valid values: success, invalid_body, match_regex_invalid, mismatch, and timeout.
_response_match_Indicates whether the response body matches the value of the ResponseStringMatch field. If the ResponseStringMatch field does not exist, the value of _response_match_ is null. If the ResponseStringMatch field exists, the value of _response_match_ is yes or no.