alertrecord.go 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. // Copyright 2019 Yunion
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package monitor
  15. import (
  16. "time"
  17. "yunion.io/x/onecloud/pkg/apis"
  18. )
  19. const (
  20. SEND_STATE_OK = "ok"
  21. SEND_STATE_SILENT = "silent"
  22. SEND_STATE_SHIELD = "shield"
  23. )
  24. type AlertRecordListInput struct {
  25. apis.Meta
  26. apis.ScopedResourceBaseListInput
  27. apis.EnabledResourceBaseListInput
  28. apis.StatusStandaloneResourceListInput
  29. AlertId string `json:"alert_id"`
  30. AlertName string `json:"alert_name"`
  31. Level string `json:"level"`
  32. State string `json:"state"`
  33. ResType string `json:"res_type"`
  34. Alerting bool `json:"alerting"`
  35. ResName string `json:"res_name"`
  36. ResId string `json:"res_id"`
  37. }
  38. type AlertRecordDetails struct {
  39. SAlertRecord
  40. apis.StandaloneAnonResourceDetails
  41. apis.ScopedResourceBaseInfo
  42. ResNum int64 `json:"res_num"`
  43. AlertName string `json:"alert_name"`
  44. TriggerTime time.Time `json:"trigger_time"`
  45. }
  46. type AlertRecordCreateInput struct {
  47. apis.StandaloneResourceCreateInput
  48. AlertId string `json:"alert_id"`
  49. // 报警级别
  50. Level string `json:"level"`
  51. State string `json:"state"`
  52. SendState string `json:"send_state"`
  53. ResType string `json:"res_type"`
  54. EvalData []*EvalMatch `json:"eval_data"`
  55. AlertRule []*AlertRecordRule `json:"alert_rule"`
  56. }
  57. type AlertRecordRule struct {
  58. Metric string `json:"metric"`
  59. Database string `json:"database"`
  60. Measurement string `json:"measurement"`
  61. MeasurementDesc string `json:"measurement_desc"`
  62. ResType string `json:"res_type"`
  63. Field string `json:"field"`
  64. FieldDesc string `json:"field_desc"`
  65. // 比较运算符, 比如: >, <, >=, <=
  66. Comparator string `json:"comparator"`
  67. // 报警阀值
  68. Threshold string `json:"threshold"`
  69. ThresholdRange []float64 `json:"threshold_range"`
  70. Unit string `json:"unit"`
  71. Period string `json:"period"`
  72. AlertDuration int64 `json:"alert_duration"`
  73. ConditionType string `json:"condition_type"`
  74. // 静默期
  75. SilentPeriod string `json:"silent_period"`
  76. Reducer string `json:"reducer"`
  77. }
  78. type AlertRecordHistoryAlertData struct {
  79. ProjectId string `json:"project_id"`
  80. Project string `json:"project"`
  81. DomainId string `json:"domain_id"`
  82. Domain string `json:"domain"`
  83. ResType string `json:"res_type"`
  84. ResNum int64 `json:"res_num"`
  85. }
  86. func (self AlertRecordHistoryAlertData) GetMetricTags() map[string]string {
  87. return map[string]string{
  88. "tenant_id": self.ProjectId,
  89. "domain_id": self.DomainId,
  90. "domain": self.Domain,
  91. "tenant": self.Project,
  92. "res_type": self.ResType,
  93. }
  94. }
  95. type AlertRecordHistoryAlert struct {
  96. Data []AlertRecordHistoryAlertData `json:"data"`
  97. }
  98. // ProjectAlertResourceCountData 报警资源统计数据(按 scope 分类)
  99. type ProjectAlertResourceCountData struct {
  100. Scope string `json:"scope"` // system/domain/project
  101. DomainId string `json:"domain_id"` // 域ID(domain/project scope 时有效)
  102. Domain string `json:"domain"` // 域名称(domain/project scope 时有效)
  103. ProjectId string `json:"project_id"` // 项目ID(project scope 时有效)
  104. Project string `json:"project"` // 项目名称(project scope 时有效)
  105. ResCount int64 `json:"res_count"` // 报警资源数量
  106. }
  107. // ProjectAlertResourceCount 报警资源统计结果
  108. type ProjectAlertResourceCount struct {
  109. Data []ProjectAlertResourceCountData `json:"data"`
  110. }
  111. // ProjectAlertResourceCountInput 项目报警资源统计查询输入
  112. type ProjectAlertResourceCountInput struct {
  113. StartTime time.Time `json:"start_time"`
  114. EndTime time.Time `json:"end_time"`
  115. ResType string `json:"res_type"`
  116. AlertId string `json:"alert_id"`
  117. Scope string `json:"scope"`
  118. }