feat 接入Prometheus
This commit is contained in:
@@ -12,6 +12,13 @@ type LogConfig struct {
|
||||
Level string `yaml:"level"`
|
||||
}
|
||||
|
||||
type MonitorConfig struct {
|
||||
Prometheus *struct {
|
||||
Address string `yaml:"address"`
|
||||
Port int `yaml:"port"`
|
||||
} `yaml:"prometheus"`
|
||||
}
|
||||
|
||||
type DBConfig struct {
|
||||
Etcd *struct {
|
||||
Address []string `yaml:"address"`
|
||||
|
||||
33
Server/common/utils/gen_gorm_test.go
Normal file
33
Server/common/utils/gen_gorm_test.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"gorm.io/driver/mysql"
|
||||
"gorm.io/gen"
|
||||
"gorm.io/gorm"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestGenGormStruct(t *testing.T) {
|
||||
dsn := "user:password@tcp(47.108.184.184:3306)/point?charset=utf8mb4&parseTime=True&loc=Local"
|
||||
db, err := gorm.Open(mysql.Open(dsn))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
g := gen.NewGenerator(gen.Config{
|
||||
OutPath: "./model", // 生成的 model 文件路径
|
||||
})
|
||||
|
||||
g.UseDB(db)
|
||||
|
||||
// 生成所有表的 struct
|
||||
g.ApplyBasic(g.GenerateAllTable()...)
|
||||
|
||||
// 或者指定表
|
||||
// g.ApplyBasic(
|
||||
// g.GenerateModel("users"),
|
||||
// g.GenerateModel("orders"),
|
||||
// )
|
||||
|
||||
g.Execute()
|
||||
}
|
||||
41
Server/common/utils/workerpool.go
Normal file
41
Server/common/utils/workerpool.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"sync"
|
||||
)
|
||||
|
||||
// DefaultMaxWorkers 默认并发数
|
||||
const DefaultMaxWorkers = 32
|
||||
|
||||
// WorkerPool 并发执行一批任务。
|
||||
func WorkerPool(tasks []interface{}, taskFunc func(interface{}), maxWorkers ...int) {
|
||||
if len(tasks) == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
workers := DefaultMaxWorkers
|
||||
if len(maxWorkers) > 0 && maxWorkers[0] > 0 {
|
||||
workers = maxWorkers[0]
|
||||
}
|
||||
if workers > len(tasks) {
|
||||
workers = len(tasks)
|
||||
}
|
||||
|
||||
jobs := make(chan interface{}, len(tasks))
|
||||
var wg sync.WaitGroup
|
||||
for i := 0; i < workers; i++ {
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
for task := range jobs {
|
||||
taskFunc(task)
|
||||
}
|
||||
}()
|
||||
}
|
||||
for _, task := range tasks {
|
||||
jobs <- task
|
||||
}
|
||||
|
||||
close(jobs)
|
||||
wg.Wait()
|
||||
}
|
||||
Reference in New Issue
Block a user