app_info.go 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. package modelse
  2. import "time"
  3. const (
  4. APP_NAME = "app_name"
  5. APP_ID = "app_id"
  6. AGENT_ID = "agent_id"
  7. INSTANCE_ID = "instance_id"
  8. )
  9. type APP_TYPE int
  10. const (
  11. APP_WAIT APP_TYPE = iota
  12. APP_SUCCESS
  13. APP_UPROBE_ERROR
  14. APP_STACK_ERROR
  15. APP_UNINSTALL
  16. APP_UNINSTALL_ERROR
  17. APP_FUSE
  18. APP_FUSE_ERROR
  19. APP_LICENSE_FUSE
  20. APP_LICENSE_FUSE_ERROR
  21. )
  22. const (
  23. TRACE_STATUS = 200
  24. )
  25. func (s APP_TYPE) Error() APP_TYPE {
  26. switch s {
  27. case APP_UNINSTALL:
  28. return APP_UNINSTALL_ERROR
  29. case APP_FUSE:
  30. return APP_FUSE_ERROR
  31. case APP_LICENSE_FUSE:
  32. return APP_LICENSE_FUSE_ERROR
  33. default:
  34. return APP_UPROBE_ERROR
  35. }
  36. }
  37. func (s APP_TYPE) IsSuccess() bool {
  38. if s == APP_SUCCESS {
  39. return true
  40. }
  41. return false
  42. }
  43. func (s APP_TYPE) IsError() bool {
  44. switch s {
  45. case APP_UNINSTALL_ERROR:
  46. case APP_FUSE_ERROR:
  47. case APP_LICENSE_FUSE_ERROR:
  48. case APP_UPROBE_ERROR:
  49. return true
  50. default:
  51. return false
  52. }
  53. return false
  54. }
  55. func (s APP_TYPE) String() string {
  56. switch s {
  57. case APP_SUCCESS:
  58. return "SUCCESS"
  59. case APP_UPROBE_ERROR:
  60. return "UPROBE ERROR"
  61. case APP_UNINSTALL:
  62. return "UNINSTALL"
  63. case APP_FUSE:
  64. return "FUSE"
  65. case APP_LICENSE_FUSE:
  66. return "LICENSE FUSE"
  67. default:
  68. return "-"
  69. }
  70. }
  71. type AppInfo struct {
  72. AppName string `json:"app_name"`
  73. AppIdHash INT_HASH_ID `json:"app_id_hash"`
  74. InstanceIdHash INT_HASH_ID `json:"instance_id_hash"`
  75. AgentId int64 `json:"agent_id"`
  76. Sn string `json:"sn"`
  77. Sport int `json:"sport"`
  78. ServiceType string `json:"service_name"`
  79. CodeType CodeType `json:"code_type"`
  80. EBPFProcInfo *EbpfProcInfo `json:"ebpf_proc_info"`
  81. RegisterAt int64 `json:"register_at"`
  82. UpdateAt int64 `json:"update_at"`
  83. PreStatus APP_TYPE `json:"pre_status"`
  84. Status APP_TYPE `json:"status"`
  85. Version string `json:"version"`
  86. GoProcCache ProcOnce `json:"go_proc_cache"`
  87. }
  88. type ProcOnce struct {
  89. StartAddr uint64 `json:"start_addr"`
  90. EndAddr uint64 `json:"end_addr"`
  91. }
  92. func (a *AppInfo) UpdateAtTime() {
  93. a.UpdateAt = time.Now().Unix()
  94. }
  95. func (a *AppInfo) SetAppStatus(status APP_TYPE) {
  96. a.PreStatus = a.Status
  97. a.Status = status
  98. a.UpdateAtTime()
  99. }
  100. func (a *AppInfo) SetAppSuccess() {
  101. if !a.Status.IsSuccess() {
  102. a.SetAppStatus(APP_SUCCESS)
  103. }
  104. }
  105. func (a *AppInfo) SetAppStackError() {
  106. a.SetAppStatus(APP_STACK_ERROR)
  107. }
  108. func (a *AppInfo) AppUninstall() {
  109. a.SetAppStatus(APP_UNINSTALL)
  110. }