muzea / portfwd

A low performance port forwarding implementation
https://muzea.github.io/portfwd
20 stars 4 forks source link

建议有数据请求时打日志 #8

Open j0hnnie opened 4 years ago

j0hnnie commented 4 years ago

因为portfwd是用来中转的,目前我的操作方式是:安装vnstat ,用vnstat -l查看流量是否有进出判断是否中转成功,如果可以在程序里记录中转进来的请求日志,想必是极好的。 我自己写了一个logrun.sh ,用来输出 portfwd的日志,内容如下:

[root@xxx portfwd]# cat logrun.sh 
#!/bin/bash
cd `dirname $0`
ulimit -n 512000
ps -ef|grep 'portfwd'
if [ $? -ne 0 ]
then
nohup ./portfwd >> ./portfwd.log 2>&1 &
fi
j0hnnie commented 4 years ago

例如可以是这样:

[GIN-debug] [WARNING] Running in "debug" mode. Switch to "release" mode in production.

[GIN-debug] GET /ping --> main.apiHandlePing (4 handlers) [GIN-debug] POST /proxy --> main.apiHandleProxyAdd (4 handlers) [GIN-debug] PATCH /proxy/:local --> main.apiHandleProxyUpdate (4 handlers) [GIN-debug] DELETE /proxy/:local --> main.apiHandleProxyDelete (4 handlers) [GIN-debug] GET /proxy --> main.apiHandleProxyList (4 handlers) [GIN-debug] GET /proxy/:local --> main.apiHandleProxyDetail (4 handlers) [GIN-debug] Listening and serving HTTP on :3001 2019/09/07 22:34:07 proxy 5001/8000 to 47.xxx.xxx.xxx:5001 2019/09/07 22:34:07 proxy 5000 to 47.xxx.xxx.xxx:5000 [GIN] 2019/09/07 - 22:34:27 | 200 | 122.897µs | 140.243.231.247 | GET /proxy/5000

[GIN] 2019/09/07 - 23:00:00 | 127.0.0.1 | 5000 
[GIN] 2019/09/07 - 23:00:00 | 127.0.0.2 | 5001
[GIN] 2019/09/07 - 23:00:00 | 127.0.0.1 | 5000 
[GIN] 2019/09/07 - 23:00:00 | 127.0.0.22 | 6000