TomcatInfo.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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. 'tomcat.sessions.created': { color: 'green', text: 'tomcat 已创建 session 数', unit: '个' },
  62. 'tomcat.sessions.expired': { color: 'green', text: 'tomcat 已过期 session 数', unit: '个' },
  63. 'tomcat.sessions.active.current': { color: 'green', text: 'tomcat 当前活跃 session 数', unit: '个' },
  64. 'tomcat.sessions.active.max': { color: 'green', text: 'tomcat 活跃 session 数峰值', unit: '个' },
  65. 'tomcat.sessions.rejected': { color: 'green', text: '超过session 最大配置后,拒绝的 session 个数', unit: '个' },
  66. 'tomcat.global.sent': { color: 'purple', text: '发送的字节数', unit: 'bytes' },
  67. 'tomcat.global.request.max': { color: 'purple', text: 'request 请求最长耗时', unit: '秒' },
  68. 'tomcat.global.request.count': { color: 'purple', text: '全局 request 请求次数', unit: '次' },
  69. 'tomcat.global.request.totalTime': { color: 'purple', text: '全局 request 请求总耗时', unit: '秒' },
  70. 'tomcat.servlet.request.max': { color: 'cyan', text: 'servlet 请求最长耗时', unit: '秒' },
  71. 'tomcat.servlet.request.count': { color: 'cyan', text: 'servlet 总请求次数', unit: '次' },
  72. 'tomcat.servlet.request.totalTime': { color: 'cyan', text: 'servlet 请求总耗时', unit: '秒' },
  73. 'tomcat.threads.current': { color: 'pink', text: 'tomcat 当前线程数(包括守护线程)', unit: '个' },
  74. 'tomcat.threads.config.max': { color: 'pink', text: 'tomcat 配置的线程最大数', unit: '个' }
  75. },
  76. // 当一条记录中需要取出多条数据的时候需要配置该字段
  77. moreInfo: {
  78. 'tomcat.global.request': ['.count', '.totalTime'],
  79. 'tomcat.servlet.request': ['.count', '.totalTime']
  80. }
  81. }
  82. },
  83. mounted() {
  84. this.loadTomcatInfo()
  85. },
  86. methods: {
  87. handleClickUpdate() {
  88. this.loadTomcatInfo()
  89. },
  90. loadTomcatInfo() {
  91. this.tableLoading = true
  92. this.time = moment().format('YYYY年MM月DD日 HH时mm分ss秒')
  93. Promise.all([
  94. getAction('actuator/metrics/tomcat.sessions.created'),
  95. getAction('actuator/metrics/tomcat.sessions.expired'),
  96. getAction('actuator/metrics/tomcat.sessions.active.current'),
  97. getAction('actuator/metrics/tomcat.sessions.active.max'),
  98. getAction('actuator/metrics/tomcat.sessions.rejected'),
  99. // 2.3.5.RELEASE 无此API
  100. // getAction('actuator/metrics/tomcat.global.sent'),
  101. // getAction('actuator/metrics/tomcat.global.request.max'),
  102. // getAction('actuator/metrics/tomcat.global.request'),
  103. // getAction('actuator/metrics/tomcat.threads.current'),
  104. // getAction('actuator/metrics/tomcat.threads.config.max')
  105. // 2.1.3.RELEASE 无此API
  106. //getAction('actuator/metrics/tomcat.servlet.request'),
  107. // getAction('actuator/metrics/tomcat.servlet.request.max'),
  108. ]).then((res) => {
  109. let tomcatInfo = []
  110. res.forEach((value, id) => {
  111. let more = this.moreInfo[value.name]
  112. if (!(more instanceof Array)) {
  113. more = ['']
  114. }
  115. more.forEach((item, idx) => {
  116. let param = value.name + item
  117. tomcatInfo.push({
  118. id: param + id, param,
  119. text: 'false value',
  120. value: value.measurements[idx].value
  121. })
  122. })
  123. })
  124. this.dataSource = tomcatInfo
  125. }).catch((e) => {
  126. console.error(e)
  127. this.$message.error('获取Tomcat信息失败')
  128. }).finally(() => {
  129. this.loading = false
  130. this.tableLoading = false
  131. })
  132. }
  133. }
  134. }
  135. </script>
  136. <style></style>