Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
763a72d526 | ||
|
|
bd762ad10b | ||
|
|
56574ea3d9 | ||
|
|
6a31605519 | ||
|
|
c7abeeaf07 | ||
|
|
c11483ec6d | ||
|
|
c3713cefc9 | ||
|
|
2098bd4d32 | ||
|
|
7a6a02284e | ||
|
|
c749a7b088 |
@@ -28,6 +28,14 @@ func main() {
|
|||||||
fmt.Println("[ERROR]" + err.Error())
|
fmt.Println("[ERROR]" + err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
prettyResultsJSON, err := json.MarshalIndent(results, "", " ")
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("[ERROR]" + err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 写入到 sql.go 中
|
||||||
dir, _ := os.Getwd()
|
dir, _ := os.Getwd()
|
||||||
var sqlFile string
|
var sqlFile string
|
||||||
for i := 0; i < 5; i++ {
|
for i := 0; i < 5; i++ {
|
||||||
@@ -71,5 +79,13 @@ func init() {
|
|||||||
fmt.Println("[ERROR]write file failed: " + err.Error())
|
fmt.Println("[ERROR]write file failed: " + err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 写入到 sql.json 中
|
||||||
|
err = os.WriteFile(dir+"/internal/setup/sql.json", prettyResultsJSON, 0666)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("[ERROR]" + err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
fmt.Println("ok")
|
fmt.Println("ok")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package teaconst
|
package teaconst
|
||||||
|
|
||||||
const (
|
const (
|
||||||
Version = "0.6.4"
|
Version = "0.6.4.2"
|
||||||
|
|
||||||
ProductName = "Edge API"
|
ProductName = "Edge API"
|
||||||
ProcessName = "edge-api"
|
ProcessName = "edge-api"
|
||||||
@@ -18,7 +18,7 @@ const (
|
|||||||
|
|
||||||
// 其他节点版本号,用来检测是否有需要升级的节点
|
// 其他节点版本号,用来检测是否有需要升级的节点
|
||||||
|
|
||||||
NodeVersion = "0.6.4"
|
NodeVersion = "0.6.4.2"
|
||||||
|
|
||||||
// SQLVersion SQL版本号
|
// SQLVersion SQL版本号
|
||||||
SQLVersion = "11"
|
SQLVersion = "11"
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"github.com/iwind/TeaGo/rands"
|
"github.com/iwind/TeaGo/rands"
|
||||||
"github.com/iwind/TeaGo/types"
|
"github.com/iwind/TeaGo/types"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -16,4 +18,17 @@ var (
|
|||||||
NodeId int64 = 0
|
NodeId int64 = 0
|
||||||
Debug = false
|
Debug = false
|
||||||
InstanceCode = fmt.Sprintf("%x", sha1.Sum([]byte("INSTANCE"+types.String(time.Now().UnixNano())+"@"+types.String(rands.Int64()))))
|
InstanceCode = fmt.Sprintf("%x", sha1.Sum([]byte("INSTANCE"+types.String(time.Now().UnixNano())+"@"+types.String(rands.Int64()))))
|
||||||
|
IsMain = checkMain()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// 检查是否为主程序
|
||||||
|
func checkMain() bool {
|
||||||
|
if len(os.Args) == 1 ||
|
||||||
|
(len(os.Args) >= 2 && os.Args[1] == "pprof") {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
exe, _ := os.Executable()
|
||||||
|
return strings.HasSuffix(exe, ".test") ||
|
||||||
|
strings.HasSuffix(exe, ".test.exe") ||
|
||||||
|
strings.Contains(exe, "___")
|
||||||
|
}
|
||||||
|
|||||||
@@ -435,6 +435,16 @@ func (this *NodeDAO) ListEnabledNodesMatch(tx *dbs.Tx,
|
|||||||
valueField = "load1m"
|
valueField = "load1m"
|
||||||
isAsc = false
|
isAsc = false
|
||||||
ifNullValue = -1
|
ifNullValue = -1
|
||||||
|
case "connectionsAsc":
|
||||||
|
valueItem = "connections"
|
||||||
|
valueField = "total"
|
||||||
|
isAsc = true
|
||||||
|
ifNullValue = 1000
|
||||||
|
case "connectionsDesc":
|
||||||
|
valueItem = "connections"
|
||||||
|
valueField = "total"
|
||||||
|
isAsc = false
|
||||||
|
ifNullValue = -1
|
||||||
default:
|
default:
|
||||||
query.Desc("level")
|
query.Desc("level")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -114,6 +114,20 @@ func (this *NodeClusterTrafficDailyStatDAO) FindDailyStats(tx *dbs.Tx, clusterId
|
|||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SumDailyStat 计算当月总流量
|
||||||
|
func (this *NodeClusterTrafficDailyStatDAO) SumDailyStat(tx *dbs.Tx, clusterId int64, dayFrom string, dayTo string) (*NodeClusterTrafficDailyStat, error) {
|
||||||
|
one, err := this.Query(tx).
|
||||||
|
Result("SUM(bytes) AS bytes", "SUM(cachedBytes) AS cachedBytes", "SUM(countRequests) AS countRequests", "SUM(countCachedRequests) AS countCachedRequests", "SUM(countAttackRequests) AS countAttackRequests", "SUM(attackBytes) AS attackBytes").
|
||||||
|
Attr("clusterId", clusterId).
|
||||||
|
Between("day", dayFrom, dayTo).
|
||||||
|
Find()
|
||||||
|
if err != nil || one == nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return one.(*NodeClusterTrafficDailyStat), nil
|
||||||
|
}
|
||||||
|
|
||||||
// Clean 清理历史数据
|
// Clean 清理历史数据
|
||||||
func (this *NodeClusterTrafficDailyStatDAO) Clean(tx *dbs.Tx, days int) error {
|
func (this *NodeClusterTrafficDailyStatDAO) Clean(tx *dbs.Tx, days int) error {
|
||||||
var day = timeutil.Format("Ymd", time.Now().AddDate(0, 0, -days))
|
var day = timeutil.Format("Ymd", time.Now().AddDate(0, 0, -days))
|
||||||
|
|||||||
@@ -117,6 +117,21 @@ func (this *NodeTrafficDailyStatDAO) FindDailyStats(tx *dbs.Tx, role string, nod
|
|||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SumDailyStat 计算日期之间的总和
|
||||||
|
func (this *NodeTrafficDailyStatDAO) SumDailyStat(tx *dbs.Tx, role string, nodeId int64, dayFrom string, dayTo string) (*NodeTrafficDailyStat, error) {
|
||||||
|
one, err := this.Query(tx).
|
||||||
|
Result("SUM(bytes) AS bytes", "SUM(cachedBytes) AS cachedBytes", "SUM(countRequests) AS countRequests", "SUM(countCachedRequests) AS countCachedRequests", "SUM(countAttackRequests) AS countAttackRequests", "SUM(attackBytes) AS attackBytes").
|
||||||
|
Attr("nodeId", nodeId).
|
||||||
|
Attr("role", role).
|
||||||
|
Between("day", dayFrom, dayTo).
|
||||||
|
Find()
|
||||||
|
if err != nil || one == nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return one.(*NodeTrafficDailyStat), nil
|
||||||
|
}
|
||||||
|
|
||||||
// Clean 清理历史数据
|
// Clean 清理历史数据
|
||||||
func (this *NodeTrafficDailyStatDAO) Clean(tx *dbs.Tx, days int) error {
|
func (this *NodeTrafficDailyStatDAO) Clean(tx *dbs.Tx, days int) error {
|
||||||
var day = timeutil.Format("Ymd", time.Now().AddDate(0, 0, -days))
|
var day = timeutil.Format("Ymd", time.Now().AddDate(0, 0, -days))
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ var sharedDAO DAOInterface
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
// 定期上传日志
|
// 定期上传日志
|
||||||
ticker := time.NewTicker(60 * time.Second)
|
var ticker = time.NewTicker(60 * time.Second)
|
||||||
goman.New(func() {
|
goman.New(func() {
|
||||||
for range ticker.C {
|
for range ticker.C {
|
||||||
err := uploadLogs()
|
err := uploadLogs()
|
||||||
|
|||||||
@@ -109,7 +109,7 @@ func (this *BaseService) ValidateAuthorityNode(ctx context.Context) (nodeId int6
|
|||||||
func (this *BaseService) ValidateNodeId(ctx context.Context, roles ...rpcutils.UserType) (role rpcutils.UserType, nodeIntId int64, err error) {
|
func (this *BaseService) ValidateNodeId(ctx context.Context, roles ...rpcutils.UserType) (role rpcutils.UserType, nodeIntId int64, err error) {
|
||||||
// 默认包含大部分节点
|
// 默认包含大部分节点
|
||||||
if len(roles) == 0 {
|
if len(roles) == 0 {
|
||||||
roles = []rpcutils.UserType{rpcutils.UserTypeNode, rpcutils.UserTypeCluster, rpcutils.UserTypeAdmin, rpcutils.UserTypeUser, rpcutils.UserTypeDNS, rpcutils.UserTypeReport, rpcutils.UserTypeMonitor, rpcutils.UserTypeLog}
|
roles = []rpcutils.UserType{rpcutils.UserTypeNode, rpcutils.UserTypeCluster, rpcutils.UserTypeAdmin, rpcutils.UserTypeUser, rpcutils.UserTypeDNS, rpcutils.UserTypeReport, rpcutils.UserTypeMonitor, rpcutils.UserTypeLog, rpcutils.UserTypeAPI}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ctx == nil {
|
if ctx == nil {
|
||||||
|
|||||||
@@ -225,6 +225,10 @@ func (this *NodeService) ListEnabledNodesMatch(ctx context.Context, req *pb.List
|
|||||||
order = "loadAsc"
|
order = "loadAsc"
|
||||||
} else if req.LoadDesc {
|
} else if req.LoadDesc {
|
||||||
order = "loadDesc"
|
order = "loadDesc"
|
||||||
|
} else if req.ConnectionsAsc {
|
||||||
|
order = "connectionsAsc"
|
||||||
|
} else if req.ConnectionsDesc {
|
||||||
|
order = "connectionsDesc"
|
||||||
}
|
}
|
||||||
|
|
||||||
nodes, err := models.SharedNodeDAO.ListEnabledNodesMatch(tx, req.NodeClusterId, configutils.ToBoolState(req.InstallState), configutils.ToBoolState(req.ActiveState), req.Keyword, req.NodeGroupId, req.NodeRegionId, req.Level, true, order, req.Offset, req.Size)
|
nodes, err := models.SharedNodeDAO.ListEnabledNodesMatch(tx, req.NodeClusterId, configutils.ToBoolState(req.InstallState), configutils.ToBoolState(req.ActiveState), req.Keyword, req.NodeGroupId, req.NodeRegionId, req.Level, true, order, req.Offset, req.Size)
|
||||||
|
|||||||
@@ -85,13 +85,30 @@ func (this *ServerStatBoardService) ComposeServerStatNodeClusterBoard(ctx contex
|
|||||||
}
|
}
|
||||||
result.CountServers = countServers
|
result.CountServers = countServers
|
||||||
|
|
||||||
|
// 当月总流量
|
||||||
|
monthlyTrafficStat, err := stats.SharedNodeClusterTrafficDailyStatDAO.SumDailyStat(tx, req.NodeClusterId, timeutil.Format("Ym01"), timeutil.Format("Ym31"))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if monthlyTrafficStat != nil {
|
||||||
|
result.MonthlyTrafficBytes = int64(monthlyTrafficStat.Bytes)
|
||||||
|
}
|
||||||
|
|
||||||
// 按日流量统计
|
// 按日流量统计
|
||||||
var dayFrom = timeutil.Format("Ymd", time.Now().AddDate(0, 0, -14))
|
var dayFrom = timeutil.Format("Ymd", time.Now().AddDate(0, 0, -14))
|
||||||
dailyTrafficStats, err := stats.SharedNodeClusterTrafficDailyStatDAO.FindDailyStats(tx, req.NodeClusterId, dayFrom, timeutil.Format("Ymd"))
|
dailyTrafficStats, err := stats.SharedNodeClusterTrafficDailyStatDAO.FindDailyStats(tx, req.NodeClusterId, dayFrom, timeutil.Format("Ymd"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
var dailyTrafficBytes int64
|
||||||
|
var lastDailyTrafficBytes int64
|
||||||
for _, stat := range dailyTrafficStats {
|
for _, stat := range dailyTrafficStats {
|
||||||
|
if stat.Day == timeutil.Format("Ymd") { // 今天
|
||||||
|
dailyTrafficBytes = int64(stat.Bytes)
|
||||||
|
} else if stat.Day == timeutil.Format("Ymd", time.Now().AddDate(0, 0, -1)) {
|
||||||
|
lastDailyTrafficBytes = int64(stat.Bytes)
|
||||||
|
}
|
||||||
|
|
||||||
result.DailyTrafficStats = append(result.DailyTrafficStats, &pb.ComposeServerStatNodeClusterBoardResponse_DailyTrafficStat{
|
result.DailyTrafficStats = append(result.DailyTrafficStats, &pb.ComposeServerStatNodeClusterBoardResponse_DailyTrafficStat{
|
||||||
Day: stat.Day,
|
Day: stat.Day,
|
||||||
Bytes: int64(stat.Bytes),
|
Bytes: int64(stat.Bytes),
|
||||||
@@ -102,6 +119,8 @@ func (this *ServerStatBoardService) ComposeServerStatNodeClusterBoard(ctx contex
|
|||||||
AttackBytes: int64(stat.AttackBytes),
|
AttackBytes: int64(stat.AttackBytes),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
result.DailyTrafficBytes = dailyTrafficBytes
|
||||||
|
result.LastDailyTrafficBytes = lastDailyTrafficBytes
|
||||||
|
|
||||||
// 小时流量统计
|
// 小时流量统计
|
||||||
var hourFrom = timeutil.Format("YmdH", time.Now().Add(-23*time.Hour))
|
var hourFrom = timeutil.Format("YmdH", time.Now().Add(-23*time.Hour))
|
||||||
@@ -305,13 +324,30 @@ func (this *ServerStatBoardService) ComposeServerStatNodeBoard(ctx context.Conte
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 当月总流量
|
||||||
|
monthlyTrafficStat, err := stats.SharedNodeTrafficDailyStatDAO.SumDailyStat(tx, nodeconfigs.NodeRoleNode, req.NodeId, timeutil.Format("Ym01"), timeutil.Format("Ym31"))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if monthlyTrafficStat != nil {
|
||||||
|
result.MonthlyTrafficBytes = int64(monthlyTrafficStat.Bytes)
|
||||||
|
}
|
||||||
|
|
||||||
// 按日流量统计
|
// 按日流量统计
|
||||||
var dayFrom = timeutil.Format("Ymd", time.Now().AddDate(0, 0, -14))
|
var dayFrom = timeutil.Format("Ymd", time.Now().AddDate(0, 0, -14))
|
||||||
dailyTrafficStats, err := stats.SharedNodeTrafficDailyStatDAO.FindDailyStats(tx, "node", req.NodeId, dayFrom, timeutil.Format("Ymd"))
|
dailyTrafficStats, err := stats.SharedNodeTrafficDailyStatDAO.FindDailyStats(tx, "node", req.NodeId, dayFrom, timeutil.Format("Ymd"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
var dailyTrafficBytes int64
|
||||||
|
var lastDailyTrafficBytes int64
|
||||||
for _, stat := range dailyTrafficStats {
|
for _, stat := range dailyTrafficStats {
|
||||||
|
if stat.Day == timeutil.Format("Ymd") { // 当天
|
||||||
|
dailyTrafficBytes = int64(stat.Bytes)
|
||||||
|
} else if stat.Day == timeutil.Format("Ymd", time.Now().AddDate(0, 0, -1)) { // 昨天
|
||||||
|
lastDailyTrafficBytes = int64(stat.Bytes)
|
||||||
|
}
|
||||||
|
|
||||||
result.DailyTrafficStats = append(result.DailyTrafficStats, &pb.ComposeServerStatNodeBoardResponse_DailyTrafficStat{
|
result.DailyTrafficStats = append(result.DailyTrafficStats, &pb.ComposeServerStatNodeBoardResponse_DailyTrafficStat{
|
||||||
Day: stat.Day,
|
Day: stat.Day,
|
||||||
Bytes: int64(stat.Bytes),
|
Bytes: int64(stat.Bytes),
|
||||||
@@ -322,6 +358,8 @@ func (this *ServerStatBoardService) ComposeServerStatNodeBoard(ctx context.Conte
|
|||||||
AttackBytes: int64(stat.AttackBytes),
|
AttackBytes: int64(stat.AttackBytes),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
result.DailyTrafficBytes = dailyTrafficBytes
|
||||||
|
result.LastDailyTrafficBytes = lastDailyTrafficBytes
|
||||||
|
|
||||||
// 小时流量统计
|
// 小时流量统计
|
||||||
var hourFrom = timeutil.Format("YmdH", time.Now().Add(-23*time.Hour))
|
var hourFrom = timeutil.Format("YmdH", time.Now().Add(-23*time.Hour))
|
||||||
|
|||||||
189185
internal/setup/sql.json
Normal file
189185
internal/setup/sql.json
Normal file
File diff suppressed because it is too large
Load Diff
@@ -6,6 +6,7 @@ import (
|
|||||||
"github.com/go-sql-driver/mysql"
|
"github.com/go-sql-driver/mysql"
|
||||||
"github.com/iwind/TeaGo/dbs"
|
"github.com/iwind/TeaGo/dbs"
|
||||||
"github.com/iwind/TeaGo/lists"
|
"github.com/iwind/TeaGo/lists"
|
||||||
|
"github.com/iwind/TeaGo/maps"
|
||||||
"github.com/iwind/TeaGo/types"
|
"github.com/iwind/TeaGo/types"
|
||||||
"io"
|
"io"
|
||||||
"regexp"
|
"regexp"
|
||||||
@@ -57,6 +58,7 @@ var recordsTables = []*SQLRecordsTable{
|
|||||||
{
|
{
|
||||||
TableName: "edgeClientAgentIPs",
|
TableName: "edgeClientAgentIPs",
|
||||||
UniqueFields: []string{"agentId", "ip"},
|
UniqueFields: []string{"agentId", "ip"},
|
||||||
|
IgnoreId: true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -374,6 +376,7 @@ func (this *SQLDump) applyQueue(db *dbs.DB, newResult *SQLDumpResult, showLog bo
|
|||||||
|
|
||||||
// 对比记录
|
// 对比记录
|
||||||
// +
|
// +
|
||||||
|
var newRecordsTable = this.findRecordsTable(newTable.Name)
|
||||||
for _, record := range newTable.Records {
|
for _, record := range newTable.Records {
|
||||||
var queryArgs = []string{}
|
var queryArgs = []string{}
|
||||||
var queryValues = []any{}
|
var queryValues = []any{}
|
||||||
@@ -392,8 +395,15 @@ func (this *SQLDump) applyQueue(db *dbs.DB, newResult *SQLDumpResult, showLog bo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
queryValues = append(queryValues, recordId)
|
var one maps.Map
|
||||||
one, err := db.FindOne("SELECT * FROM "+newTable.Name+" WHERE (("+strings.Join(queryArgs, " AND ")+") OR id=?)", queryValues...)
|
|
||||||
|
if newRecordsTable != nil && newRecordsTable.IgnoreId {
|
||||||
|
one, err = db.FindOne("SELECT * FROM "+newTable.Name+" WHERE (("+strings.Join(queryArgs, " AND ")+"))", queryValues...)
|
||||||
|
} else {
|
||||||
|
queryValues = append(queryValues, recordId)
|
||||||
|
one, err = db.FindOne("SELECT * FROM "+newTable.Name+" WHERE (("+strings.Join(queryArgs, " AND ")+") OR id=?)", queryValues...)
|
||||||
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -411,7 +421,10 @@ func (this *SQLDump) applyQueue(db *dbs.DB, newResult *SQLDumpResult, showLog bo
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// ID需要保留,因为各个表格之间需要有对应关系
|
if newRecordsTable != nil && newRecordsTable.IgnoreId && k == "id" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
params = append(params, "`"+k+"`")
|
params = append(params, "`"+k+"`")
|
||||||
args = append(args, "?")
|
args = append(args, "?")
|
||||||
values = append(values, v)
|
values = append(values, v)
|
||||||
|
|||||||
@@ -4,4 +4,5 @@ type SQLRecordsTable struct {
|
|||||||
TableName string
|
TableName string
|
||||||
UniqueFields []string
|
UniqueFields []string
|
||||||
ExceptFields []string
|
ExceptFields []string
|
||||||
|
IgnoreId bool // 是否可以排除ID
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user