mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-11-11 22:00:25 +08:00
优化服务日志
This commit is contained in:
@@ -40,7 +40,7 @@ func (this *HTTPRequest) doReverseProxy() {
|
|||||||
requestCall.CallResponseCallbacks(this.writer)
|
requestCall.CallResponseCallbacks(this.writer)
|
||||||
if origin == nil {
|
if origin == nil {
|
||||||
err := errors.New(this.requestFullURL() + ": no available origin sites for reverse proxy")
|
err := errors.New(this.requestFullURL() + ": no available origin sites for reverse proxy")
|
||||||
remotelogs.ServerError(this.Server.Id, "HTTP_REQUEST_REVERSE_PROXY", err.Error())
|
remotelogs.ServerError(this.Server.Id, "HTTP_REQUEST_REVERSE_PROXY", err.Error(), "", nil)
|
||||||
this.write50x(err, http.StatusBadGateway)
|
this.write50x(err, http.StatusBadGateway)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -137,7 +137,7 @@ func (this *BaseListener) matchSSL(domain string) (*sslconfigs.SSLPolicy, *tls.C
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(sslConfig.Certs) == 0 {
|
if len(sslConfig.Certs) == 0 {
|
||||||
remotelogs.ServerError(server.Id, "BASE_LISTENER", "no ssl certs found for '"+domain+"', server id: "+types.String(server.Id))
|
remotelogs.ServerError(server.Id, "BASE_LISTENER", "no ssl certs found for '"+domain+"', server id: "+types.String(server.Id), "", nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
return sslConfig, sslConfig.FirstCert(), nil
|
return sslConfig, sslConfig.FirstCert(), nil
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
"github.com/TeaOSLab/EdgeNode/internal/remotelogs"
|
"github.com/TeaOSLab/EdgeNode/internal/remotelogs"
|
||||||
"github.com/iwind/TeaGo/Tea"
|
"github.com/iwind/TeaGo/Tea"
|
||||||
"github.com/iwind/TeaGo/lists"
|
"github.com/iwind/TeaGo/lists"
|
||||||
|
"github.com/iwind/TeaGo/maps"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"regexp"
|
"regexp"
|
||||||
@@ -123,20 +124,19 @@ func (this *ListenerManager) Start(node *nodeconfigs.NodeConfig) error {
|
|||||||
portIndex := strings.LastIndex(addr, ":")
|
portIndex := strings.LastIndex(addr, ":")
|
||||||
if portIndex > 0 {
|
if portIndex > 0 {
|
||||||
var port = addr[portIndex+1:]
|
var port = addr[portIndex+1:]
|
||||||
var processName = this.findProcessNameWithPort(port)
|
var processName = this.findProcessNameWithPort(group.IsUDP(), port)
|
||||||
if len(processName) > 0 {
|
if len(processName) > 0 {
|
||||||
err = errors.New(err.Error() + " (the process using port: '" + processName + "')")
|
err = errors.New(err.Error() + " (the process using port: '" + processName + "')")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
remotelogs.ServerError(firstServer.Id, "LISTENER_MANAGER", err.Error())
|
remotelogs.ServerError(firstServer.Id, "LISTENER_MANAGER", "listen '"+addr+"' failed: "+err.Error(), nodeconfigs.NodeLogTypeListenAddressFailed, maps.Map{"address": addr})
|
||||||
}
|
}
|
||||||
|
|
||||||
continue
|
continue
|
||||||
} else {
|
} else {
|
||||||
// TODO 是否是从错误中恢复
|
// TODO 是否是从错误中恢复
|
||||||
|
|
||||||
}
|
}
|
||||||
this.listenersMap[addr] = listener
|
this.listenersMap[addr] = listener
|
||||||
}
|
}
|
||||||
@@ -179,14 +179,12 @@ func (this *ListenerManager) retryListeners() {
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
delete(this.retryListenerMap, addr)
|
delete(this.retryListenerMap, addr)
|
||||||
this.listenersMap[addr] = listener
|
this.listenersMap[addr] = listener
|
||||||
remotelogs.ServerSuccess(listener.group.FirstServer().Id, "LISTENER_MANAGER", "retry to listen '"+addr+"' successfully")
|
remotelogs.ServerSuccess(listener.group.FirstServer().Id, "LISTENER_MANAGER", "retry to listen '"+addr+"' successfully", nodeconfigs.NodeLogTypeListenAddressFailed, maps.Map{"address": addr})
|
||||||
|
|
||||||
// TODO 删除失败记录
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *ListenerManager) findProcessNameWithPort(port string) string {
|
func (this *ListenerManager) findProcessNameWithPort(isUdp bool, port string) string {
|
||||||
if runtime.GOOS != "linux" {
|
if runtime.GOOS != "linux" {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
@@ -196,7 +194,12 @@ func (this *ListenerManager) findProcessNameWithPort(port string) string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
var cmd = exec.Command(path, "-tlpn", "sport = :"+port)
|
var option = "t"
|
||||||
|
if isUdp {
|
||||||
|
option = "u"
|
||||||
|
}
|
||||||
|
|
||||||
|
var cmd = exec.Command(path, "-"+option+"lpn", "sport = :"+port)
|
||||||
var output = &bytes.Buffer{}
|
var output = &bytes.Buffer{}
|
||||||
cmd.Stdout = output
|
cmd.Stdout = output
|
||||||
err = cmd.Run()
|
err = cmd.Run()
|
||||||
|
|||||||
@@ -177,7 +177,7 @@ func (this *TCPListener) connectOrigin(serverId int64, reverseProxy *serverconfi
|
|||||||
}
|
}
|
||||||
conn, err = OriginConnect(origin, remoteAddr)
|
conn, err = OriginConnect(origin, remoteAddr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
remotelogs.ServerError(serverId, "TCP_LISTENER", "unable to connect origin: "+origin.Addr.Host+":"+origin.Addr.PortRange+": "+err.Error())
|
remotelogs.ServerError(serverId, "TCP_LISTENER", "unable to connect origin: "+origin.Addr.Host+":"+origin.Addr.PortRange+": "+err.Error(), "", nil)
|
||||||
continue
|
continue
|
||||||
} else {
|
} else {
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -114,7 +114,7 @@ func (this *UDPListener) connectOrigin(serverId int64, reverseProxy *serverconfi
|
|||||||
}
|
}
|
||||||
conn, err = OriginConnect(origin, remoteAddr.String())
|
conn, err = OriginConnect(origin, remoteAddr.String())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
remotelogs.ServerError(serverId, "UDP_LISTENER", "unable to connect origin: "+origin.Addr.Host+":"+origin.Addr.PortRange+": "+err.Error())
|
remotelogs.ServerError(serverId, "UDP_LISTENER", "unable to connect origin: "+origin.Addr.Host+":"+origin.Addr.PortRange+": "+err.Error(), "", nil)
|
||||||
continue
|
continue
|
||||||
} else {
|
} else {
|
||||||
// PROXY Protocol
|
// PROXY Protocol
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package remotelogs
|
package remotelogs
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
|
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
teaconst "github.com/TeaOSLab/EdgeNode/internal/const"
|
teaconst "github.com/TeaOSLab/EdgeNode/internal/const"
|
||||||
@@ -8,6 +9,7 @@ import (
|
|||||||
"github.com/TeaOSLab/EdgeNode/internal/trackers"
|
"github.com/TeaOSLab/EdgeNode/internal/trackers"
|
||||||
"github.com/cespare/xxhash"
|
"github.com/cespare/xxhash"
|
||||||
"github.com/iwind/TeaGo/logs"
|
"github.com/iwind/TeaGo/logs"
|
||||||
|
"github.com/iwind/TeaGo/maps"
|
||||||
"github.com/iwind/TeaGo/types"
|
"github.com/iwind/TeaGo/types"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@@ -33,18 +35,13 @@ func init() {
|
|||||||
func Println(tag string, description string) {
|
func Println(tag string, description string) {
|
||||||
logs.Println("[" + tag + "]" + description)
|
logs.Println("[" + tag + "]" + description)
|
||||||
|
|
||||||
nodeConfig, _ := nodeconfigs.SharedNodeConfig()
|
|
||||||
if nodeConfig == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case logChan <- &pb.NodeLog{
|
case logChan <- &pb.NodeLog{
|
||||||
Role: teaconst.Role,
|
Role: teaconst.Role,
|
||||||
Tag: tag,
|
Tag: tag,
|
||||||
Description: description,
|
Description: description,
|
||||||
Level: "info",
|
Level: "info",
|
||||||
NodeId: nodeConfig.Id,
|
NodeId: teaconst.NodeId,
|
||||||
CreatedAt: time.Now().Unix(),
|
CreatedAt: time.Now().Unix(),
|
||||||
}:
|
}:
|
||||||
default:
|
default:
|
||||||
@@ -56,18 +53,13 @@ func Println(tag string, description string) {
|
|||||||
func Warn(tag string, description string) {
|
func Warn(tag string, description string) {
|
||||||
logs.Println("[" + tag + "]" + description)
|
logs.Println("[" + tag + "]" + description)
|
||||||
|
|
||||||
nodeConfig, _ := nodeconfigs.SharedNodeConfig()
|
|
||||||
if nodeConfig == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case logChan <- &pb.NodeLog{
|
case logChan <- &pb.NodeLog{
|
||||||
Role: teaconst.Role,
|
Role: teaconst.Role,
|
||||||
Tag: tag,
|
Tag: tag,
|
||||||
Description: description,
|
Description: description,
|
||||||
Level: "warning",
|
Level: "warning",
|
||||||
NodeId: nodeConfig.Id,
|
NodeId: teaconst.NodeId,
|
||||||
CreatedAt: time.Now().Unix(),
|
CreatedAt: time.Now().Unix(),
|
||||||
}:
|
}:
|
||||||
default:
|
default:
|
||||||
@@ -79,18 +71,13 @@ func Warn(tag string, description string) {
|
|||||||
func Error(tag string, description string) {
|
func Error(tag string, description string) {
|
||||||
logs.Println("[" + tag + "]" + description)
|
logs.Println("[" + tag + "]" + description)
|
||||||
|
|
||||||
nodeConfig, _ := nodeconfigs.SharedNodeConfig()
|
|
||||||
if nodeConfig == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case logChan <- &pb.NodeLog{
|
case logChan <- &pb.NodeLog{
|
||||||
Role: teaconst.Role,
|
Role: teaconst.Role,
|
||||||
Tag: tag,
|
Tag: tag,
|
||||||
Description: description,
|
Description: description,
|
||||||
Level: "error",
|
Level: "error",
|
||||||
NodeId: nodeConfig.Id,
|
NodeId: teaconst.NodeId,
|
||||||
CreatedAt: time.Now().Unix(),
|
CreatedAt: time.Now().Unix(),
|
||||||
}:
|
}:
|
||||||
default:
|
default:
|
||||||
@@ -111,12 +98,18 @@ func ErrorObject(tag string, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ServerError 打印服务相关错误信息
|
// ServerError 打印服务相关错误信息
|
||||||
func ServerError(serverId int64, tag string, description string) {
|
func ServerError(serverId int64, tag string, description string, logType nodeconfigs.NodeLogType, params maps.Map) {
|
||||||
logs.Println("[" + tag + "]" + description)
|
logs.Println("[" + tag + "]" + description)
|
||||||
|
|
||||||
nodeConfig, _ := nodeconfigs.SharedNodeConfig()
|
// 参数
|
||||||
if nodeConfig == nil {
|
var paramsJSON []byte
|
||||||
return
|
if len(params) > 0 {
|
||||||
|
p, err := json.Marshal(params)
|
||||||
|
if err != nil {
|
||||||
|
logs.Println("[LOG]" + err.Error())
|
||||||
|
} else {
|
||||||
|
paramsJSON = p
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
select {
|
select {
|
||||||
@@ -125,9 +118,11 @@ func ServerError(serverId int64, tag string, description string) {
|
|||||||
Tag: tag,
|
Tag: tag,
|
||||||
Description: description,
|
Description: description,
|
||||||
Level: "error",
|
Level: "error",
|
||||||
NodeId: nodeConfig.Id,
|
NodeId: teaconst.NodeId,
|
||||||
ServerId: serverId,
|
ServerId: serverId,
|
||||||
CreatedAt: time.Now().Unix(),
|
CreatedAt: time.Now().Unix(),
|
||||||
|
Type: logType,
|
||||||
|
ParamsJSON: paramsJSON,
|
||||||
}:
|
}:
|
||||||
default:
|
default:
|
||||||
|
|
||||||
@@ -135,12 +130,18 @@ func ServerError(serverId int64, tag string, description string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ServerSuccess 打印服务相关成功信息
|
// ServerSuccess 打印服务相关成功信息
|
||||||
func ServerSuccess(serverId int64, tag string, description string) {
|
func ServerSuccess(serverId int64, tag string, description string, logType nodeconfigs.NodeLogType, params maps.Map) {
|
||||||
logs.Println("[" + tag + "]" + description)
|
logs.Println("[" + tag + "]" + description)
|
||||||
|
|
||||||
nodeConfig, _ := nodeconfigs.SharedNodeConfig()
|
// 参数
|
||||||
if nodeConfig == nil {
|
var paramsJSON []byte
|
||||||
return
|
if len(params) > 0 {
|
||||||
|
p, err := json.Marshal(params)
|
||||||
|
if err != nil {
|
||||||
|
logs.Println("[LOG]" + err.Error())
|
||||||
|
} else {
|
||||||
|
paramsJSON = p
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
select {
|
select {
|
||||||
@@ -149,9 +150,11 @@ func ServerSuccess(serverId int64, tag string, description string) {
|
|||||||
Tag: tag,
|
Tag: tag,
|
||||||
Description: description,
|
Description: description,
|
||||||
Level: "success",
|
Level: "success",
|
||||||
NodeId: nodeConfig.Id,
|
NodeId: teaconst.NodeId,
|
||||||
ServerId: serverId,
|
ServerId: serverId,
|
||||||
CreatedAt: time.Now().Unix(),
|
CreatedAt: time.Now().Unix(),
|
||||||
|
Type: logType,
|
||||||
|
ParamsJSON: paramsJSON,
|
||||||
}:
|
}:
|
||||||
default:
|
default:
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user