| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- 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 {
- if c.AppInfo.CodeType.IsUnknownCode() || c.AppInfo.CodeType.IsWaitCheck() {
- return fmt.Errorf("[register app] Unknown app code[%s],Wait buildIDs.", c.AppInfo.CodeType.String())
- }
- //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 app] Register App req: %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()
- }
- }
- c.AppInfo.AppSuccess()
- return nil
- }
|