46194a8b7879e258ce43a24573575bfac534432d.svn-base 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. 'system.cpu.count': { color: 'green', text: 'CPU 数量', unit: '核' },
  62. 'system.cpu.usage': { color: 'green', text: '系统 CPU 使用率', unit: '%' },
  63. 'process.start.time': { color: 'purple', text: '应用启动时间点', unit: '' },
  64. 'process.uptime': { color: 'purple', text: '应用已运行时间', unit: '秒' },
  65. 'process.cpu.usage': { color: 'purple', text: '当前应用 CPU 使用率', unit: '%' }
  66. },
  67. // 当一条记录中需要取出多条数据的时候需要配置该字段
  68. moreInfo: {}
  69. }
  70. },
  71. mounted() {
  72. this.loadTomcatInfo()
  73. },
  74. methods: {
  75. handleClickUpdate() {
  76. this.loadTomcatInfo()
  77. },
  78. loadTomcatInfo() {
  79. this.tableLoading = true
  80. this.time = moment().format('YYYY年MM月DD日 HH时mm分ss秒')
  81. Promise.all([
  82. getAction('actuator/metrics/system.cpu.count'),
  83. getAction('actuator/metrics/system.cpu.usage'),
  84. getAction('actuator/metrics/process.start.time'),
  85. getAction('actuator/metrics/process.uptime'),
  86. getAction('actuator/metrics/process.cpu.usage')
  87. ]).then((res) => {
  88. let info = []
  89. res.forEach((value, id) => {
  90. let more = this.moreInfo[value.name]
  91. if (!(more instanceof Array)) {
  92. more = ['']
  93. }
  94. more.forEach((item, idx) => {
  95. let param = value.name + item
  96. let val = value.measurements[idx].value
  97. if (param === 'system.cpu.usage' || param === 'process.cpu.usage') {
  98. val = this.convert(val, Number)
  99. }
  100. if (param === 'process.start.time') {
  101. val = this.convert(val, Date)
  102. }
  103. info.push({ id: param + id, param, text: 'false value', value: val })
  104. })
  105. })
  106. this.dataSource = info
  107. }).catch((e) => {
  108. console.error(e)
  109. this.$message.error('获取服务器信息失败')
  110. }).finally(() => {
  111. this.loading = false
  112. this.tableLoading = false
  113. })
  114. },
  115. convert(value, type) {
  116. if (type === Number) {
  117. return Number(value * 100).toFixed(2)
  118. } else if (type === Date) {
  119. return moment(value * 1000).format('YYYY-MM-DD HH:mm:ss')
  120. }
  121. return value
  122. }
  123. }
  124. }
  125. </script>
  126. <style></style>