Apache ShenYuThe gateway receives requests from the client, forwards them to the server, and returns the server results to the client. The gateway can record the details of each request,
The list includes: request time, request parameters, request path, response result, response status code, time consumption, upstream IP, exception information waiting. Shenyu gateway can record access logs through logging-elasticsearch-plugin and send access logs to elasticsearch database.
Core Module shenyu-plugin-logging-elasticsearch
Core Class org.apache.shenyu.plugin.logging.elasticsearch.LoggingElasticSearchPlugin
Core Class org.apache.shenyu.plugin.logging.elasticsearch.client.ElasticSearchLogCollectClient
pom.xml file.<!--shenyu logging-elasticsearch plugin start--> <dependency> <groupId>org.apache.shenyu</groupId> <artifactId>shenyu-spring-boot-starter-plugin-logging-elasticsearch</artifactId> <version>${project.version}</version> </dependency> <!--shenyu logging-elasticsearch plugin end-->
shenyu-admin --> Basic Configuration --> Plugin Management --> loggingElasticSearch, configure the ElasticSearch parameter and set it to on.| config-item | type | description | remarks |
|---|---|---|---|
| host | String | host name | must |
| port | String | port num | must |
| sampleRate | String | Sampling rate, range 0~1, 0: off, 0.01: acquisition 1%, 1: acquisition 100% | Optional, default 1, all collection |
| compressAlg | String | Compression algorithm, no compression by default, currently supports LZ4 compression | Optional, no compression by default |
| maxResponseBody | Ingeter | Maximum response size, above the threshold no response will be collected | Optional, default 512KB |
| maxRequestBody | Ingeter | Maximum request body size, above the threshold no request body will be collected | Optional, default 512KB |
| Except for host, port, all others are optional, in most cases only these 3 items need to be configured. |
For detailed configuration of selectors and rules, please refer to: Selector and rule management。 In addition sometimes a large gateway cluster corresponds to multiple applications (business), different applications (business) corresponds to different topics, related to isolation,
then you can configure different topics (optional) and sampling rate (optional) by selector, the meaning of the configuration items as shown in the table above.
The operation is shown below:
The fields of the captured access log are as follows.
| Field Name | Meaning | Description | Remarks |
|---|---|---|---|
| clientIp | Client IP | ||
| timeLocal | Request time string, format: yyyy-MM-dd HH:mm:ss.SSS | ||
| method | request method (different rpc type is not the same, http class for: get, post wait, rpc class for the interface name) | ||
| requestHeader | Request header (json format) | ||
| responseHeader | Response header (json format) | ||
| queryParams | Request query parameters | ||
| requestBody | Request Body (body of binary type will not be captured) | ||
| requestUri | Request uri | ||
| responseBody | Response body | ||
| responseContentLength | Response body size | ||
| rpcType | rpc type | ||
| status | response status | ||
| upstreamIp | Upstream (program providing the service) IP | ||
| upstreamResponseTime | Time taken by the upstream (program providing the service) to respond to the request (ms ms) | ||
| userAgent | Requested user agent | ||
| host | The requested host | ||
| module | Requested modules | ||
| path | The requested path | ||
| traceId | Requested Link Tracking ID | Need to access link tracking plugins, such as skywalking,zipkin |
Users need to deploy the ElasticSearch service to collect
bin directory, and double-click to execute elasticsearch.bat to start9200. Accesshttp://localhost:9200, verify successbin directory and execute the startup command on the terminal: ./elasticsearch9200. Access http://localhost:9200, verify successbin directory, and double-click to execute kibana.bat to start5601. Access http://localhost:5601, verify successbin directory and execute the startup command on the terminal: ./kibana5601. Access http://localhost:5601, verify successshenyu-access-logging indexshenyu-admin --> BasicConfig --> Plugin --> LoggingElasticSearch set Status disable.