metric.go 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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. "yunion.io/x/pkg/util/sets"
  17. "yunion.io/x/onecloud/pkg/apis"
  18. )
  19. const EXT_PREFIX = "ext"
  20. const (
  21. METRIC_RES_TYPE_GUEST = "guest"
  22. METRIC_RES_TYPE_HOST = "host"
  23. METRIC_RES_TYPE_REDIS = "redis"
  24. METRIC_RES_TYPE_OSS = "oss"
  25. METRIC_RES_TYPE_RDS = "rds"
  26. METRIC_RES_TYPE_CLOUDACCOUNT = "cloudaccount"
  27. METRIC_RES_TYPE_AGENT = "agent"
  28. METRIC_RES_TYPE_TENANT = "tenant"
  29. METRIC_RES_TYPE_DOMAIN = "domain"
  30. METRIC_RES_TYPE_STORAGE = "storage"
  31. METRIC_RES_TYPE_ELB = "elb"
  32. METRIC_RES_TYPE_K8S = "k8s"
  33. METRIC_RES_TYPE_CONTAINER = "container"
  34. METRIC_RES_TYPE_SYSTEM = "system"
  35. //ext is prefix!
  36. METRIC_RES_TYPE_JENKINS = "ext_jenkins"
  37. METRIC_RES_TYPE_EXT_MYSQL = "ext_mysql"
  38. METRIC_RES_TYPE_EXT_REDIS = "ext_redis"
  39. METRIC_RES_TYPE_EXT_RABBITMQ = "ext_rabbitmq"
  40. METRIC_UNIT_PERCENT = "%"
  41. METRIC_UNIT_BPS = "bps"
  42. METRIC_UNIT_PPS = "pps"
  43. METRIC_UNIT_MBPS = "Mbps"
  44. METRIC_UNIT_BYTEPS = "Bps"
  45. METRIC_UNIT_CPS = "cps"
  46. METRIC_UNIT_COUNT = "count"
  47. METRIC_UNIT_MS = "ms"
  48. METRIC_UNIT_SEC = "s"
  49. METRIC_UNIT_BYTE = "byte"
  50. METRIC_UNIT_MB = "Mb"
  51. METRIC_UNIT_NULL = "NULL"
  52. METRIC_DATABASE_TELE = "telegraf"
  53. METRIC_DATABASE_METER = "meter_db"
  54. METRIC_DATABASE_SYSTEM = "system"
  55. )
  56. var (
  57. MetricCloudResTypes = sets.NewString(
  58. METRIC_RES_TYPE_HOST,
  59. METRIC_RES_TYPE_AGENT,
  60. METRIC_RES_TYPE_GUEST,
  61. METRIC_RES_TYPE_CONTAINER,
  62. METRIC_RES_TYPE_OSS,
  63. METRIC_RES_TYPE_RDS,
  64. METRIC_RES_TYPE_REDIS,
  65. METRIC_RES_TYPE_TENANT,
  66. METRIC_RES_TYPE_DOMAIN,
  67. METRIC_RES_TYPE_STORAGE,
  68. METRIC_RES_TYPE_CLOUDACCOUNT)
  69. MetricResType = []string{METRIC_RES_TYPE_GUEST, METRIC_RES_TYPE_HOST, METRIC_RES_TYPE_REDIS, METRIC_RES_TYPE_OSS,
  70. METRIC_RES_TYPE_RDS, METRIC_RES_TYPE_CLOUDACCOUNT}
  71. MetricUnit = []string{METRIC_UNIT_PERCENT, METRIC_UNIT_BPS, METRIC_UNIT_MBPS, METRIC_UNIT_BYTEPS, "count/s",
  72. METRIC_UNIT_COUNT, METRIC_UNIT_MS, METRIC_UNIT_BYTE, METRIC_UNIT_NULL}
  73. ResTypeScoreMap = map[string]float64{
  74. METRIC_RES_TYPE_HOST: -100,
  75. METRIC_RES_TYPE_GUEST: -99,
  76. METRIC_RES_TYPE_AGENT: -98,
  77. METRIC_RES_TYPE_CONTAINER: -97,
  78. METRIC_RES_TYPE_SYSTEM: -96,
  79. METRIC_RES_TYPE_K8S: -95,
  80. METRIC_RES_TYPE_ELB: -94,
  81. METRIC_RES_TYPE_CLOUDACCOUNT: -93,
  82. METRIC_RES_TYPE_STORAGE: -93,
  83. }
  84. )
  85. type MetricMeasurementCreateInput struct {
  86. apis.StandaloneResourceCreateInput
  87. apis.EnabledBaseResourceCreateInput
  88. ResType string `json:"res_type"`
  89. DisplayName string `json:"display_name"`
  90. Database string `json:"database"`
  91. Score int `json:"score"`
  92. }
  93. type MetricMeasurementUpdateInput struct {
  94. apis.StandaloneResourceBaseUpdateInput
  95. ResType string `json:"res_type"`
  96. DisplayName string `json:"display_name"`
  97. }
  98. type MetricMeasurementListInput struct {
  99. apis.StatusStandaloneResourceListInput
  100. apis.EnabledResourceBaseListInput
  101. apis.ScopedResourceBaseListInput
  102. ResType string `json:"res_type"`
  103. DisplayName string `json:"display_name"`
  104. }
  105. type MetricFieldCreateInput struct {
  106. apis.StandaloneResourceCreateInput
  107. DisplayName string `json:"display_name"`
  108. Unit string `json:"unit"`
  109. ValueType string `json:"value_type"`
  110. Score int `json:"score"`
  111. }
  112. type MetricFieldUpdateInput struct {
  113. apis.StandaloneResourceBaseUpdateInput
  114. Id string `json:"id"`
  115. DisplayName string `json:"display_name"`
  116. Unit string `json:"unit"`
  117. ValueType string `json:"value_type"`
  118. Score int `json:"score"`
  119. }
  120. type MetricFieldListInput struct {
  121. apis.StatusStandaloneResourceListInput
  122. apis.EnabledResourceBaseListInput
  123. apis.ScopedResourceBaseListInput
  124. DisplayName string `json:"display_name"`
  125. Unit string `json:"unit"`
  126. Scope string `json:"scope"`
  127. }
  128. type MetricCreateInput struct {
  129. Measurement MetricMeasurementCreateInput `json:"measurement"`
  130. MetricFields []MetricFieldCreateInput `json:"metric_fields"`
  131. Scope string `json:"scope"`
  132. }
  133. type MetricUpdateInput struct {
  134. apis.Meta
  135. Measurement MetricMeasurementUpdateInput `json:"measurement"`
  136. MetricFields []MetricFieldUpdateInput `json:"metric_fields"`
  137. Scope string `json:"scope"`
  138. }
  139. type MetricListInput struct {
  140. apis.Meta
  141. Measurement MetricMeasurementListInput `json:"measurement"`
  142. MetricFields MetricFieldListInput `json:"metric_fields"`
  143. Scope string `json:"scope"`
  144. }
  145. type MetricDetails struct {
  146. apis.StatusStandaloneResourceDetails
  147. apis.ScopedResourceBaseInfo
  148. MetricFields []MetricFieldDetail `json:"metric_fields"`
  149. }
  150. type MetricFieldDetail struct {
  151. Name string `json:"name"`
  152. DisplayName string `json:"display_name"`
  153. Unit string `json:"unit"`
  154. Id string `json:"id"`
  155. }
  156. type InfluxMeasurement struct {
  157. apis.Meta
  158. Database string `json:"database"`
  159. Measurement string `json:"measurement"`
  160. MeasurementDisplayName string `json:"measurement_display_name"`
  161. ResType string `json:"res_type"`
  162. Score int `json:"score"`
  163. TagKey []string `json:"tag_key"`
  164. TagValue map[string][]string `json:"tag_value"`
  165. FieldKey []string `json:"field_key"`
  166. FieldDescriptions map[string]MetricFieldDetail `json:"field_descriptions"`
  167. Unit []string `json:"unit"`
  168. }