瀏覽代碼

Feature #TASK_QT-21189 Euspace 接入配置文件

Tom 1 年之前
父節點
當前提交
f958d89c97

+ 270 - 0
config/config.go

@@ -0,0 +1,270 @@
+package config
+
+import (
+	"fmt"
+	"github.com/coroot/coroot-node-agent/flags"
+	log "github.com/sirupsen/logrus"
+	"github.com/spf13/viper"
+	"strings"
+	"sync"
+)
+
+type Config struct {
+	m          *sync.RWMutex
+	subscribes map[scbType]chan struct{}
+	//subscribes     map[scbType]chan<- struct{}
+	euspaceCfg     *euspaceCfg
+	omniCommCfg    *omniCommonCfg
+	watchingConfig bool
+}
+
+type scbType string
+
+const (
+	scbTypeUndefined          scbType = ""
+	ScbTypeLogLevelChg        scbType = "logLevelChange"
+	ScbTypeNetDataIntervalChg scbType = "netDataIntervalChange"
+	ScbTypeConfigServerChg    scbType = "configServerChg"
+	ScbTypeDataServerChg      scbType = "dataServerChg"
+	ScbTypeTracesEndpointChg  scbType = "tracesEndpointChg"
+)
+
+var Cfg *Config
+
+func init() {
+
+	fmt.Println("\n")
+	fmt.Printf("------- *flags.LogLevel :%s \n", *flags.LogLevel)
+	fmt.Printf("------- *flags.DataServer :%s \n", *flags.DataServer)
+	fmt.Printf("------- *flags.ConfigServer :%s \n", *flags.ConfigServer)
+	fmt.Println("\n")
+
+	var err error
+	Cfg, err = New()
+	if err != nil {
+		log.Fatalf("load Config failed: %s.", err.Error())
+	}
+
+	//fmt.Printf("common.config_server :%s \n", Cfg.omniCommonV.GetString("common.config_server"))
+	//fmt.Printf("common.data_server :%s \n", Cfg.omniCommonV.GetString("common.data_server"))
+
+	fmt.Println("\n")
+	fmt.Printf("cfg --- logLevel :%s \n", Cfg.GetString("logLevel"))
+	fmt.Printf("cfg --- netDataInterval :%d  \n", Cfg.GetInt("netDataInterval"))
+	fmt.Printf("cfg --- configServer :%s  \n", Cfg.GetString("configServer"))
+	fmt.Printf("cfg --- dataServer :%s \n", Cfg.GetString("dataServer"))
+}
+
+func New() (*Config, error) {
+	/*
+		1. Viper uses the following precedence order: explicit call to `Set` > flag > env > Config > key/value store > default
+		2. 按照现有业务实现,设计为:命令行参数(*flags.xxx)优先级高于配置文件中的项 。
+		3. 会将euspace的配置 和 omniagent-common.ini的配置进行合并,然后同步到配置文件。(命令行参数会覆盖上下文的配置,但不会被同步到配置文件)
+	*/
+
+	ec, err := initEuspaceCfg()
+	if err != nil {
+		return nil, fmt.Errorf("init Config,load `euspace` Config failed : %s", err.Error())
+	}
+
+	omc, err := initOmniCommonCfg()
+	if err != nil {
+		return nil, fmt.Errorf("init Config,load `omniagent` Config failed : %s", err.Error())
+	}
+
+	cfg := &Config{
+		m:          new(sync.RWMutex),
+		subscribes: make(map[scbType]chan struct{}),
+		//subscribes:  make(map[scbType]chan<- struct{}),
+		euspaceCfg:  ec,
+		omniCommCfg: omc,
+	}
+
+	//merge and sync omniagent common.ini Config
+	if err = cfg.mergeAndSyncOmniCommConf(); err != nil {
+		return nil, fmt.Errorf("init Config,%s", err.Error())
+	}
+
+	//merge the flags
+	cfg.mergeFlags()
+
+	//simple check
+	theCfgSvr := cfg.euspaceCfg.runtimeV.GetString("configServer")
+	theDataSvr := cfg.euspaceCfg.runtimeV.GetString("dataServer")
+	if theCfgSvr == "" || theDataSvr == "" {
+		return nil, fmt.Errorf("init Config,the Config-server[%s] or the data-server[%s] is not set", theCfgSvr, theDataSvr)
+	}
+	if !strings.HasPrefix(theCfgSvr, "http") {
+		cfg.euspaceCfg.runtimeV.Set("configServer", fmt.Sprintf("http://%s", theCfgSvr))
+	}
+	if !strings.HasPrefix(theDataSvr, "http") {
+		cfg.euspaceCfg.runtimeV.Set("dataServer", fmt.Sprintf("http://%s", theDataSvr))
+	}
+
+	// set flags.TracesEndpoint
+	/*if *flags.TracesEndpoint == nil {
+		dataServer, err := url.Parse(theDataSvr)
+		if err == nil && dataServer != nil {
+			*flags.TracesEndpoint = dataServer.JoinPath(*flags.ServerPrefix + "/api/v2/data/receive")
+		}
+	}*/
+
+	//start watch
+	cfg.watchConfig()
+
+	return cfg, nil
+}
+
+func (c *Config) mergeAndSyncOmniCommConf() error {
+	hasChange := false
+	if c.omniCommCfg != nil {
+		cfgSrv := c.euspaceCfg.runtimeV.GetString("configServer")
+		omniCfgSvr := c.omniCommCfg.getConfigServer()
+		if omniCfgSvr != "" && omniCfgSvr != cfgSrv {
+			hasChange = true
+			c.euspaceCfg.runtimeV.Set("configServer", omniCfgSvr)
+		}
+
+		dataSvr := c.euspaceCfg.runtimeV.GetString("dataServer")
+		omniDataSvr := c.omniCommCfg.getDataServer()
+		if omniDataSvr != "" && omniDataSvr != dataSvr {
+			hasChange = true
+			c.euspaceCfg.runtimeV.Set("dataServer", omniDataSvr)
+		}
+	}
+	// set cfgRecordLast
+	if err := c.euspaceCfg.runtimeV.Unmarshal(c.euspaceCfg.cfgRecordLast); err != nil {
+		return fmt.Errorf("`euspaceCfg.runtimeV` unmarshal `cfgRecordLast` failed : %s", err.Error())
+	}
+	//fmt.Printf("------ c.euspaceCfg.cfgRecordLast:%#v \n", c.euspaceCfg.cfgRecordLast)
+
+	if err := c.omniCommCfg.commonSecV.Unmarshal(c.omniCommCfg.cfgRecordLast); err != nil {
+		return fmt.Errorf("`omniCommCfg.commonSecV` unmarshal `cfgRecordLast` failed : %s", err.Error())
+	}
+	//fmt.Printf("------ c.omniCommCfg.cfgRecordLast:%#v \n", c.omniCommCfg.cfgRecordLast)
+
+	//sync Config
+	if hasChange {
+		if err := c.euspaceCfg.syncConfToFile(c.euspaceCfg.cfgRecordLast); err != nil {
+			return err
+		}
+	}
+	return nil
+}
+
+func (c *Config) mergeFlags() {
+	if *flags.LogLevel != "" {
+		c.euspaceCfg.runtimeV.Set("logLevel", *flags.LogLevel)
+	}
+	if *flags.ConfigServer != "" {
+		c.euspaceCfg.runtimeV.Set("configServer", *flags.ConfigServer)
+	}
+	if *flags.DataServer != "" {
+		c.euspaceCfg.runtimeV.Set("dataServer", *flags.DataServer)
+	}
+}
+
+func (c *Config) watchConfig() {
+	c.m.Lock()
+	defer c.m.Unlock()
+
+	if c.watchingConfig {
+		return
+	}
+	c.watchingConfig = true
+
+	//watch euspace Config
+	c.euspaceCfg.watchConfig(c)
+
+	//watch omniagent-common.ini
+	if c.omniCommCfg.omniCommonV != nil {
+		c.omniCommCfg.watchConfig(c)
+	}
+}
+
+func (c *Config) Get(key string) any {
+	c.m.RLock()
+	defer c.m.RUnlock()
+	return c.euspaceCfg.runtimeV.Get(key)
+}
+
+func (c *Config) Sub(key string) *viper.Viper {
+	c.m.RLock()
+	defer c.m.RUnlock()
+	return c.euspaceCfg.runtimeV.Sub(key)
+}
+
+func (c *Config) GetString(key string) string {
+	c.m.RLock()
+	defer c.m.RUnlock()
+	return c.euspaceCfg.runtimeV.GetString(key)
+}
+
+func (c *Config) GetBool(key string) bool {
+	c.m.RLock()
+	defer c.m.RUnlock()
+	return c.euspaceCfg.runtimeV.GetBool(key)
+}
+
+func (c *Config) GetInt(key string) int {
+	c.m.RLock()
+	defer c.m.RUnlock()
+	return c.euspaceCfg.runtimeV.GetInt(key)
+}
+
+func (c *Config) GetInt32(key string) int32 {
+	c.m.RLock()
+	defer c.m.RUnlock()
+	return c.euspaceCfg.runtimeV.GetInt32(key)
+}
+
+func (c *Config) GetInt64(key string) int64 {
+	c.m.RLock()
+	defer c.m.RUnlock()
+	return c.euspaceCfg.runtimeV.GetInt64(key)
+}
+
+func (c *Config) GetFloat64(key string) float64 {
+	c.m.RLock()
+	defer c.m.RUnlock()
+	return c.euspaceCfg.runtimeV.GetFloat64(key)
+}
+
+func (c *Config) GetConfigFileUsed() string {
+	c.m.RLock()
+	defer c.m.RUnlock()
+	return c.euspaceCfg.runtimeV.ConfigFileUsed()
+}
+
+func (c *Config) SubscribeConfigChange(typ scbType) <-chan struct{} {
+	c.m.Lock()
+	defer c.m.Unlock()
+
+	if typ == scbTypeUndefined {
+		return nil
+	}
+	ch, ok := c.subscribes[typ]
+	if !ok {
+		ch = make(chan struct{})
+		c.subscribes[typ] = ch
+	}
+	return ch
+}
+
+func (c *Config) noticeSubscribers(typ scbType) {
+	c.m.RLock()
+	defer c.m.RUnlock()
+	if ch, ok := c.subscribes[typ]; ok {
+		ch <- struct{}{}
+	}
+}
+
+func (c *Config) Close() {
+	c.m.Lock()
+	defer c.m.Unlock()
+
+	for typ, ch := range c.subscribes {
+		close(ch)
+		delete(c.subscribes, typ)
+	}
+}

+ 139 - 0
config/euspaceCfg.go

@@ -0,0 +1,139 @@
+package config
+
+import (
+	"fmt"
+	"github.com/coroot/coroot-node-agent/flags"
+	"github.com/coroot/coroot-node-agent/utils"
+	"github.com/coroot/coroot-node-agent/utils/enums"
+	"github.com/fsnotify/fsnotify"
+	log "github.com/sirupsen/logrus"
+	"github.com/spf13/viper"
+	"reflect"
+)
+
+type euspaceCfgRecord struct {
+	LogLevel        string `mapstructure:"logLevel"`
+	NetDataInterval int    `mapstructure:"netDataInterval"`
+	ConfigServer    string `mapstructure:"configServer"`
+	DataServer      string `mapstructure:"dataServer"`
+}
+
+type euspaceCfg struct {
+	runtimeV      *viper.Viper
+	watchedV      *viper.Viper
+	cfgRecordLast *euspaceCfgRecord
+}
+
+func initEuspaceCfg() (*euspaceCfg, error) {
+	v := viper.New()
+	v.SetConfigName("config")
+	v.SetConfigType("yaml")
+	v.AddConfigPath(utils.GetDefaultConfPath())
+	if err := v.ReadInConfig(); err != nil {
+		/*if _, ok := err.(viper.ConfigFileNotFoundError); !ok {
+			return nil, err
+		}*/
+		return nil, err
+	}
+
+	sv := viper.New()
+	sv.SetConfigFile(v.ConfigFileUsed())
+
+	ec := &euspaceCfg{
+		runtimeV:      v,
+		watchedV:      sv,
+		cfgRecordLast: new(euspaceCfgRecord),
+	}
+	ec.setDefault()
+	return ec, nil
+}
+
+func (ec *euspaceCfg) setDefault() {
+	ec.runtimeV.SetDefault("logLevel", enums.DefaultLogLevel)
+	ec.runtimeV.SetDefault("netDataInterval", enums.DefaultNetDataInterval1Min)
+	ec.runtimeV.SetDefault("configServer", "")
+	ec.runtimeV.SetDefault("dataServer", "")
+}
+
+func (ec *euspaceCfg) syncConfToFile(ecr *euspaceCfgRecord) error {
+	if ecr != nil {
+
+		syncV := viper.New()
+		syncV.SetConfigFile(ec.watchedV.ConfigFileUsed())
+		syncV.Set("logLevel", ecr.LogLevel)
+		syncV.Set("netDataInterval", ecr.NetDataInterval)
+		syncV.Set("configServer", ecr.ConfigServer)
+		syncV.Set("dataServer", ecr.DataServer)
+		err := syncV.WriteConfig()
+		if err != nil {
+			return fmt.Errorf("sync Config to [%s] failed : %s", ec.watchedV.ConfigFileUsed(), err.Error())
+		}
+		return nil
+	}
+	return fmt.Errorf("sync Config to [%s] euspaceCfgRecord is nil", ec.watchedV.ConfigFileUsed())
+}
+
+func (ec *euspaceCfg) watchConfig(c *Config) {
+	ec.watchedV.OnConfigChange(func(e fsnotify.Event) {
+		//fmt.Printf("euspaceCfg Config file changed [%s],Op:%d ,AllKeys:%#v======> \n", e.Name, e.Op, ec.watchedV.AllSettings())
+
+		if !e.Op.Has(fsnotify.Create) && !e.Op.Has(fsnotify.Write) {
+			return
+		}
+
+		c.m.Lock()
+		//defer c.m.Unlock()
+		cr := new(euspaceCfgRecord)
+		if err := ec.watchedV.Unmarshal(cr); err != nil {
+			log.Warningf("on-Config-change, `watchedV` unmarshal `euspaceCfgRecord` failed : %s", err.Error())
+			c.m.Unlock()
+			return
+		}
+
+		if reflect.DeepEqual(ec.cfgRecordLast, cr) {
+			c.m.Unlock()
+			return
+		}
+		//拷贝ec.cfgRecordLast 到临时变量,目的是及时释放锁
+		crLast := ec.cfgRecordLast
+		//update cfgRecordLast
+		ec.cfgRecordLast = cr
+		c.m.Unlock()
+
+		if *flags.ConfigServer == "" {
+			if crLast.ConfigServer != cr.ConfigServer {
+				c.m.Lock()
+				ec.runtimeV.Set("configServer", cr.ConfigServer)
+				c.m.Unlock()
+				c.noticeSubscribers(ScbTypeConfigServerChg)
+			}
+		}
+
+		if *flags.DataServer == "" {
+			if crLast.DataServer != cr.DataServer {
+				c.m.Lock()
+				ec.runtimeV.Set("dataServer", cr.DataServer)
+				c.m.Unlock()
+				c.noticeSubscribers(ScbTypeDataServerChg)
+				c.noticeSubscribers(ScbTypeTracesEndpointChg)
+			}
+		}
+
+		if *flags.LogLevel == "" {
+			if crLast.LogLevel != cr.LogLevel {
+				c.m.Lock()
+				ec.runtimeV.Set("logLevel", cr.LogLevel)
+				c.m.Unlock()
+				c.noticeSubscribers(ScbTypeLogLevelChg)
+			}
+		}
+
+		if crLast.NetDataInterval != cr.NetDataInterval {
+			c.m.Lock()
+			ec.runtimeV.Set("netDataInterval", cr.NetDataInterval)
+			c.m.Unlock()
+			c.noticeSubscribers(ScbTypeNetDataIntervalChg)
+		}
+	})
+	ec.watchedV.WatchConfig()
+}

+ 198 - 0
config/omniagentCfg.go

@@ -0,0 +1,198 @@
+package config
+
+import (
+	"fmt"
+	"github.com/coroot/coroot-node-agent/flags"
+	"github.com/coroot/coroot-node-agent/utils"
+	"github.com/fsnotify/fsnotify"
+	log "github.com/sirupsen/logrus"
+	"github.com/spf13/viper"
+	"path/filepath"
+	"reflect"
+)
+
+type commonCfgRecord struct {
+	ConfigServer string `mapstructure:"config_server"`
+	DataServer   string `mapstructure:"data_server"`
+	//FileServer        string `ini:"file_server"`
+	ProxyConfigServer string `mapstructure:"proxy_config_server"`
+	ProxyDataServer   string `mapstructure:"proxy_data_server"`
+	//ProxyFileServer   string `ini:"proxy_file_server"`
+	//Ip string `ini:"ip"`
+	//Token string `ini:"token"`
+	//HostId string `ini:"host_id"`
+	//HostTag string `ini:"host_tag"`
+	//RealAccountId string `ini:"real_account_id"`
+}
+
+type omniCommonCfg struct {
+	omniCommonV   *viper.Viper
+	commonSecV    *viper.Viper
+	cfgRecordLast *commonCfgRecord
+}
+
+func initOmniCommonCfg() (*omniCommonCfg, error) {
+	var (
+		omniConfDirAbs  string
+		omniConfDirAbs2 string
+		err             error
+	)
+
+	v := viper.New()
+
+	if *flags.CommonIni != "" {
+		// *flags.CommonIni默认值 => /opt/cloudwise/omniagent/conf/common.ini
+		omniConfDirAbs, err = filepath.Abs(filepath.Dir(*flags.CommonIni))
+		if err != nil {
+			omniConfDirAbs = ""
+			log.Warningf("get filepath.Abs for the flags.CommonIni[%s] occurs error: %s.", *flags.CommonIni, err.Error())
+		} else {
+			v.AddConfigPath(omniConfDirAbs)
+		}
+	}
+
+	//结合部署路径,获取omniagent common.ini文件所在路径 => eg: /xxx/cloudwise/omniagent/agents/euspace/0.0.7/../../../conf
+	omniConfDir := filepath.Join(filepath.Dir(filepath.Dir(filepath.Dir(utils.GetRootPath()))), "conf")
+	omniConfDirAbs2, err = filepath.Abs(omniConfDir)
+	if err != nil {
+		omniConfDirAbs2 = ""
+		log.Warningf("get filepath.Abs for omniConfDir[%s] occurs error: %s.", omniConfDir, err.Error())
+	} else {
+		if omniConfDirAbs2 != "" && omniConfDirAbs != omniConfDirAbs2 {
+			v.AddConfigPath(omniConfDirAbs2)
+		}
+	}
+
+	v.SetConfigName("common")
+	v.SetConfigType("ini")
+	if err = v.ReadInConfig(); err != nil {
+		if _, ok := err.(viper.ConfigFileNotFoundError); ok {
+			return nil, nil
+		}
+		return nil, err
+	}
+
+	commonSecV := v.Sub("common")
+	if commonSecV == nil {
+		return nil, fmt.Errorf("`common` section not found in Config file [%s]", v.ConfigFileUsed())
+	}
+
+	//fmt.Printf("v.ConfigFileUsed() =====> %s \n", v.ConfigFileUsed())
+
+	//set RunInOmniagent at first
+	*flags.RunInOmniagent = true
+	//set CommonIni
+	if v.ConfigFileUsed() != *flags.CommonIni {
+		*flags.CommonIni = v.ConfigFileUsed()
+	}
+	// set ServerPrefix
+	if *flags.ServerPrefix == "" {
+		*flags.ServerPrefix = "/apm"
+	}
+
+	omc := &omniCommonCfg{
+		omniCommonV:   v,
+		commonSecV:    commonSecV,
+		cfgRecordLast: new(commonCfgRecord),
+	}
+	return omc, nil
+}
+
+func (omc *omniCommonCfg) getConfigServer() string {
+	omniPrxCfgSvr := omc.commonSecV.GetString("proxy_config_server")
+	if omniPrxCfgSvr != "" {
+		return omniPrxCfgSvr
+	} else {
+		return omc.commonSecV.GetString("config_server")
+	}
+}
+
+func (omc *omniCommonCfg) getDataServer() string {
+	omniPrxDataSvr := omc.commonSecV.GetString("proxy_data_server")
+	if omniPrxDataSvr != "" {
+		return omniPrxDataSvr
+	} else {
+		return omc.commonSecV.GetString("data_server")
+	}
+}
+
+func (omc *omniCommonCfg) getFileServer() string {
+	omniPrxFileSvr := omc.commonSecV.GetString("proxy_file_server")
+	if omniPrxFileSvr != "" {
+		return omniPrxFileSvr
+	} else {
+		return omc.commonSecV.GetString("file_server")
+	}
+}
+
+func (omc *omniCommonCfg) watchConfig(c *Config) {
+	omc.omniCommonV.OnConfigChange(func(e fsnotify.Event) {
+		//fmt.Printf("Config file changed [%s],Op:%d ,AllKeys:%#v======> \n", e.Name, e.Op, omc.omniCommonV.AllSettings())
+		if !e.Op.Has(fsnotify.Create) && !e.Op.Has(fsnotify.Write) {
+			return
+		}
+
+		c.m.Lock()
+		//defer c.m.Unlock()
+
+		omc.commonSecV = omc.omniCommonV.Sub("common")
+		if omc.commonSecV == nil {
+			//`common` section not found
+			c.m.Unlock()
+			return
+		}
+
+		ccr := new(commonCfgRecord)
+		if err := omc.commonSecV.Unmarshal(ccr); err != nil {
+			log.Warningf("on-Config-change,`omniCommonV` unmarshal `commonCfgRecord` failed : %s", err.Error())
+			c.m.Unlock()
+			return
+		}
+
+		if reflect.DeepEqual(omc.cfgRecordLast, ccr) {
+			c.m.Unlock()
+			return
+		}
+
+		//update cfgRecordLast
+		omc.cfgRecordLast = ccr
+		c.m.Unlock()
+
+		hasChange := false
+
+		omniCfgSvr := omc.getConfigServer()
+		if omniCfgSvr != "" && omniCfgSvr != c.euspaceCfg.cfgRecordLast.ConfigServer {
+			hasChange = true
+			c.euspaceCfg.cfgRecordLast.ConfigServer = omniCfgSvr
+			if *flags.ConfigServer == "" {
+				c.m.Lock()
+				c.euspaceCfg.runtimeV.Set("configServer", omniCfgSvr)
+				c.m.Unlock()
+				c.noticeSubscribers(ScbTypeConfigServerChg)
+			}
+		}
+
+		omniDataSvr := omc.getDataServer()
+		if omniDataSvr != "" && omniDataSvr != c.euspaceCfg.cfgRecordLast.DataServer {
+			hasChange = true
+			c.euspaceCfg.cfgRecordLast.DataServer = omniDataSvr
+			if *flags.DataServer == "" {
+				c.m.Lock()
+				c.euspaceCfg.runtimeV.Set("dataServer", omniDataSvr)
+				c.m.Unlock()
+				c.noticeSubscribers(ScbTypeDataServerChg)
+				c.noticeSubscribers(ScbTypeTracesEndpointChg)
+			}
+		}
+
+		// sync common.ini to euspace Config.ymal
+		if hasChange {
+			c.m.Lock()
+			if err := c.euspaceCfg.syncConfToFile(c.euspaceCfg.cfgRecordLast); err != nil {
+				log.Warningf("on-Config-change,%s", err.Error())
+			}
+			c.m.Unlock()
+		}
+	})
+	omc.omniCommonV.WatchConfig()
+}

+ 13 - 3
containers/registry.go

@@ -10,6 +10,7 @@ import (
 	"sync"
 	"time"
 
+	"github.com/coroot/coroot-node-agent/config"
 	"github.com/coroot/coroot-node-agent/kube"
 	. "github.com/coroot/coroot-node-agent/utils"
 	"github.com/coroot/coroot-node-agent/utils/enums"
@@ -141,13 +142,22 @@ func NewRegistry(reg prometheus.Registerer, kernelVersion string, nodeInfo *Node
 		nodeInfo:             nodeInfo,
 	}
 	// 初始化软负载集群节点
-	proxyClient, clientErr := NewProxyClient(*flags.ConfigServer, false)
+	proxyClient, clientErr := NewProxyClient(config.Cfg.GetString("configServer"), false)
 	if clientErr == nil {
 		// 负载健康检测
 		try.Go(proxyClient.CheckEndpoints, CatchFn)
-		klog.Infof("New Proxy Client success.config_server is [%s]", *flags.ConfigServer)
+		klog.Infof("New Proxy Client success.config_server is [%s]", config.Cfg.GetString("configServer"))
+		//监听configServer变更
+		try.Go(func() {
+			for range config.Cfg.SubscribeConfigChange(config.ScbTypeConfigServerChg) {
+				klog.Infof("the configuration `configServer` changed,new logLevel [%s]", config.Cfg.GetString("configServer"))
+				_ = proxyClient.SetEndpoint(config.Cfg.GetString("configServer"), false)
+				klog.Infof("the configuration `configServer` change finished")
+			}
+			klog.Infof("SubscribeConfigChange ScbTypeConfigServerChg exit")
+		}, CatchFn)
 	} else {
-		klog.WithError(clientErr).Errorf("NewProxyClient error, Please check [export CONFIG_ENDPOINT=ip:port]")
+		klog.WithError(clientErr).Errorf("NewProxyClient error, Please set in the config file[%s] or check [export CONFIG_ENDPOINT=ip:port]", config.Cfg.GetConfigFileUsed())
 		return nil, clientErr
 	}
 

+ 28 - 26
flags/flags.go

@@ -7,8 +7,6 @@ import (
 	"github.com/coroot/coroot-node-agent/utils/modelse"
 	"github.com/jedib0t/go-pretty/v6/table"
 	"gopkg.in/alecthomas/kingpin.v2"
-	"gopkg.in/ini.v1"
-	"net/url"
 	"os"
 	"path"
 	"strings"
@@ -16,11 +14,13 @@ import (
 
 var (
 	// apm
-	ConfigServer        = kingpin.Flag("config-server", "The URL of the endpoint to send traces to").Envar("CONFIG_SERVER").Default("http://10.0.16.250:18080").String()
-	DataServer          = kingpin.Flag("data-server", "The URL of the endpoint to send traces to").Envar("DATA_SERVER").Default("http://10.0.16.250:18080").String()
+	//ConfigServer        = kingpin.Flag("config-server", "The URL of the endpoint to send traces to").Envar("CONFIG_SERVER").Default("http://10.0.16.250:18080").String()
+	ConfigServer = kingpin.Flag("config-server", "The URL of the endpoint to send traces to").Envar("CONFIG_SERVER").Default("").String()
+	//DataServer          = kingpin.Flag("data-server", "The URL of the endpoint to send traces to").Envar("DATA_SERVER").Default("http://10.0.16.250:18080").String()
+	DataServer          = kingpin.Flag("data-server", "The URL of the endpoint to send traces to").Envar("DATA_SERVER").Default("").String()
 	DumpApps            = kingpin.Flag("dump", "Dump app snap").Default("false").Bool()
 	Version             = kingpin.Flag("version", "show app version").Short('v').Bool()
-	LogLevel            = kingpin.Flag("log-level", "Log level").Envar("LOG_LEVEL").Default("info").String()
+	LogLevel            = kingpin.Flag("log-level", "Log level").Envar("LOG_LEVEL").Default("").String()
 	EbpfFilePath        = kingpin.Flag("ebpf-path", "Set ebpf file path").Envar("EBPF_FILE").Default("").String()
 	CommonIni           = kingpin.Flag("common.ini", "Set ebpf file path").Envar("COMMON_INI").Default("/opt/cloudwise/omniagent/conf/common.ini").String()
 	ServerPrefix        = kingpin.Flag("server-prefix", "server-prefix").Envar("SERVER_PREFIX").Default("").String()
@@ -113,28 +113,30 @@ func init() {
 		*ListenAddress = "127.0.0.1:10300"
 	}
 
-	// set ServerPrefix
-	// set ConfigServer
-	// set DataServer
-	if *CommonIni != "" {
-		iniData, err := ini.Load(*CommonIni)
-		if err == nil && iniData != nil {
-			*ServerPrefix = "/apm"
-			*ConfigServer = iniData.Section("common").Key("config_server").String()
-			*DataServer = iniData.Section("common").Key("data_server").String()
+	/*
+		// set ServerPrefix
+		// set ConfigServer
+		// set DataServer
+		if *CommonIni != "" {
+			iniData, err := ini.Load(*CommonIni)
+			if err == nil && iniData != nil {
+				*ServerPrefix = "/apm"
+				*ConfigServer = iniData.Section("common").Key("config_server").String()
+				*DataServer = iniData.Section("common").Key("data_server").String()
+			}
 		}
-	}
-
-	// set TracesEndpoint
-	if *TracesEndpoint == nil && *DataServer != "" {
-		if !strings.HasPrefix(*DataServer, "http") {
-			*DataServer = fmt.Sprintf("http://%s", *DataServer)
-		}
-		dataServer, err := url.Parse(*DataServer)
-		if err == nil && dataServer != nil {
-			*TracesEndpoint = dataServer.JoinPath(*ServerPrefix + "/api/v2/data/receive")
-		}
-	}
+	*/
+	/*
+		// set TracesEndpoint
+		if *TracesEndpoint == nil && *DataServer != "" {
+			if !strings.HasPrefix(*DataServer, "http") {
+				*DataServer = fmt.Sprintf("http://%s", *DataServer)
+			}
+			dataServer, err := url.Parse(*DataServer)
+			if err == nil && dataServer != nil {
+				*TracesEndpoint = dataServer.JoinPath(*ServerPrefix + "/api/v2/data/receive")
+			}
+		}*/
 
 	// set tiny-agent config
 	//nativeConf := utils.GetDefaultAgentsPath("NativeAgent", "conf", "agent.properties")

+ 23 - 20
go.mod

@@ -16,8 +16,8 @@ require (
 	github.com/go-kit/log v0.2.1
 	github.com/go-logr/logr v1.4.1
 	github.com/go-sql-driver/mysql v1.8.1
-	github.com/gomodule/redigo v1.9.2
 	github.com/godbus/dbus/v5 v5.0.6
+	github.com/gomodule/redigo v1.9.2
 	github.com/grafana/pyroscope/ebpf v0.4.1
 	github.com/hashicorp/go-version v1.6.0
 	github.com/jedib0t/go-pretty/v6 v6.6.0
@@ -32,20 +32,20 @@ require (
 	github.com/prometheus/prometheus v0.50.1
 	github.com/pyroscope-io/dotnetdiag v1.2.1
 	github.com/sirupsen/logrus v1.9.3
-	github.com/stretchr/testify v1.8.4
+	github.com/stretchr/testify v1.9.0
 	github.com/vishvananda/netlink v1.2.1-beta.2.0.20220608195807-1a118fe229fc
 	github.com/vishvananda/netns v0.0.4
 	github.com/xin053/hsperfdata v0.2.3
 	go.mongodb.org/mongo-driver v1.13.1
-	go.opentelemetry.io/otel v1.22.0
+	go.opentelemetry.io/otel v1.24.0
 	go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.22.0
 	go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.22.0
 	go.opentelemetry.io/otel/sdk v1.22.0
-	go.opentelemetry.io/otel/trace v1.22.0
+	go.opentelemetry.io/otel/trace v1.24.0
 	golang.org/x/arch v0.4.0
 	golang.org/x/exp v0.0.0-20240119083558-1b970713d09a
 	golang.org/x/mod v0.16.0
-	golang.org/x/net v0.22.0
+	golang.org/x/net v0.23.0
 	golang.org/x/sys v0.18.0
 	golang.org/x/time v0.5.0
 	gopkg.in/alecthomas/kingpin.v2 v2.2.6
@@ -56,7 +56,7 @@ require (
 )
 
 require (
-	cloud.google.com/go/compute v1.23.3 // indirect
+	cloud.google.com/go/compute v1.24.0 // indirect
 	filippo.io/edwards25519 v1.1.0 // indirect
 	github.com/Azure/azure-sdk-for-go/sdk/azcore v1.9.1 // indirect
 	github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.5.1 // indirect
@@ -112,7 +112,7 @@ require (
 	github.com/google/go-cmp v0.6.0 // indirect
 	github.com/google/gofuzz v1.2.0 // indirect
 	github.com/google/pprof v0.0.0-20240117000934-35fc243c5815 // indirect
-	github.com/google/uuid v1.5.0 // indirect
+	github.com/google/uuid v1.6.0 // indirect
 	github.com/grafana/regexp v0.0.0-20221123153739-15dc172cd2db // indirect
 	github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 // indirect
 	github.com/hashicorp/golang-lru/v2 v2.0.5 // indirect
@@ -126,7 +126,7 @@ require (
 	github.com/klauspost/compress v1.17.4 // indirect
 	github.com/kylelemons/godebug v1.1.0 // indirect
 	github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
-	github.com/magiconair/properties v1.8.6 // indirect
+	github.com/magiconair/properties v1.8.7 // indirect
 	github.com/mailru/easyjson v0.7.7 // indirect
 	github.com/mattn/go-runewidth v0.0.15 // indirect
 	github.com/mdlayher/genetlink v1.3.2 // indirect
@@ -149,7 +149,7 @@ require (
 	github.com/opencontainers/selinux v1.10.1 // indirect
 	github.com/opentracing/opentracing-go v1.2.1-0.20220228012449-10b1cf09e00b // indirect
 	github.com/pelletier/go-toml v1.9.5 // indirect
-	github.com/pelletier/go-toml/v2 v2.0.5 // indirect
+	github.com/pelletier/go-toml/v2 v2.2.2 // indirect
 	github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5 // indirect
 	github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c // indirect
 	github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
@@ -157,23 +157,26 @@ require (
 	github.com/prometheus/common/sigv4 v0.1.0 // indirect
 	github.com/prometheus/procfs v0.12.0 // indirect
 	github.com/rivo/uniseg v0.2.0 // indirect
+	github.com/sagikazarmark/locafero v0.4.0 // indirect
+	github.com/sagikazarmark/slog-shim v0.1.0 // indirect
 	github.com/samber/lo v1.38.1 // indirect
 	github.com/sasha-s/go-deadlock v0.3.1 // indirect
 	github.com/shirou/gopsutil/v3 v3.22.10 // indirect
-	github.com/spf13/afero v1.9.2 // indirect
-	github.com/spf13/cast v1.5.0 // indirect
+	github.com/sourcegraph/conc v0.3.0 // indirect
+	github.com/spf13/afero v1.11.0 // indirect
+	github.com/spf13/cast v1.6.0 // indirect
 	github.com/spf13/cobra v1.6.1 // indirect
 	github.com/spf13/jwalterweatherman v1.1.0 // indirect
 	github.com/spf13/pflag v1.0.5 // indirect
-	github.com/spf13/viper v1.14.0 // indirect
-	github.com/subosito/gotenv v1.4.1 // indirect
+	github.com/spf13/viper v1.19.0 // indirect
+	github.com/subosito/gotenv v1.6.0 // indirect
 	github.com/yusufpapurcu/wmi v1.2.2 // indirect
 	go.opencensus.io v0.24.0 // indirect
 	go.opentelemetry.io/collector/featuregate v1.0.1 // indirect
 	go.opentelemetry.io/collector/pdata v1.0.1 // indirect
 	go.opentelemetry.io/collector/semconv v0.93.0 // indirect
-	go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.47.0 // indirect
-	go.opentelemetry.io/otel/metric v1.22.0 // indirect
+	go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 // indirect
+	go.opentelemetry.io/otel/metric v1.24.0 // indirect
 	go.opentelemetry.io/proto/otlp v1.0.0 // indirect
 	go.uber.org/atomic v1.11.0 // indirect
 	go.uber.org/goleak v1.3.0 // indirect
@@ -181,16 +184,16 @@ require (
 	go4.org/intern v0.0.0-20211027215823-ae77deb06f29 // indirect
 	go4.org/unsafe/assume-no-moving-gc v0.0.0-20230525183740-e7c30c78aeb2 // indirect
 	golang.org/x/crypto v0.21.0 // indirect
-	golang.org/x/oauth2 v0.16.0 // indirect
+	golang.org/x/oauth2 v0.18.0 // indirect
 	golang.org/x/sync v0.6.0 // indirect
 	golang.org/x/term v0.18.0 // indirect
 	golang.org/x/text v0.14.0 // indirect
 	golang.org/x/tools v0.19.0 // indirect
 	google.golang.org/appengine v1.6.8 // indirect
-	google.golang.org/genproto/googleapis/api v0.0.0-20240116215550-a9fa1716bcac // indirect
-	google.golang.org/genproto/googleapis/rpc v0.0.0-20240116215550-a9fa1716bcac // indirect
-	google.golang.org/grpc v1.61.0 // indirect
-	google.golang.org/protobuf v1.32.0 // indirect
+	google.golang.org/genproto/googleapis/api v0.0.0-20240311132316-a219d84964c2 // indirect
+	google.golang.org/genproto/googleapis/rpc v0.0.0-20240314234333-6e1732d8331c // indirect
+	google.golang.org/grpc v1.62.1 // indirect
+	google.golang.org/protobuf v1.33.0 // indirect
 	gopkg.in/inf.v0 v0.9.1 // indirect
 	gopkg.in/ini.v1 v1.67.0 // indirect
 	gopkg.in/yaml.v3 v3.0.1 // indirect

+ 31 - 0
go.sum

@@ -26,6 +26,7 @@ cloud.google.com/go/bigquery v1.7.0/go.mod h1://okPTzCYNXSlb24MZs83e2Do+h+VXtc4g
 cloud.google.com/go/bigquery v1.8.0/go.mod h1:J5hqkt3O0uAFnINi6JXValWIb1v0goeZM77hZzJN/fQ=
 cloud.google.com/go/compute v1.23.3 h1:6sVlXXBmbd7jNX0Ipq0trII3e4n1/MsADLK6a+aiVlk=
 cloud.google.com/go/compute v1.23.3/go.mod h1:VCgBUoMnIVIR0CscqQiPJLAG25E3ZRZMzcFZeQ+h8CI=
+cloud.google.com/go/compute v1.24.0/go.mod h1:kw1/T+h/+tK2LJK0wiPPx1intgdAM3j/g3hFDlscY40=
 cloud.google.com/go/compute/metadata v0.2.3 h1:mg4jlk7mCAj6xXp9UJ4fjI9VUI5rubuGBW5aJ7UnBMY=
 cloud.google.com/go/compute/metadata v0.2.3/go.mod h1:VAV5nSsACxMJvgaAuX6Pk2AawlZn8kiOGuCv6gTkwuA=
 cloud.google.com/go/datastore v1.0.0/go.mod h1:LXYbyblFSglQ5pkeyhO+Qmw7ukd3C+pD7TKLgZqpHYE=
@@ -603,6 +604,7 @@ github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+
 github.com/google/uuid v1.2.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
 github.com/google/uuid v1.5.0 h1:1p67kYwdtXjb0gL0BPiP1Av9wiZPo5A8z2cWkTZ+eyU=
 github.com/google/uuid v1.5.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
+github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
 github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
 github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
 github.com/googleapis/gnostic v0.4.1/go.mod h1:LRhVm6pbyptWbWbuZ38d1eyptfvIytN3ir6b65WBswg=
@@ -762,6 +764,8 @@ github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0/go.mod h1:zJYVVT2
 github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
 github.com/magiconair/properties v1.8.6 h1:5ibWZ6iY0NctNGWo87LalDlEZ6R41TqbbDamhfG/Qzo=
 github.com/magiconair/properties v1.8.6/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60=
+github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY=
+github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0=
 github.com/mailru/easyjson v0.0.0-20160728113105-d5b7844b561a/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
 github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
 github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
@@ -918,6 +922,8 @@ github.com/pelletier/go-toml v1.9.5 h1:4yBQzkHv+7BHq2PQUZF3Mx0IYxG7LsP222s7Agd3v
 github.com/pelletier/go-toml v1.9.5/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=
 github.com/pelletier/go-toml/v2 v2.0.5 h1:ipoSadvV8oGUjnUbMub59IDPPwfxF694nG/jwbMiyQg=
 github.com/pelletier/go-toml/v2 v2.0.5/go.mod h1:OMHamSCAODeSsVrwwvcJOaoN0LIUIaFVNZzmWyNfXas=
+github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM=
+github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs=
 github.com/peterbourgon/diskv v2.0.1+incompatible/go.mod h1:uqqh8zWWbv1HBMNONnaR/tNboyR3/BZd58JJSHlUSCU=
 github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5 h1:q2e307iGHPdTGp0hoxKjt1H5pDo6utceo3dQVK3I5XQ=
 github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5/go.mod h1:jvVRKCrJTQWu0XVbaOlby/2lO20uSCHEMzzplHXte1o=
@@ -991,6 +997,10 @@ github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUz
 github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
 github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
 github.com/safchain/ethtool v0.0.0-20190326074333-42ed695e3de8/go.mod h1:Z0q5wiBQGYcxhMZ6gUqHn6pYNLypFAvaL3UvgZLR0U4=
+github.com/sagikazarmark/locafero v0.4.0 h1:HApY1R9zGo4DBgr7dqsTH/JJxLTTsOt7u6keLGt6kNQ=
+github.com/sagikazarmark/locafero v0.4.0/go.mod h1:Pe1W6UlPYUk/+wc/6KFhbORCfqzgYEpgQ3O5fPuL3H4=
+github.com/sagikazarmark/slog-shim v0.1.0 h1:diDBnUNK9N/354PgrxMywXnAwEr1QZcOr6gto+ugjYE=
+github.com/sagikazarmark/slog-shim v0.1.0/go.mod h1:SrcSrq8aKtyuqEI1uvTDTK1arOWRIczQRv+GVI1AkeQ=
 github.com/samber/lo v1.38.1 h1:j2XEAqXKb09Am4ebOg31SpvzUTTs6EN3VfgeLUhPdXM=
 github.com/samber/lo v1.38.1/go.mod h1:+m/ZKRl6ClXCE2Lgf3MsQlWfh4bn1bz6CXEOxnEXnEA=
 github.com/sasha-s/go-deadlock v0.3.1 h1:sqv7fDNShgjcaxkO0JNcOAlr8B9+cV5Ey/OB71efZx0=
@@ -1017,14 +1027,20 @@ github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVs
 github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
 github.com/smartystreets/goconvey v0.0.0-20190330032615-68dc04aab96a/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
 github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM=
+github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9ySo=
+github.com/sourcegraph/conc v0.3.0/go.mod h1:Sdozi7LEKbFPqYX2/J+iBAM6HpqSLTASQIKqDmF7Mt0=
 github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
 github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=
 github.com/spf13/afero v1.2.2/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk=
 github.com/spf13/afero v1.9.2 h1:j49Hj62F0n+DaZ1dDCvhABaPNSGNkt32oRFxI33IEMw=
 github.com/spf13/afero v1.9.2/go.mod h1:iUV7ddyEEZPO5gA3zD4fJt6iStLlL+Lg4m2cihcDf8Y=
+github.com/spf13/afero v1.11.0 h1:WJQKhtpdm3v2IzqG8VMqrr6Rf3UYpEF239Jy9wNepM8=
+github.com/spf13/afero v1.11.0/go.mod h1:GH9Y3pIexgf1MTIWtNGyogA5MwRIDXGUr+hbWNoBjkY=
 github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
 github.com/spf13/cast v1.5.0 h1:rj3WzYc11XZaIZMPKmwP96zkFEnnAmV8s6XbB2aY32w=
 github.com/spf13/cast v1.5.0/go.mod h1:SpXXQ5YoyJw6s3/6cMTQuxvgRl3PCJiyaX9p6b155UU=
+github.com/spf13/cast v1.6.0 h1:GEiTHELF+vaR5dhz3VqZfFSzZjYbgeKDpBxQVS4GYJ0=
+github.com/spf13/cast v1.6.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo=
 github.com/spf13/cobra v0.0.2-0.20171109065643-2da4a54c5cee/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
 github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
 github.com/spf13/cobra v1.0.0/go.mod h1:/6GTrnGXV9HjY+aR4k0oJ5tcvakLuG6EuKReYlHNrgE=
@@ -1042,6 +1058,8 @@ github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An
 github.com/spf13/viper v1.4.0/go.mod h1:PTJ7Z/lr49W6bUbkmS1V3by4uWynFiR9p7+dSq/yZzE=
 github.com/spf13/viper v1.14.0 h1:Rg7d3Lo706X9tHsJMUjdiwMpHB7W8WnSVOssIY+JElU=
 github.com/spf13/viper v1.14.0/go.mod h1:WT//axPky3FdvXHzGw33dNdXXXfFQqmEalje+egj8As=
+github.com/spf13/viper v1.19.0 h1:RWq5SEjt8o25SROyN3z2OrDB9l7RPd3lwTWU8EcEdcI=
+github.com/spf13/viper v1.19.0/go.mod h1:GQUN9bilAbhU/jgc1bKs99f/suXKeUMct8Adx5+Ntkg=
 github.com/stefanberger/go-pkcs11uri v0.0.0-20201008174630-78d3cae3a980/go.mod h1:AO3tvPzVZ/ayst6UlUKUv6rcPQInYe3IknH3jYhAKu8=
 github.com/stretchr/objx v0.0.0-20180129172003-8a3f7159479f/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
 github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
@@ -1050,6 +1068,7 @@ github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoH
 github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
 github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c=
 github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
+github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
 github.com/stretchr/testify v0.0.0-20180303142811-b89eecf5ca5d/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
 github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
 github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
@@ -1062,8 +1081,11 @@ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO
 github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
 github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
 github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
+github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
 github.com/subosito/gotenv v1.4.1 h1:jyEFiXpy21Wm81FBN71l9VoMMV8H8jG+qIK3GCpY6Qs=
 github.com/subosito/gotenv v1.4.1/go.mod h1:ayKnFf/c6rvx/2iiLrJUk1e6plDbT3edrFNGqEflhK0=
+github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8=
+github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU=
 github.com/syndtr/gocapability v0.0.0-20170704070218-db04d3cc01c8/go.mod h1:hkRG7XYTFWNJGYcbNJQlaLq0fg1yr4J4t/NcTQtrfww=
 github.com/syndtr/gocapability v0.0.0-20180916011248-d98352740cb2/go.mod h1:hkRG7XYTFWNJGYcbNJQlaLq0fg1yr4J4t/NcTQtrfww=
 github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635/go.mod h1:hkRG7XYTFWNJGYcbNJQlaLq0fg1yr4J4t/NcTQtrfww=
@@ -1145,6 +1167,7 @@ go.opentelemetry.io/collector/semconv v0.93.0 h1:eBlMcVNTwYYsVdAsCVDs4wvVYs75K1x
 go.opentelemetry.io/collector/semconv v0.93.0/go.mod h1:gZ0uzkXsN+J5NpiRcdp9xOhNGQDDui8Y62p15sKrlzo=
 go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.47.0 h1:sv9kVfal0MK0wBMCOGr+HeJm9v803BkJxGrk2au7j08=
 go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.47.0/go.mod h1:SK2UL73Zy1quvRPonmOmRDiWk1KBV3LyIeeIxcEApWw=
+go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0/go.mod h1:p8pYQP+m5XfbZm9fxtSKAbM6oIllS7s2AfxrChvc7iw=
 go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI=
 go.opentelemetry.io/proto/otlp v1.0.0 h1:T0TX0tmXU8a3CbNXzEKGeU5mIVOdf0oykP+u2lIVU/I=
 go.opentelemetry.io/proto/otlp v1.0.0/go.mod h1:Sy6pihPLfYHkr3NkUbEhGHFhINUSI/v80hjKIs5JXpM=
@@ -1281,6 +1304,8 @@ golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qx
 golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
 golang.org/x/net v0.22.0 h1:9sGLhx7iRIHEiX0oAJ3MRZMUCElJgy7Br1nO+AMN3Tc=
 golang.org/x/net v0.22.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
+golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs=
+golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
 golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
 golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
 golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
@@ -1293,6 +1318,7 @@ golang.org/x/oauth2 v0.0.0-20210218202405-ba52d332ba99/go.mod h1:KelEdhl1UZF7XfJ
 golang.org/x/oauth2 v0.0.0-20210514164344-f6687ab2804c/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A=
 golang.org/x/oauth2 v0.16.0 h1:aDkGMBSYxElaoP81NpoUoz2oo2R2wHdZpGToUxfyQrQ=
 golang.org/x/oauth2 v0.16.0/go.mod h1:hqZ+0LWXsiVoZpeld6jVt06P3adbS2Uu911W1SsJv2o=
+golang.org/x/oauth2 v0.18.0/go.mod h1:Wf7knwG0MPoWIMMBgFlEaSUDaKskp0dCfrlJRJXbBi8=
 golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
 golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
 golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
@@ -1583,8 +1609,10 @@ google.golang.org/genproto v0.0.0-20240102182953-50ed04b92917 h1:nz5NESFLZbJGPFx
 google.golang.org/genproto v0.0.0-20240102182953-50ed04b92917/go.mod h1:pZqR+glSb11aJ+JQcczCvgf47+duRuzNSKqE8YAQnV0=
 google.golang.org/genproto/googleapis/api v0.0.0-20240116215550-a9fa1716bcac h1:OZkkudMUu9LVQMCoRUbI/1p5VCo9BOrlvkqMvWtqa6s=
 google.golang.org/genproto/googleapis/api v0.0.0-20240116215550-a9fa1716bcac/go.mod h1:B5xPO//w8qmBDjGReYLpR6UJPnkldGkCSMoH/2vxJeg=
+google.golang.org/genproto/googleapis/api v0.0.0-20240311132316-a219d84964c2/go.mod h1:O1cOfN1Cy6QEYr7VxtjOyP5AdAuR0aJ/MYZaaof623Y=
 google.golang.org/genproto/googleapis/rpc v0.0.0-20240116215550-a9fa1716bcac h1:nUQEQmH/csSvFECKYRv6HWEyypysidKl2I6Qpsglq/0=
 google.golang.org/genproto/googleapis/rpc v0.0.0-20240116215550-a9fa1716bcac/go.mod h1:daQN87bsDqDoe316QbbvX60nMoJQa4r6Ds0ZuoAe5yA=
+google.golang.org/genproto/googleapis/rpc v0.0.0-20240314234333-6e1732d8331c/go.mod h1:WtryC6hu0hhx87FDGxWCDptyssuo68sk10vYjF+T9fY=
 google.golang.org/grpc v0.0.0-20160317175043-d3ddb4469d5a/go.mod h1:yo6s7OP7yaDglbqo1J04qKzAhqBH6lvTonzMVmEdcZw=
 google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
 google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38=
@@ -1610,6 +1638,7 @@ google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAG
 google.golang.org/grpc v1.40.0/go.mod h1:ogyxbiOoUXAkP+4+xa6PZSE9DZgIHtSpzjDTB9KAK34=
 google.golang.org/grpc v1.61.0 h1:TOvOcuXn30kRao+gfcvsebNEa5iZIiLkisYEkf7R7o0=
 google.golang.org/grpc v1.61.0/go.mod h1:VUbo7IFqmF1QtCAstipjG0GIoq49KvMe9+h1jFLBNJs=
+google.golang.org/grpc v1.62.1/go.mod h1:IWTG0VlJLCh1SkC58F7np9ka9mx/WNkjl4PGJaiq+QE=
 google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
 google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
 google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
@@ -1625,6 +1654,8 @@ google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQ
 google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
 google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I=
 google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
+google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
+google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
 gopkg.in/airbrake/gobrake.v2 v2.0.9/go.mod h1:/h5ZAUhDkGaJfjzjKLSjv6zCL6O0LLBxU4K+aSYdM/U=
 gopkg.in/alecthomas/kingpin.v2 v2.2.6 h1:jMFz6MfLP0/4fUyZle81rXUoxOBFi19VUFKVDOQfozc=
 gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=

+ 48 - 9
main.go

@@ -4,6 +4,7 @@ import (
 	"bytes"
 	"encoding/json"
 	"github.com/cilium/ebpf/rlimit"
+	"github.com/coroot/coroot-node-agent/config"
 	"github.com/coroot/coroot-node-agent/kube"
 	"github.com/coroot/coroot-node-agent/utils"
 	"github.com/coroot/coroot-node-agent/utils/enums"
@@ -39,8 +40,7 @@ import (
 )
 
 var (
-	version             = flags.AgentVersion
-	sendNetDataInterval = 1 * time.Minute
+	version = flags.AgentVersion
 )
 
 const minSupportedKernelVersion = "4.18"
@@ -133,9 +133,8 @@ type PostData struct {
 	Data        []MetricData `json:"data"`
 }
 
-func main() {
-	runtime.GOMAXPROCS(1)
-	err := logs.InitLog(*flags.LogLevel, logs.LogConfig{
+func initLog() error {
+	err := logs.InitLog(config.Cfg.GetString("logLevel"), logs.LogConfig{
 		Path:       utils.GetDefaultLogPath(),
 		AppInfo:    enums.DaemonProc,
 		MaxSize:    50, // 日志文件最大尺寸,单位MB
@@ -143,10 +142,27 @@ func main() {
 		MaxAge:     3,  // 日志文件保留的最长时间,单位天
 		//Console:    true,
 	})
+	return err
+}
 
-	if err != nil {
+func main() {
+	runtime.GOMAXPROCS(1)
+
+	if err := initLog(); err != nil {
 		log.WithError(err).Errorf("log init error.")
 	}
+
+	try.Go(func() {
+		for range config.Cfg.SubscribeConfigChange(config.ScbTypeLogLevelChg) {
+			log.Infof("the configuration `logLevel` changed,new logLevel [%s]", config.Cfg.GetString("logLevel"))
+			if err := initLog(); err != nil {
+				log.WithError(err).Errorf("after logLevelChange, log init error.")
+			}
+			log.Infof("the configuration `logLevel` change finished")
+		}
+		log.Infof("SubscribeConfigChange ScbTypeLogLevelChg exit")
+	}, utils.CatchFn)
+
 	if err := rlimit.RemoveMemlock(); err != nil {
 		log.WithError(err).Warning("Failed Removing memlock.")
 	} else {
@@ -326,9 +342,9 @@ func main() {
 		// 创建请求
 		urlRoute := "/api/v2/ebpf/receive"
 
-		log.Infoln("send url is ", *flags.DataServer+*flags.ServerPrefix+urlRoute)
+		log.Infoln("send url is ", config.Cfg.GetString("dataServer")+*flags.ServerPrefix+urlRoute)
 		// req, err := http.NewRequest("POST", "http://10.0.7.115:18080/api/v2/ebpf/receive", bytes.NewBuffer(jsonData))
-		req, err := http.NewRequest("POST", *flags.DataServer+*flags.ServerPrefix+urlRoute, bytes.NewBuffer(jsonData))
+		req, err := http.NewRequest("POST", config.Cfg.GetString("dataServer")+*flags.ServerPrefix+urlRoute, bytes.NewBuffer(jsonData))
 		if err != nil {
 			log.Errorf(err.Error())
 			return
@@ -367,7 +383,11 @@ func main() {
 	sendNetDataDone := make(chan struct{})
 
 	try.Go(func() {
-		sendNetDataTicker := time.NewTicker(sendNetDataInterval)
+		intervalChangeCh := config.Cfg.SubscribeConfigChange(config.ScbTypeNetDataIntervalChg)
+		dataServerChangeCh := config.Cfg.SubscribeConfigChange(config.ScbTypeDataServerChg)
+
+		interval := time.Duration(config.Cfg.GetInt("netDataInterval")) * time.Minute
+		sendNetDataTicker := time.NewTicker(interval)
 		defer sendNetDataTicker.Stop()
 		for {
 			select {
@@ -379,6 +399,24 @@ func main() {
 					log.Infoln("after enter sendNetDataFunc")
 					sendNetDataFunc()
 				}
+			case _, ok := <-intervalChangeCh:
+				if ok {
+					log.Infof("the configuration `netDataInterval` changed,new netDataInterval [%d]", config.Cfg.GetInt("netDataInterval"))
+					interval = time.Duration(config.Cfg.GetInt("netDataInterval")) * time.Minute
+					sendNetDataTicker.Reset(interval)
+					log.Infof("the configuration `netDataInterval` change finished")
+				} else {
+					intervalChangeCh = nil
+					log.Infof("SubscribeConfigChange ScbTypeNetDataIntervalChg exit")
+				}
+			case _, ok := <-dataServerChangeCh:
+				if ok {
+					// something todo?
+					log.Infof("the configuration `dataServer` changed,new dataServer [%s]", config.Cfg.GetString("dataServer"))
+				} else {
+					dataServerChangeCh = nil
+					log.Infof("SubscribeConfigChange ScbTypeDataServerChg exit")
+				}
 			}
 		}
 	}, utils.CatchFn)
@@ -538,6 +576,7 @@ func main() {
 		<-sigs
 		log.Infoln("Signal received, shutting down...")
 		cr.Close()
+		config.Cfg.Close()
 		close(sendNetDataDone)
 		close(done)
 	}, utils.CatchFn)

+ 9 - 9
pkg/go.opentelemetry.io/otel/exporters/otlp/otlptrace/go.mod

@@ -7,12 +7,12 @@ toolchain go1.21.3
 require (
 	github.com/coroot/coroot-node-agent v0.0.0
 	github.com/google/go-cmp v0.6.0
-	github.com/stretchr/testify v1.8.4
-	go.opentelemetry.io/otel v1.22.0
+	github.com/stretchr/testify v1.9.0
+	go.opentelemetry.io/otel v1.24.0
 	go.opentelemetry.io/otel/sdk v1.22.0
-	go.opentelemetry.io/otel/trace v1.22.0
+	go.opentelemetry.io/otel/trace v1.24.0
 	go.opentelemetry.io/proto/otlp v1.0.0
-	google.golang.org/protobuf v1.32.0
+	google.golang.org/protobuf v1.33.0
 )
 
 require (
@@ -37,18 +37,18 @@ require (
 	github.com/vishvananda/netlink v1.2.1-beta.2.0.20220608195807-1a118fe229fc // indirect
 	github.com/vishvananda/netns v0.0.4 // indirect
 	go.mongodb.org/mongo-driver v1.13.1 // indirect
-	go.opentelemetry.io/otel/metric v1.22.0 // indirect
+	go.opentelemetry.io/otel/metric v1.24.0 // indirect
 	go4.org/intern v0.0.0-20211027215823-ae77deb06f29 // indirect
 	go4.org/unsafe/assume-no-moving-gc v0.0.0-20230525183740-e7c30c78aeb2 // indirect
 	golang.org/x/arch v0.4.0 // indirect
 	golang.org/x/exp v0.0.0-20240119083558-1b970713d09a // indirect
 	golang.org/x/mod v0.16.0 // indirect
-	golang.org/x/net v0.22.0 // indirect
+	golang.org/x/net v0.23.0 // indirect
 	golang.org/x/sys v0.18.0 // indirect
 	golang.org/x/text v0.14.0 // indirect
-	google.golang.org/genproto/googleapis/api v0.0.0-20240116215550-a9fa1716bcac // indirect
-	google.golang.org/genproto/googleapis/rpc v0.0.0-20240116215550-a9fa1716bcac // indirect
-	google.golang.org/grpc v1.61.0 // indirect
+	google.golang.org/genproto/googleapis/api v0.0.0-20240311132316-a219d84964c2 // indirect
+	google.golang.org/genproto/googleapis/rpc v0.0.0-20240314234333-6e1732d8331c // indirect
+	google.golang.org/grpc v1.62.1 // indirect
 	gopkg.in/alecthomas/kingpin.v2 v2.2.6 // indirect
 	gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
 	gopkg.in/yaml.v3 v3.0.1 // indirect

+ 6 - 0
pkg/go.opentelemetry.io/otel/exporters/otlp/otlptrace/go.sum

@@ -72,6 +72,7 @@ github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81P
 github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
 github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
 github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
+github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
 github.com/vishvananda/netlink v1.2.1-beta.2.0.20220608195807-1a118fe229fc h1:2wzJ1cBcM23GetRJs2y6ETXrFMvp6HefTbFWtqviHZQ=
 github.com/vishvananda/netlink v1.2.1-beta.2.0.20220608195807-1a118fe229fc/go.mod h1:twkDnbuQxJYemMlGd4JFIcuhgX83tXhKS2B/PRMpOho=
 github.com/vishvananda/netns v0.0.0-20200728191858-db3c7e526aae/go.mod h1:DD4vA1DwXk04H54A1oHXtwZmA0grkVMdPxx/VGLCah0=
@@ -115,6 +116,7 @@ golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qx
 golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
 golang.org/x/net v0.22.0 h1:9sGLhx7iRIHEiX0oAJ3MRZMUCElJgy7Br1nO+AMN3Tc=
 golang.org/x/net v0.22.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
+golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
 golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
 golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
 golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
@@ -154,14 +156,18 @@ google.golang.org/genproto v0.0.0-20240102182953-50ed04b92917 h1:nz5NESFLZbJGPFx
 google.golang.org/genproto v0.0.0-20240102182953-50ed04b92917/go.mod h1:pZqR+glSb11aJ+JQcczCvgf47+duRuzNSKqE8YAQnV0=
 google.golang.org/genproto/googleapis/api v0.0.0-20240116215550-a9fa1716bcac h1:OZkkudMUu9LVQMCoRUbI/1p5VCo9BOrlvkqMvWtqa6s=
 google.golang.org/genproto/googleapis/api v0.0.0-20240116215550-a9fa1716bcac/go.mod h1:B5xPO//w8qmBDjGReYLpR6UJPnkldGkCSMoH/2vxJeg=
+google.golang.org/genproto/googleapis/api v0.0.0-20240311132316-a219d84964c2/go.mod h1:O1cOfN1Cy6QEYr7VxtjOyP5AdAuR0aJ/MYZaaof623Y=
 google.golang.org/genproto/googleapis/rpc v0.0.0-20240116215550-a9fa1716bcac h1:nUQEQmH/csSvFECKYRv6HWEyypysidKl2I6Qpsglq/0=
 google.golang.org/genproto/googleapis/rpc v0.0.0-20240116215550-a9fa1716bcac/go.mod h1:daQN87bsDqDoe316QbbvX60nMoJQa4r6Ds0ZuoAe5yA=
+google.golang.org/genproto/googleapis/rpc v0.0.0-20240314234333-6e1732d8331c/go.mod h1:WtryC6hu0hhx87FDGxWCDptyssuo68sk10vYjF+T9fY=
 google.golang.org/grpc v1.61.0 h1:TOvOcuXn30kRao+gfcvsebNEa5iZIiLkisYEkf7R7o0=
 google.golang.org/grpc v1.61.0/go.mod h1:VUbo7IFqmF1QtCAstipjG0GIoq49KvMe9+h1jFLBNJs=
+google.golang.org/grpc v1.62.1/go.mod h1:IWTG0VlJLCh1SkC58F7np9ka9mx/WNkjl4PGJaiq+QE=
 google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
 google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
 google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I=
 google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
+google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
 gopkg.in/alecthomas/kingpin.v2 v2.2.6 h1:jMFz6MfLP0/4fUyZle81rXUoxOBFi19VUFKVDOQfozc=
 gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
 gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=

+ 9 - 9
pkg/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/go.mod

@@ -7,14 +7,14 @@ toolchain go1.21.3
 require (
 	github.com/cenkalti/backoff/v4 v4.2.1
 	github.com/coroot/coroot-node-agent v0.0.0
-	github.com/stretchr/testify v1.8.4
-	go.opentelemetry.io/otel v1.22.0
+	github.com/stretchr/testify v1.9.0
+	go.opentelemetry.io/otel v1.24.0
 	go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.22.0
 	go.opentelemetry.io/otel/sdk v1.22.0
-	go.opentelemetry.io/otel/trace v1.22.0
+	go.opentelemetry.io/otel/trace v1.24.0
 	go.opentelemetry.io/proto/otlp v1.0.0
-	google.golang.org/grpc v1.61.0
-	google.golang.org/protobuf v1.32.0
+	google.golang.org/grpc v1.62.1
+	google.golang.org/protobuf v1.33.0
 )
 
 require (
@@ -37,17 +37,17 @@ require (
 	github.com/vishvananda/netlink v1.2.1-beta.2.0.20220608195807-1a118fe229fc // indirect
 	github.com/vishvananda/netns v0.0.4 // indirect
 	go.mongodb.org/mongo-driver v1.13.1 // indirect
-	go.opentelemetry.io/otel/metric v1.22.0 // indirect
+	go.opentelemetry.io/otel/metric v1.24.0 // indirect
 	go4.org/intern v0.0.0-20211027215823-ae77deb06f29 // indirect
 	go4.org/unsafe/assume-no-moving-gc v0.0.0-20230525183740-e7c30c78aeb2 // indirect
 	golang.org/x/arch v0.4.0 // indirect
 	golang.org/x/exp v0.0.0-20240119083558-1b970713d09a // indirect
 	golang.org/x/mod v0.16.0 // indirect
-	golang.org/x/net v0.22.0 // indirect
+	golang.org/x/net v0.23.0 // indirect
 	golang.org/x/sys v0.18.0 // indirect
 	golang.org/x/text v0.14.0 // indirect
-	google.golang.org/genproto/googleapis/api v0.0.0-20240116215550-a9fa1716bcac // indirect
-	google.golang.org/genproto/googleapis/rpc v0.0.0-20240116215550-a9fa1716bcac // indirect
+	google.golang.org/genproto/googleapis/api v0.0.0-20240311132316-a219d84964c2 // indirect
+	google.golang.org/genproto/googleapis/rpc v0.0.0-20240314234333-6e1732d8331c // indirect
 	gopkg.in/alecthomas/kingpin.v2 v2.2.6 // indirect
 	gopkg.in/yaml.v3 v3.0.1 // indirect
 	inet.af/netaddr v0.0.0-20230525184311-b8eac61e914a // indirect

+ 6 - 0
pkg/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/go.sum

@@ -72,6 +72,7 @@ github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81P
 github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
 github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
 github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
+github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
 github.com/vishvananda/netlink v1.2.1-beta.2.0.20220608195807-1a118fe229fc h1:2wzJ1cBcM23GetRJs2y6ETXrFMvp6HefTbFWtqviHZQ=
 github.com/vishvananda/netlink v1.2.1-beta.2.0.20220608195807-1a118fe229fc/go.mod h1:twkDnbuQxJYemMlGd4JFIcuhgX83tXhKS2B/PRMpOho=
 github.com/vishvananda/netns v0.0.0-20200728191858-db3c7e526aae/go.mod h1:DD4vA1DwXk04H54A1oHXtwZmA0grkVMdPxx/VGLCah0=
@@ -115,6 +116,7 @@ golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qx
 golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
 golang.org/x/net v0.22.0 h1:9sGLhx7iRIHEiX0oAJ3MRZMUCElJgy7Br1nO+AMN3Tc=
 golang.org/x/net v0.22.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
+golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
 golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
 golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
 golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
@@ -154,14 +156,18 @@ google.golang.org/genproto v0.0.0-20240102182953-50ed04b92917 h1:nz5NESFLZbJGPFx
 google.golang.org/genproto v0.0.0-20240102182953-50ed04b92917/go.mod h1:pZqR+glSb11aJ+JQcczCvgf47+duRuzNSKqE8YAQnV0=
 google.golang.org/genproto/googleapis/api v0.0.0-20240116215550-a9fa1716bcac h1:OZkkudMUu9LVQMCoRUbI/1p5VCo9BOrlvkqMvWtqa6s=
 google.golang.org/genproto/googleapis/api v0.0.0-20240116215550-a9fa1716bcac/go.mod h1:B5xPO//w8qmBDjGReYLpR6UJPnkldGkCSMoH/2vxJeg=
+google.golang.org/genproto/googleapis/api v0.0.0-20240311132316-a219d84964c2/go.mod h1:O1cOfN1Cy6QEYr7VxtjOyP5AdAuR0aJ/MYZaaof623Y=
 google.golang.org/genproto/googleapis/rpc v0.0.0-20240116215550-a9fa1716bcac h1:nUQEQmH/csSvFECKYRv6HWEyypysidKl2I6Qpsglq/0=
 google.golang.org/genproto/googleapis/rpc v0.0.0-20240116215550-a9fa1716bcac/go.mod h1:daQN87bsDqDoe316QbbvX60nMoJQa4r6Ds0ZuoAe5yA=
+google.golang.org/genproto/googleapis/rpc v0.0.0-20240314234333-6e1732d8331c/go.mod h1:WtryC6hu0hhx87FDGxWCDptyssuo68sk10vYjF+T9fY=
 google.golang.org/grpc v1.61.0 h1:TOvOcuXn30kRao+gfcvsebNEa5iZIiLkisYEkf7R7o0=
 google.golang.org/grpc v1.61.0/go.mod h1:VUbo7IFqmF1QtCAstipjG0GIoq49KvMe9+h1jFLBNJs=
+google.golang.org/grpc v1.62.1/go.mod h1:IWTG0VlJLCh1SkC58F7np9ka9mx/WNkjl4PGJaiq+QE=
 google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
 google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
 google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I=
 google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
+google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
 gopkg.in/alecthomas/kingpin.v2 v2.2.6 h1:jMFz6MfLP0/4fUyZle81rXUoxOBFi19VUFKVDOQfozc=
 gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
 gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=

+ 35 - 3
tracing/tracing.go

@@ -4,7 +4,10 @@ import (
 	"context"
 	"crypto/tls"
 	"fmt"
-
+	"github.com/coroot/coroot-node-agent/config"
+	"github.com/coroot/coroot-node-agent/utils"
+	"github.com/coroot/coroot-node-agent/utils/try"
+	"net/url"
 	"sync"
 	"time"
 
@@ -29,11 +32,34 @@ const (
 )
 
 var (
-	tracer func(containerId string) trace.Tracer
+	tracer            func(containerId string) trace.Tracer
+	watchEndpointOnce sync.Once
 )
 
+func getTracesEndpoint() *url.URL {
+	var u *url.URL
+	if *flags.TracesEndpoint != nil {
+		u = *flags.TracesEndpoint
+	} else {
+		dataServer, err := url.Parse(config.Cfg.GetString("dataServer"))
+		if err == nil && dataServer != nil {
+			u = dataServer.JoinPath(*flags.ServerPrefix + "/api/v2/data/receive")
+		}
+	}
+	return u
+}
+
+func watchTracesEndpoint(machineId, hostname, version string) {
+	for range config.Cfg.SubscribeConfigChange(config.ScbTypeTracesEndpointChg) {
+		klog.Infof("OpenTelemetry endpoint changed (the configuration `dataServer`),new dataServer [%s]", config.Cfg.GetString("dataServer"))
+		Init(machineId, hostname, version)
+		klog.Infoln("OpenTelemetry endpoint change finished")
+	}
+	klog.Infof("SubscribeConfigChange ScbTypeTracesEndpointChg exit")
+}
+
 func Init(machineId, hostname, version string) {
-	endpointUrl := *flags.TracesEndpoint
+	endpointUrl := getTracesEndpoint()
 	if endpointUrl == nil {
 		klog.Infoln("no OpenTelemetry traces collector endpoint configured")
 		return
@@ -73,6 +99,12 @@ func Init(machineId, hostname, version string) {
 		)
 		return provider.Tracer("coroot-node-agent", trace.WithInstrumentationVersion(version))
 	}
+
+	watchEndpointOnce.Do(func() {
+		if *flags.TracesEndpoint == nil {
+			try.GoParams(watchTracesEndpoint, utils.CatchFn, machineId, hostname, version)
+		}
+	})
 }
 
 type Trace struct {

+ 3 - 1
utils/enums/enums.go

@@ -29,5 +29,7 @@ const (
 	DefaultLocalFilePort   = "18086"
 	DefaultVpcKey          = "identification"
 
-	TimeoutNamedPipe3S = 3
+	TimeoutNamedPipe3S         = 3
+	DefaultLogLevel            = "error"
+	DefaultNetDataInterval1Min = 1
 )

+ 8 - 4
utils/util.go

@@ -478,9 +478,9 @@ func GetDefaultPath(path_name ...string) string {
 	return filepath.Join(agentdaemon_home, filepath.Join(path_name...))
 }
 
-func GetDefaultConfigPath() string {
+/*func GetDefaultConfigPath() string {
 	return GetDefaultPath(ConfPath, ConfName)
-}
+}*/
 
 func GetDefaultLogPath() string {
 	return GetDefaultPath(LogsPath)
@@ -521,6 +521,10 @@ func GetPluginInstallParamsPath(pluginId string) string {
 	return GetDefaultPath(ConfPath, "agents-installation", pluginId)
 }
 
+func GetDefaultConfPath() string {
+	return GetDefaultPath(ConfPath)
+}
+
 func CatchFn(err interface{}) {
 	log.Errorf(fmt.Sprintf("panic : %s\n", err))
 	log.Errorf(fmt.Sprint(string(debug.Stack())))
@@ -554,7 +558,7 @@ func DecodeAccountUser(token string) (string, string) {
 /**
  * 读取原配置项
  */
-func GetOriginConfig() (map[string]interface{}, error) {
+/*func GetOriginConfig() (map[string]interface{}, error) {
 	configMap := make(map[string]interface{})
 	content, err := ioutil.ReadFile(GetDefaultConfigPath())
 	if err != nil {
@@ -563,7 +567,7 @@ func GetOriginConfig() (map[string]interface{}, error) {
 	err = json.Unmarshal(content, &configMap)
 	return configMap, err
 }
-
+*/
 func Capitalize(str string) string {
 	if len(str) == 0 {
 		return str