pod.go 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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 measurements
  15. import (
  16. "fmt"
  17. "strings"
  18. "yunion.io/x/onecloud/pkg/apis/monitor"
  19. )
  20. var podCpu = SMeasurement{
  21. Context: []SMonitorContext{
  22. {
  23. Name: "pod_cpu",
  24. DisplayName: "Pod cpu",
  25. ResourceType: monitor.METRIC_RES_TYPE_CONTAINER,
  26. Database: monitor.METRIC_DATABASE_TELE,
  27. },
  28. },
  29. Metrics: []SMetric{
  30. {
  31. Name: "usage_rate",
  32. DisplayName: "Pod cpu usage rate",
  33. Unit: monitor.METRIC_UNIT_PERCENT,
  34. },
  35. },
  36. }
  37. var podGpu = SMeasurement{
  38. Context: []SMonitorContext{
  39. {
  40. Name: "pod_gpu",
  41. DisplayName: "Pod gpu",
  42. ResourceType: monitor.METRIC_RES_TYPE_CONTAINER,
  43. Database: monitor.METRIC_DATABASE_TELE,
  44. },
  45. },
  46. Metrics: []SMetric{
  47. {
  48. Name: "mem",
  49. DisplayName: "Pod gpu mem used",
  50. Unit: monitor.METRIC_UNIT_MB,
  51. },
  52. {
  53. Name: "mem_util",
  54. DisplayName: "Pod gpu mem usage",
  55. Unit: monitor.METRIC_UNIT_PERCENT,
  56. },
  57. },
  58. }
  59. var podMem = SMeasurement{
  60. Context: []SMonitorContext{
  61. {
  62. Name: "pod_mem",
  63. DisplayName: "Pod memory",
  64. ResourceType: monitor.METRIC_RES_TYPE_CONTAINER,
  65. Database: monitor.METRIC_DATABASE_TELE,
  66. },
  67. },
  68. Metrics: []SMetric{
  69. {
  70. Name: "usage_rate",
  71. DisplayName: "Pod memory usage rate",
  72. Unit: monitor.METRIC_UNIT_PERCENT,
  73. },
  74. {
  75. "working_set_rate",
  76. "Container memory working set usage rate",
  77. monitor.METRIC_UNIT_PERCENT,
  78. },
  79. {
  80. "usage_bytes",
  81. "Container memory usage bytes",
  82. monitor.METRIC_UNIT_BYTE,
  83. },
  84. {
  85. Name: "working_set_bytes",
  86. DisplayName: "Pod memory working set bytes",
  87. Unit: monitor.METRIC_UNIT_BYTE,
  88. },
  89. },
  90. }
  91. var podVolume = SMeasurement{
  92. Context: []SMonitorContext{
  93. {
  94. Name: "pod_volume",
  95. DisplayName: "Pod volume",
  96. ResourceType: monitor.METRIC_RES_TYPE_CONTAINER,
  97. Database: monitor.METRIC_DATABASE_TELE,
  98. },
  99. },
  100. Metrics: []SMetric{
  101. {
  102. Name: "free",
  103. DisplayName: "Pod volume free size",
  104. Unit: monitor.METRIC_UNIT_BYTE,
  105. },
  106. {
  107. Name: "used",
  108. DisplayName: "Pod volume used size",
  109. Unit: monitor.METRIC_UNIT_BYTE,
  110. },
  111. {
  112. Name: "used_percent",
  113. DisplayName: "Pod volume used percent",
  114. Unit: monitor.METRIC_UNIT_PERCENT,
  115. },
  116. {
  117. Name: "inodes_total",
  118. DisplayName: "Pod volume inodes total count",
  119. Unit: monitor.METRIC_UNIT_COUNT,
  120. },
  121. {
  122. Name: "inodes_free",
  123. DisplayName: "Pod volume inodes free count",
  124. Unit: monitor.METRIC_UNIT_COUNT,
  125. },
  126. {
  127. Name: "inodes_used",
  128. DisplayName: "Pod volume inodes used count",
  129. Unit: monitor.METRIC_UNIT_COUNT,
  130. },
  131. {
  132. Name: "inodes_used_percent",
  133. DisplayName: "Pod volume inodes used percent",
  134. Unit: monitor.METRIC_UNIT_PERCENT,
  135. },
  136. },
  137. }
  138. func newCadvisorProcessMetrics(displayType string) []SMetric {
  139. return []SMetric{
  140. {
  141. Name: "process_count",
  142. DisplayName: fmt.Sprintf("%s process count", displayType),
  143. Unit: monitor.METRIC_UNIT_COUNT,
  144. },
  145. {
  146. Name: "threads_current",
  147. DisplayName: fmt.Sprintf("%s threads currently count", displayType),
  148. Unit: monitor.METRIC_UNIT_COUNT,
  149. },
  150. {
  151. Name: "threads_max",
  152. DisplayName: fmt.Sprintf("Maximum number of threads allowed in %s", strings.ToLower(displayType)),
  153. Unit: monitor.METRIC_UNIT_COUNT,
  154. },
  155. {
  156. Name: "fd_count",
  157. DisplayName: fmt.Sprintf("%s open file descriptors count", displayType),
  158. Unit: monitor.METRIC_UNIT_COUNT,
  159. },
  160. {
  161. Name: "socket_count",
  162. DisplayName: fmt.Sprintf("%s sockets count", displayType),
  163. Unit: monitor.METRIC_UNIT_COUNT,
  164. },
  165. }
  166. }
  167. func newCadvisorDiskIoMetrics(displayType string) []SMetric {
  168. return []SMetric{
  169. {
  170. Name: "read_Bps",
  171. DisplayName: fmt.Sprintf("%s read bytes per second", displayType),
  172. Unit: monitor.METRIC_UNIT_BYTEPS,
  173. },
  174. {
  175. Name: "write_Bps",
  176. DisplayName: fmt.Sprintf("%s write bytes per second", displayType),
  177. Unit: monitor.METRIC_UNIT_BYTEPS,
  178. },
  179. {
  180. Name: "read_iops",
  181. DisplayName: fmt.Sprintf("%s read iops", displayType),
  182. Unit: monitor.METRIC_UNIT_COUNT,
  183. },
  184. {
  185. Name: "write_iops",
  186. DisplayName: fmt.Sprintf("%s write iops", displayType),
  187. Unit: monitor.METRIC_UNIT_COUNT,
  188. },
  189. {
  190. Name: "read_bytes",
  191. DisplayName: fmt.Sprintf("%s read bytes", displayType),
  192. Unit: monitor.METRIC_UNIT_BYTE,
  193. },
  194. {
  195. Name: "write_bytes",
  196. DisplayName: fmt.Sprintf("%s write bytes", displayType),
  197. Unit: monitor.METRIC_UNIT_BYTE,
  198. },
  199. {
  200. Name: "read_count",
  201. DisplayName: fmt.Sprintf("%s read count", displayType),
  202. Unit: monitor.METRIC_UNIT_COUNT,
  203. },
  204. {
  205. Name: "write_count",
  206. DisplayName: fmt.Sprintf("%s write count", displayType),
  207. Unit: monitor.METRIC_UNIT_COUNT,
  208. },
  209. }
  210. }
  211. var podProcess = SMeasurement{
  212. Context: []SMonitorContext{
  213. {
  214. Name: "pod_process",
  215. DisplayName: "Pod process",
  216. ResourceType: monitor.METRIC_RES_TYPE_CONTAINER,
  217. Database: monitor.METRIC_DATABASE_TELE,
  218. },
  219. },
  220. Metrics: newCadvisorProcessMetrics("Pod"),
  221. }
  222. var podDiskIo = SMeasurement{
  223. Context: []SMonitorContext{
  224. {
  225. Name: "pod_diskio",
  226. DisplayName: "Pod diskio",
  227. ResourceType: monitor.METRIC_RES_TYPE_CONTAINER,
  228. Database: monitor.METRIC_DATABASE_TELE,
  229. },
  230. },
  231. Metrics: newCadvisorDiskIoMetrics("Pod"),
  232. }