apm_register_app.go 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. package containers
  2. import (
  3. "fmt"
  4. "github.com/coroot/coroot-node-agent/utils"
  5. . "github.com/coroot/coroot-node-agent/utils/modelse"
  6. klog "github.com/sirupsen/logrus"
  7. )
  8. func (c *Container) RegisterAppInfo(r *Registry, pid uint32) error {
  9. if c.WhiteSettingInfo.AppName == "" {
  10. return fmt.Errorf("AppName is empty")
  11. }
  12. var err error
  13. originAppName := c.AppInfo.AppName
  14. whiteAppName := c.WhiteSettingInfo.AppName
  15. if originAppName != whiteAppName {
  16. c.AppInfo.AppId, err = utils.BuildInt64ID(whiteAppName).ToInt64()
  17. if err != nil {
  18. return err
  19. }
  20. c.AppInfo.ServiceName = c.AppInfo.CodeType.ServiceTypeString()
  21. // 注册
  22. hostId, _ := utils.GetHostID()
  23. registerAppReq := RegisterAppReq{
  24. AppId: c.AppInfo.AppId,
  25. AppName: c.WhiteSettingInfo.AppName,
  26. AccountId: 110,
  27. AgentId: c.AppInfo.AgentId,
  28. Sn: c.AppInfo.Sn,
  29. Sport: c.AppInfo.Sport,
  30. ServiceType: c.AppInfo.ServiceName,
  31. CodeType: c.AppInfo.CodeType.Int(),
  32. App_type: 1,
  33. HostId: hostId,
  34. }
  35. klog.Infof("Register App: %s", registerAppReq.String())
  36. err = r.connServer.RegisterApp(registerAppReq)
  37. if err != nil {
  38. klog.WithError(err).Errorf("Failed Register App %s", registerAppReq.String())
  39. return err
  40. }
  41. c.AppInfo.AppName = c.WhiteSettingInfo.AppName
  42. }
  43. // ip:port + process_name + exe路径生成
  44. //c.instanceID.IntVal + proc.GetExe(pid)
  45. //c.AppInfo.AgentId =
  46. return nil
  47. }
  48. func (c *Container) TestRegisterAppInfo(r *Registry) error {
  49. var err error
  50. c.AppInfo.AppName = "eBPF-APP"
  51. c.AppInfo.AppId, err = utils.BuildInt64ID(c.AppInfo.AppName).ToInt64()
  52. if err != nil {
  53. return err
  54. }
  55. c.AppInfo.ServiceName = c.AppInfo.CodeType.ServiceTypeString()
  56. // 注册
  57. hostId, _ := utils.GetHostID()
  58. registerAppReq := RegisterAppReq{
  59. AppId: c.AppInfo.AppId,
  60. AppName: c.AppInfo.AppName,
  61. AccountId: 110,
  62. AgentId: c.AppInfo.AgentId,
  63. Sn: c.AppInfo.Sn,
  64. Sport: c.AppInfo.Sport,
  65. ServiceType: c.AppInfo.ServiceName,
  66. CodeType: c.AppInfo.CodeType.Int(),
  67. App_type: 1,
  68. HostId: hostId,
  69. }
  70. registerAppReq.Print()
  71. err = r.connServer.RegisterApp(registerAppReq)
  72. if err != nil {
  73. return err
  74. }
  75. // ip:port + process_name + exe路径生成
  76. //c.instanceID.IntVal + proc.GetExe(pid)
  77. //c.AppInfo.AgentId =
  78. return nil
  79. }