当前位置: 首页 > news >正文

网关kong记录接口处理请求和响应插件 tcp-log-with-body的安装

tcp-log-with-body

介绍

Kong的tcp-log-with-body插件是一个高效的工具,它能够转发Kong处理的请求和响应。这个插件非常适用于需要详细记录API请求和响应信息的情景,尤其是在调试和排查问题时。

Kong的tcp-log-with-body插件

软件环境说明
  • kong version 2.1.4 - 2.8.3 [可用亲测]
  • CentOS version 7.3.1611
kong version --vv
2024/02/29 00:17:48 [verbose] Kong: 2.1.4
2024/02/29 00:17:48 [debug] ngx_lua: 10015
2024/02/29 00:17:48 [debug] nginx: 1015008
2024/02/29 00:17:48 [debug] Lua: LuaJIT 2.1.0-beta3
2.1.4cat /etc/centos-release
CentOS Linux release 7.3.1611 (Core) 
插件安装教程
  1. 找到 kong 插件存放位置
[root@bwg] - [/usr/local/share/lua/5.1/kong/plugins] - [2024-02-28 11:52:33]
└─[0] ls
acl              basic-auth      file-log      http-log-with-body  key-auth         post-function  request-size-limiting  session            udp-log
acme             bot-detection   grpc-gateway  http-mirror         ldap-auth        pre-function   request-termination    statsd             zipkin
aws-lambda       correlation-id  grpc-web      ip-restriction      loggly           prometheus     request-transformer    syslog
azure-functions  cors            hmac-auth     jwt                 log-serializers  proxy-cache    response-ratelimiting  tcp-log
base_plugin.lua  datadog         http-log      kafka-log           oauth2           rate-limiting  response-transformer   tcp-log-with-body
  1. git 克隆项目到plugins目录下
git clone https://gitee.com/XiongMingcai/tcp-log-with-body.git
  1. 修改kong配置文件 加入启用tcp-log-with-body 插件
vim /etc/kong/kong.conf

修改位置

plugins = bundled,tcp-log-with-body 
  1. 重启kong

监听启动错误日志

tail -f /usr/local/kong/logs/error.log 

重启kong

sudo systemctl restart kong
使用说明
  1. 配置tcp-log-with-body插件(见封面图)

  2. 接收日志tcp请求 node.js 模拟tcp-log-server

const net = require('net');
const {inspect} = require("util");// Create a server instance
const server = net.createServer((socket) => {socket.on('data', (data) => {// 将数据转换为字符串,并以JSON格式输出const dataString = data.toString('utf8');console.log("Received data:", inspect(JSON.parse(dataString), false, null, true));});socket.on('end', () => {});
});// Error callback
server.on('error', (err) => {console.error('Server error:', err);
});// Listening callback
server.listen(9999, '127.0.0.1', () => {console.log('Server is listening on 127.0.0.1:9999');
});
  1. 效果
.....request: {querystring: {},size: '563',uri: '/ok',url: 'https://ssl.hunangl.com:443/ok',headers: {host: 'ssl.hunangl.com',authorization: 'REDACTED','postman-token': 'a0cf800e-06ac-41b0-8a4d-d849c945cee1',accept: '*/*',digest: 'SHA-256=eji/gfOD9pQzrW6QDTWz4jhVk/dqe3q11DVbi6Qe4ks=','request-id': '5c54a71f-9bdb-445c-8549-f4af181ad49c','cache-control': 'no-cache','content-length': '13','accept-encoding': 'gzip, deflate, br','user-agent': 'PostmanRuntime/7.36.3','x-date': 'Thu, 29 Feb 2024 05:14:21 GMT',connection: 'keep-alive','content-type': 'application/json'},body: '{"foo":"bar"}',method: 'POST'},client_ip: '54.86.50.139',
.....
response: {body: '{"host":"0.0.0.0:8300","connection":"keep-alive","x-forwarded-for":"54.86.50.139","x-forwarded-proto":"https","x-forwarded-host":"ssl.hunangl.com","x-forwarded-port":"443","x-real-ip":"54.86.50.139","content-length":"13","x-date":"Thu, 29 Feb 2024 05:14:21 GMT","authorization":"hmac username=\\"hmac_username\\", algorithm=\\"hmac-sha256\\", headers=\\"x-date request-line digest\\", signature=\\"Kh+sGhrL3NbFNa9dsLdTs/q6hMBublOEPYUw4j8rLGM=\\"","digest":"SHA-256=eji/gfOD9pQzrW6QDTWz4jhVk/dqe3q11DVbi6Qe4ks=","content-type":"application/json","user-agent":"PostmanRuntime/7.36.3","accept":"*/*","cache-control":"no-cache","postman-token":"a0cf800e-06ac-41b0-8a4d-d849c945cee1","accept-encoding":"gzip, deflate, br","request-id":"5c54a71f-9bdb-445c-8549-f4af181ad49c"}',headers: {'content-type': 'application/json; charset=utf-8',date: 'Thu, 29 Feb 2024 05:14:15 GMT',connection: 'close','server-port': '8300','request-ip': '54.86.50.139','content-length': '761',via: 'kong/2.1.4','x-kong-proxy-latency': '6','x-kong-upstream-latency': '12','request-id': '5c54a71f-9bdb-445c-8549-f4af181ad49c'},status: 200,size: '1075'},
.....
http://www.lryc.cn/news/308368.html

相关文章:

  • ElasticSearch之Completion Suggester
  • ant 布局组件 组件等高设置
  • 不可多得的干货,网易的朋友给我这份339页的Android面经
  • Qt项目:网络1
  • 软件测试有哪些常用的测试方法?
  • 【C语言基础】:深入理解指针(一)
  • 单点故障解决方案之Smart Link与Monitor Link
  • QT之QSharedMemory共享内存
  • string 类 经典习题之数字字符相加
  • 通讯录——C语言实现
  • 优思学院|3步骤计算出Cpk|学习Minitab
  • 【Java编程进阶之路 06】深入探索:JDK、JRE与JVM的关系与差异
  • Linux中的touch命令
  • 智能驾驶规划控制理论学习-基于采样的规划方法
  • 二叉树——二叉树所有路径
  • 算法训练营day38(补),动态规划6
  • 【java、微服务、nacos】nacos服务分级存储模型
  • 共享旅游卡:打开0费用旅游新纪元,探索40+精彩线路
  • MQTT协议解析:揭秘固定报头、可变报头与有效载荷的奥秘
  • 备战蓝桥杯---树形DP基础3
  • IEEE Transactions on Industrial Electronics工业电子TIE修改稿注意事项及提交须知
  • c#委托的三种实现方式
  • c/c++|红黑树|分析应用|锚点
  • 2-29算法习题总结
  • 当Linux 磁盘满了,查看大文件并删除
  • STL -萃取特性迭代器
  • python pandas写入csv
  • oracle 数据库建集群式数据库的DBLINK的语法
  • 基于JAVA的毕业设计分配选题系统 开源项目
  • Android 接入指纹识别