2020-03-18 17:11:49 +08:00
|
|
|
|
<!--
|
|
|
|
|
#
|
|
|
|
|
# Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
|
# contributor license agreements. See the NOTICE file distributed with
|
|
|
|
|
# this work for additional information regarding copyright ownership.
|
|
|
|
|
# The ASF licenses this file to You under the Apache License, Version 2.0
|
|
|
|
|
# (the "License"); you may not use this file except in compliance with
|
|
|
|
|
# the License. You may obtain a copy of the License at
|
|
|
|
|
#
|
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
#
|
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
|
# limitations under the License.
|
|
|
|
|
#
|
|
|
|
|
-->
|
|
|
|
|
|
|
|
|
|
# 摘要
|
2020-05-22 14:43:20 +08:00
|
|
|
|
|
2020-03-18 17:11:49 +08:00
|
|
|
|
- [**定义**](#name)
|
|
|
|
|
- [**属性列表**](#attributes)
|
|
|
|
|
- [**如何开启**](#how-to-enable)
|
|
|
|
|
- [**测试插件**](#test-plugin)
|
|
|
|
|
- [**禁用插件**](#disable-plugin)
|
|
|
|
|
|
|
|
|
|
## 定义
|
|
|
|
|
|
|
|
|
|
`tcp-logger` 是用于将日志数据发送到TCP服务的插件。
|
|
|
|
|
|
|
|
|
|
以实现将日志数据以JSON格式发送到监控工具或其它TCP服务的能力。
|
|
|
|
|
|
2020-05-07 11:20:23 +08:00
|
|
|
|
该插件提供了将Log Data作为批处理推送到外部TCP服务器的功能。如果您没有收到日志数据,请放心一些时间,它会在我们的批处理处理器中的计时器功能到期后自动发送日志。
|
|
|
|
|
|
|
|
|
|
有关Apache APISIX中Batch-Processor的更多信息,请参考。
|
2020-06-19 12:03:55 +08:00
|
|
|
|
[Batch-Processor](../batch-processor.md)
|
2020-05-07 11:20:23 +08:00
|
|
|
|
|
2020-03-18 17:11:49 +08:00
|
|
|
|
## 属性列表
|
|
|
|
|
|
|
|
|
|
|属性名称 |必选项 |描述|
|
|
|
|
|
|--------- |--------|-----------|
|
|
|
|
|
| host |必要的| TCP 服务的IP地址或主机名。|
|
|
|
|
|
| port |必要的| 目标端口。|
|
|
|
|
|
| timeout |可选的|发送数据超时间。|
|
|
|
|
|
| tls |可选的|布尔值,用于控制是否执行SSL验证。|
|
|
|
|
|
| tls_options |可选的|TLS 选项|
|
|
|
|
|
|
|
|
|
|
## 如何开启
|
|
|
|
|
|
|
|
|
|
1. 下面例子展示了如何为指定路由开启 `tcp-logger` 插件的。
|
|
|
|
|
|
|
|
|
|
```shell
|
2020-04-29 21:43:38 +08:00
|
|
|
|
curl http://127.0.0.1:9080/apisix/admin/routes/5 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
|
2020-03-18 17:11:49 +08:00
|
|
|
|
{
|
2020-04-29 21:43:38 +08:00
|
|
|
|
"plugins": {
|
|
|
|
|
"tcp-logger": {
|
|
|
|
|
"host": "127.0.0.1",
|
|
|
|
|
"port": 5044,
|
|
|
|
|
"tls": false
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
"upstream": {
|
|
|
|
|
"type": "roundrobin",
|
|
|
|
|
"nodes": {
|
|
|
|
|
"127.0.0.1:1980": 1
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
"uri": "/hello"
|
2020-03-18 17:11:49 +08:00
|
|
|
|
}'
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## 测试插件
|
|
|
|
|
|
|
|
|
|
* 成功的情况:
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
$ curl -i http://127.0.0.1:9080/hello
|
|
|
|
|
HTTP/1.1 200 OK
|
|
|
|
|
...
|
|
|
|
|
hello, world
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## 禁用插件
|
|
|
|
|
|
|
|
|
|
想要禁用“tcp-logger”插件,是非常简单的,将对应的插件配置从json配置删除,就会立即生效,不需要重新启动服务:
|
|
|
|
|
|
|
|
|
|
```shell
|
2020-06-08 10:40:18 +08:00
|
|
|
|
$ curl http://127.0.0.1:2379/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d value='
|
2020-03-18 17:11:49 +08:00
|
|
|
|
{
|
|
|
|
|
"methods": ["GET"],
|
|
|
|
|
"uri": "/hello",
|
|
|
|
|
"plugins": {},
|
|
|
|
|
"upstream": {
|
|
|
|
|
"type": "roundrobin",
|
|
|
|
|
"nodes": {
|
|
|
|
|
"127.0.0.1:1980": 1
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}'
|
|
|
|
|
```
|