e23d795ac60fd5f72abfeeb9d7d94a9930687bac.svn-base 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <template>
  2. <a-skeleton active :loading="loading" :paragraph="{rows: 17}">
  3. <a-card :bordered="false">
  4. <a-alert type="info" :showIcon="true">
  5. <div slot="message">
  6. 上次更新时间:{{ this.time }}
  7. <a-divider type="vertical"/>
  8. <a @click="handleClickUpdate">立即更新</a>
  9. </div>
  10. </a-alert>
  11. <a-table
  12. rowKey="id"
  13. size="middle"
  14. :columns="columns"
  15. :dataSource="dataSource"
  16. :pagination="false"
  17. :loading="tableLoading"
  18. style="margin-top: 20px;">
  19. <template slot="param" slot-scope="text, record">
  20. <a-tag :color="textInfo[record.param].color">{{ text }}</a-tag>
  21. </template>
  22. <template slot="text" slot-scope="text, record">
  23. {{ textInfo[record.param].text }}
  24. </template>
  25. <template slot="value" slot-scope="text, record">
  26. {{ text }} {{ textInfo[record.param].unit }}
  27. </template>
  28. </a-table>
  29. </a-card>
  30. </a-skeleton>
  31. </template>
  32. <script>
  33. import moment from 'moment'
  34. import { getAction } from '@/api/manage'
  35. moment.locale('zh-cn')
  36. export default {
  37. data() {
  38. return {
  39. time: '',
  40. loading: true,
  41. tableLoading: true,
  42. columns: [{
  43. title: '参数',
  44. width: '30%',
  45. dataIndex: 'param',
  46. scopedSlots: { customRender: 'param' }
  47. }, {
  48. title: '描述',
  49. width: '40%',
  50. dataIndex: 'text',
  51. scopedSlots: { customRender: 'text' }
  52. }, {
  53. title: '当前值',
  54. width: '30%',
  55. dataIndex: 'value',
  56. scopedSlots: { customRender: 'value' }
  57. }],
  58. dataSource: [],
  59. // 列表通过 textInfo 渲染出颜色、描述和单位
  60. textInfo: {
  61. 'jvm.memory.max': { color: 'purple', text: 'JVM 最大内存', unit: 'MB' },
  62. 'jvm.memory.committed': { color: 'purple', text: 'JVM 可用内存', unit: 'MB' },
  63. 'jvm.memory.used': { color: 'purple', text: 'JVM 已用内存', unit: 'MB' },
  64. 'jvm.buffer.memory.used': { color: 'cyan', text: 'JVM 缓冲区已用内存', unit: 'MB' },
  65. 'jvm.buffer.count': { color: 'cyan', text: '当前缓冲区数量', unit: '个' },
  66. 'jvm.threads.daemon': { color: 'green', text: 'JVM 守护线程数量', unit: '个' },
  67. 'jvm.threads.live': { color: 'green', text: 'JVM 当前活跃线程数量', unit: '个' },
  68. 'jvm.threads.peak': { color: 'green', text: 'JVM 峰值线程数量', unit: '个' },
  69. 'jvm.classes.loaded': { color: 'orange', text: 'JVM 已加载 Class 数量', unit: '个' },
  70. 'jvm.classes.unloaded': { color: 'orange', text: 'JVM 未加载 Class 数量', unit: '个' },
  71. 'jvm.gc.memory.allocated': { color: 'pink', text: 'GC 时, 年轻代分配的内存空间', unit: 'MB' },
  72. 'jvm.gc.memory.promoted': { color: 'pink', text: 'GC 时, 老年代分配的内存空间', unit: 'MB' },
  73. 'jvm.gc.max.data.size': { color: 'pink', text: 'GC 时, 老年代的最大内存空间', unit: 'MB' },
  74. 'jvm.gc.live.data.size': { color: 'pink', text: 'FullGC 时, 老年代的内存空间', unit: 'MB' },
  75. 'jvm.gc.pause.count': { color: 'blue', text: '系统启动以来GC 次数', unit: '次' },
  76. 'jvm.gc.pause.totalTime': { color: 'blue', text: '系统启动以来GC 总耗时', unit: '秒' }
  77. },
  78. // 当一条记录中需要取出多条数据的时候需要配置该字段
  79. moreInfo: {
  80. 'jvm.gc.pause': ['.count', '.totalTime']
  81. }
  82. }
  83. },
  84. mounted() {
  85. this.loadTomcatInfo()
  86. },
  87. methods: {
  88. handleClickUpdate() {
  89. this.loadTomcatInfo()
  90. },
  91. loadTomcatInfo() {
  92. this.tableLoading = true
  93. this.time = moment().format('YYYY年MM月DD日 HH时mm分ss秒')
  94. Promise.all([
  95. getAction('actuator/metrics/jvm.memory.max'),
  96. getAction('actuator/metrics/jvm.memory.committed'),
  97. getAction('actuator/metrics/jvm.memory.used'),
  98. getAction('actuator/metrics/jvm.buffer.memory.used'),
  99. getAction('actuator/metrics/jvm.buffer.count'),
  100. getAction('actuator/metrics/jvm.threads.daemon'),
  101. getAction('actuator/metrics/jvm.threads.live'),
  102. getAction('actuator/metrics/jvm.threads.peak'),
  103. getAction('actuator/metrics/jvm.classes.loaded'),
  104. getAction('actuator/metrics/jvm.classes.unloaded'),
  105. getAction('actuator/metrics/jvm.gc.memory.allocated'),
  106. getAction('actuator/metrics/jvm.gc.memory.promoted'),
  107. getAction('actuator/metrics/jvm.gc.max.data.size'),
  108. getAction('actuator/metrics/jvm.gc.live.data.size'),
  109. getAction('actuator/metrics/jvm.gc.pause')
  110. ]).then((res) => {
  111. let info = []
  112. res.forEach((value, id) => {
  113. let more = this.moreInfo[value.name]
  114. if (!(more instanceof Array)) {
  115. more = ['']
  116. }
  117. more.forEach((item, idx) => {
  118. let param = value.name + item
  119. let val = value.measurements[idx].value
  120. if (param === 'jvm.memory.max'
  121. || param === 'jvm.memory.committed'
  122. || param === 'jvm.memory.used'
  123. || param === 'jvm.buffer.memory.used'
  124. || param === 'jvm.gc.memory.allocated'
  125. || param === 'jvm.gc.memory.promoted'
  126. || param === 'jvm.gc.max.data.size'
  127. || param === 'jvm.gc.live.data.size'
  128. ) {
  129. val = this.convert(val, Number)
  130. }
  131. info.push({ id: param + id, param, text: 'false value', value: val })
  132. })
  133. })
  134. this.dataSource = info
  135. }).catch((e) => {
  136. console.error(e)
  137. this.$message.error('获取JVM信息失败')
  138. }).finally(() => {
  139. this.loading = false
  140. this.tableLoading = false
  141. })
  142. },
  143. convert(value, type) {
  144. if (type === Number) {
  145. return Number(value / 1048576).toFixed(3)
  146. } else if (type === Date) {
  147. return moment(value * 1000).format('YYYY-MM-DD HH:mm:ss')
  148. }
  149. return value
  150. }
  151. }
  152. }
  153. </script>
  154. <style></style>