monitor.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. package monitor
  2. import (
  3. "fmt"
  4. "go-common/app/admin/main/videoup/model/archive"
  5. "go-common/app/admin/main/videoup/model/manager"
  6. )
  7. const (
  8. // RedisPrefix 参数:business。
  9. BusPrefix = "monitor_stats_%d_"
  10. // SuffixVideo 视频停留统计。参数:state
  11. SuffixVideo = "%d"
  12. // SuffixArc 稿件停留统计。参数:round。参数:state。
  13. SuffixArc = "%d_%d"
  14. RulesKey = "monitor_rules"
  15. RuleIDIncKey = "monitor_rule_inc_id"
  16. BusVideo int8 = 1
  17. BusArc int8 = 2
  18. RuleStateOK = 1
  19. RuleStateDisable = 0
  20. NotifyTypeEmail = 1
  21. NotityTypeSms = 2
  22. CompGT = ">"
  23. CompLT = "<"
  24. CompGET = ">="
  25. CompLET = "<="
  26. CompNE = "!="
  27. CompE = "="
  28. )
  29. var (
  30. // RedisKeyConf 监控业务的Redis Key配置
  31. RedisKeyConf = map[int8]*KeyConf{
  32. BusVideo: {
  33. KeyFormat: fmt.Sprintf(BusPrefix, BusVideo) + SuffixVideo,
  34. KFields: map[string][]int64{
  35. "state": {
  36. int64(archive.VideoStatusSubmit),
  37. int64(archive.VideoStatusWait),
  38. },
  39. },
  40. },
  41. BusArc: {
  42. KeyFormat: fmt.Sprintf(BusPrefix, BusArc) + SuffixArc,
  43. KFields: map[string][]int64{
  44. "round": {
  45. int64(archive.RoundAuditSecond),
  46. int64(archive.RoundAuditThird),
  47. int64(archive.RoundReviewFlow),
  48. int64(archive.RoundReviewFirst),
  49. int64(archive.RoundReviewFirstWaitTrigger),
  50. int64(archive.RoundReviewSecond),
  51. int64(archive.RoundTriggerClick),
  52. },
  53. "state": {
  54. int64(archive.StateForbidFixed),
  55. int64(archive.StateForbidWait),
  56. int64(archive.StateOpen),
  57. int64(archive.StateOrange),
  58. },
  59. },
  60. },
  61. }
  62. )
  63. type KeyConf struct {
  64. KeyFormat string
  65. KFields map[string][]int64
  66. }
  67. type RuleResultParams struct {
  68. Type int8 `form:"type" validate:"required"`
  69. Business int8 `form:"business" validate:"required"`
  70. //STime utils.FormatTime `form:"stime"`
  71. //ETime utils.FormatTime `form:"etime"`
  72. }
  73. type RuleResultData struct {
  74. Rule *Rule `json:"rule"`
  75. User *manager.User `json:"user"`
  76. Stats *Stats `json:"stats"`
  77. }
  78. // Rule 监控规则信息
  79. type Rule struct {
  80. ID int64 `json:"id"`
  81. Type int8 `json:"type"`
  82. Business int8 `json:"business"`
  83. Name string `json:"name"`
  84. State int8 `json:"state"`
  85. STime string `json:"s_time"`
  86. ETime string `json:"e_time"`
  87. RuleConf *RuleConf `json:"rule_conf"`
  88. UID int64 `json:"uid"`
  89. CTime string `json:"ctime"`
  90. }
  91. // RuleConf 监控方案配置结构体
  92. type RuleConf struct {
  93. Name string `json:"name"`
  94. MoniCdt map[string]struct { //监控方案的监控条件
  95. Comp string `json:"comparison"`
  96. Value int64 `json:"value"`
  97. } `json:"moni_cdt"`
  98. NotifyCdt map[string]struct { //达到发送通知的条件
  99. Comp string `json:"comparison"`
  100. Value int64 `json:"value"`
  101. } `json:"notify_cdt"`
  102. Notify struct { //通知类型配置
  103. Way int8 `json:"way"`
  104. Member []string `json:"member"`
  105. } `json:"notify"`
  106. }
  107. type Stats struct {
  108. TotalCount int `json:"total_count"`
  109. MoniCount int `json:"moni_count"`
  110. MaxTime int `json:"max_time"`
  111. }