每隔5分钟输出一次当前总状态,close #210

This commit is contained in:
e1732a364fed
2000-01-01 00:00:00 +00:00
parent ef2ade8e49
commit 20ceda9f3b
3 changed files with 35 additions and 20 deletions

View File

@@ -54,32 +54,32 @@ func (asc *ApiServerConf) SetupFlags(fs *flag.FlagSet) {
}
// 若 acref 里有与默认值不同的项且字符串不为空, 将该项的值赋值给 asc
func (asc *ApiServerConf) SetUnDefault(acref *ApiServerConf) {
defaultAc := NewApiServerConf()
// 若 ref 里有与默认值不同的项且字符串不为空, 将该项的值赋值给 c
func (c *ApiServerConf) SetNonDefault(ref *ApiServerConf) {
d := NewApiServerConf()
var emptyAc ApiServerConf
if acref.PlainHttp != defaultAc.PlainHttp {
asc.PlainHttp = acref.PlainHttp
if ref.PlainHttp != d.PlainHttp {
c.PlainHttp = ref.PlainHttp
}
if acref.EnableApiServer != defaultAc.EnableApiServer {
asc.EnableApiServer = acref.EnableApiServer
if ref.EnableApiServer != d.EnableApiServer {
c.EnableApiServer = ref.EnableApiServer
}
if acref.Addr != defaultAc.Addr && acref.Addr != emptyAc.Addr {
asc.Addr = acref.Addr
if ref.Addr != d.Addr && ref.Addr != emptyAc.Addr {
c.Addr = ref.Addr
}
if acref.AdminPass != defaultAc.AdminPass {
asc.AdminPass = acref.AdminPass
if ref.AdminPass != d.AdminPass {
c.AdminPass = ref.AdminPass
}
if acref.PathPrefix != defaultAc.PathPrefix && acref.PathPrefix != emptyAc.PathPrefix {
asc.PathPrefix = acref.PathPrefix
if ref.PathPrefix != d.PathPrefix && ref.PathPrefix != emptyAc.PathPrefix {
c.PathPrefix = ref.PathPrefix
}
if acref.CertFile != defaultAc.CertFile {
asc.CertFile = acref.CertFile
if ref.CertFile != d.CertFile {
c.CertFile = ref.CertFile
}
if acref.KeyFile != defaultAc.KeyFile {
asc.KeyFile = acref.KeyFile
if ref.KeyFile != d.KeyFile {
c.KeyFile = ref.KeyFile
}
}

View File

@@ -129,7 +129,6 @@ func (ac *AppConf) Setup() {
}
func (m *M) LoadConfigByTomlBytes(bs []byte) (err error) {
//var ac *AppConf
var vsConf VSConf
vsConf, err = LoadVSConfFromBs(bs)

View File

@@ -13,6 +13,7 @@ import (
"os"
"strings"
"sync"
"time"
"github.com/e1732a364fed/v2ray_simple"
"github.com/e1732a364fed/v2ray_simple/httpLayer"
@@ -47,6 +48,8 @@ type M struct {
listenCloserList []io.Closer
callbacks
ticker *time.Ticker
}
func New() *M {
@@ -103,6 +106,15 @@ func (m *M) Start() {
if dm := m.routingEnv.DnsMachine; dm != nil {
dm.StartListen()
}
if m.ticker == nil {
m.ticker = time.NewTicker(time.Minute * 5) //每隔五分钟输出一次目前状态
go func() {
for range m.ticker.C {
m.PrintAllState(os.Stdout)
}
}()
}
m.Unlock()
}
@@ -116,8 +128,8 @@ func (m *M) Start() {
func (m *M) SetupApiConf() {
m.ApiServerConf = NewApiServerConf()
m.ApiServerConf.SetUnDefault(&m.tomlApiServerConf)
m.ApiServerConf.SetUnDefault(&m.CmdApiServerConf)
m.ApiServerConf.SetNonDefault(&m.tomlApiServerConf)
m.ApiServerConf.SetNonDefault(&m.CmdApiServerConf)
}
// Stop不会停止ApiServer
@@ -141,6 +153,10 @@ func (m *M) Stop() {
if dm := m.routingEnv.DnsMachine; dm != nil {
dm.Stop()
}
if m.ticker != nil {
m.ticker.Stop()
m.ticker = nil
}
m.Unlock()
}