package containers import ( "fmt" "github.com/coroot/coroot-node-agent/utils" . "github.com/coroot/coroot-node-agent/utils/modelse" klog "github.com/sirupsen/logrus" "time" ) func (c *Container) RegisterAppInfo(r *Registry, pid uint32) error { if c.WhiteSettingInfo.AppName == "" { return fmt.Errorf("appname is empty.") } var err error originAppName := c.AppInfo.AppName whiteAppName := c.WhiteSettingInfo.AppName if originAppName != whiteAppName { //c.AppInfo.AppId, err = utils.BuildInt64ID(whiteAppName).ToInt64() c.AppInfo.AppIdHash.IntVal, err = utils.BuildInt64ID(whiteAppName).ToInt64() c.AppInfo.AppIdHash.HashtVal = utils.BuildInt64ID(whiteAppName).ToHashByte() if err != nil { return err } c.AppInfo.ServiceName = c.AppInfo.CodeType.ServiceTypeString() // 注册 hostId, _ := utils.GetHostID() registerAppReq := RegisterAppReq{ AppId: c.AppInfo.AppIdHash.IntVal, AppName: c.WhiteSettingInfo.AppName, // todo AccountId AccountId: utils.GetAccountID(), AgentId: c.AppInfo.AgentId, Sn: c.AppInfo.Sn, Sport: c.AppInfo.Sport, ServiceType: c.AppInfo.ServiceName, CodeType: c.AppInfo.CodeType.Int(), App_type: 1, HostId: hostId, } klog.Infof("[register] Register App: %s.", registerAppReq.String()) err = r.connServer.RegisterApp(registerAppReq) if err != nil { klog.WithError(err).Errorf("[register] Failed Register App %s.", registerAppReq.String()) return err } c.AppInfo.AppName = c.WhiteSettingInfo.AppName if originAppName == "" { c.AppInfo.RegisterAt = time.Now().Unix() } if originAppName != "" && c.checkL7AttachReady() { klog.Infoln("[kprobe] reset kernel proc_info.") err = r.tracer.InitKProcInfo(pid, &c.AppInfo) if err != nil { klog.WithError(err).Errorf("[kprobe] Failed reset KProcInfo.") return err } c.AppInfo.UpdateAt = time.Now().Unix() } } return nil }