aa4bcf5376d4668eb2c28868a950665265e75565.svn-base 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. <template>
  2. <a-skeleton active :loading="loading" :paragraph="{rows: 17}">
  3. <a-card>
  4. <!-- Radis 信息实时监控 -->
  5. <a-row :gutter="8">
  6. <a-col :sm="24" :xl="12">
  7. <area-chart-ty v-bind="memory"/>
  8. </a-col>
  9. <a-col :sm="24" :xl="12">
  10. <area-chart-ty v-bind="key"/>
  11. </a-col>
  12. </a-row>
  13. <h3>Redis 详细信息</h3>
  14. <a-table
  15. :loading="tableLoading"
  16. :columns="columns"
  17. :dataSource="redisInfo"
  18. :pagination="false"/>
  19. </a-card>
  20. </a-skeleton>
  21. </template>
  22. <script>
  23. import moment from 'moment'
  24. import { getAction } from '@/api/manage'
  25. import AreaChartTy from '@/components/chart/AreaChartTy'
  26. export default {
  27. name: 'RedisInfo',
  28. components: {
  29. AreaChartTy
  30. },
  31. data() {
  32. return {
  33. loading: true,
  34. tableLoading: true,
  35. // 定时器ID
  36. timer: null,
  37. // 定时器周期
  38. millisec: 3000,
  39. // Key 实时数量
  40. key: {
  41. title: 'Radis Key 实时数量(个)',
  42. dataSource: [],
  43. y: '数量(个)',
  44. height: 340,
  45. min: 0,
  46. max: 100,
  47. color: '#FF6987',
  48. lineSize: 8,
  49. lineColor: '#DC143C'
  50. },
  51. // 内存实时占用情况
  52. memory: {
  53. title: 'Radis 内存实时占用情况(KB)',
  54. dataSource: [],
  55. y: '内存(KB)',
  56. min: 0,
  57. max: 3000,
  58. height: 340,
  59. lineSize: 8
  60. },
  61. redisInfo: [],
  62. columns: [{
  63. title: 'Key',
  64. align: 'center',
  65. dataIndex: 'key'
  66. }, {
  67. title: 'Description',
  68. align: 'left',
  69. dataIndex: 'description'
  70. }, {
  71. title: 'Value',
  72. align: 'center',
  73. dataIndex: 'value'
  74. }],
  75. url: {
  76. keysSize: '/sys/actuator/redis/keysSize',
  77. memoryInfo: '/sys/actuator/redis/memoryInfo',
  78. info: '/sys/actuator/redis/info'
  79. },
  80. path: '/monitor/redis/info'
  81. }
  82. },
  83. mounted() {
  84. this.openTimer()
  85. this.loadRedisInfo()
  86. setTimeout(() => {
  87. this.loadData()
  88. }, 1000)
  89. },
  90. beforeDestroy() {
  91. this.closeTimer()
  92. },
  93. methods: {
  94. /** 开启定时器 */
  95. openTimer() {
  96. this.loadData()
  97. this.closeTimer()
  98. this.timer = setInterval(() => {
  99. if (this.$route.path === this.path) {
  100. this.loadData()
  101. }
  102. }, this.millisec)
  103. },
  104. /** 关闭定时器 */
  105. closeTimer() {
  106. if (this.timer) clearInterval(this.timer)
  107. },
  108. /** 查询数据 */
  109. loadData() {
  110. Promise.all([
  111. getAction(this.url.keysSize),
  112. getAction(this.url.memoryInfo)
  113. ]).then((res) => {
  114. let time = moment().format('hh:mm:ss')
  115. let [{ dbSize: currentSize }, memoryInfo] = res
  116. let currentMemory = memoryInfo.used_memory / 1000
  117. // push 数据
  118. this.key.dataSource.push({ x: time, y: currentSize })
  119. this.memory.dataSource.push({ x: time, y: currentMemory })
  120. // 最大长度为6
  121. if (this.key.dataSource.length > 6) {
  122. this.key.dataSource.splice(0, 1)
  123. this.memory.dataSource.splice(0, 1)
  124. }
  125. // 计算 Key 最大最小值
  126. let keyPole = this.getMaxAndMin(this.key.dataSource, 'y')
  127. this.key.max = Math.floor(keyPole[0]) + 10
  128. this.key.min = Math.floor(keyPole[1]) - 10
  129. if (this.key.min < 0) this.key.min = 0
  130. // 计算 Memory 最大最小值
  131. let memoryPole = this.getMaxAndMin(this.memory.dataSource, 'y')
  132. this.memory.max = Math.floor(memoryPole[0]) + 100
  133. this.memory.min = Math.floor(memoryPole[1]) - 100
  134. if (this.memory.min < 0) this.memory.min = 0
  135. }).catch((e) => {
  136. console.error(e)
  137. this.closeTimer()
  138. this.$message.error('获取 Redis 信息失败')
  139. }).finally(() => {
  140. this.loading = false
  141. })
  142. },
  143. // 获取一组数据中最大和最小的值
  144. getMaxAndMin(dataSource, field) {
  145. let maxValue = null, minValue = null
  146. dataSource.forEach(item => {
  147. let value = Number.parseInt(item[field])
  148. // max
  149. if (maxValue == null) {
  150. maxValue = value
  151. } else if (value > maxValue) {
  152. maxValue = value
  153. }
  154. // min
  155. if (minValue == null) {
  156. minValue = value
  157. } else if (value < minValue) {
  158. minValue = value
  159. }
  160. })
  161. return [maxValue, minValue]
  162. },
  163. loadRedisInfo() {
  164. this.tableLoading = true
  165. getAction(this.url.info).then((res) => {
  166. this.redisInfo = res.result
  167. }).finally(() => {
  168. this.tableLoading = false
  169. })
  170. }
  171. }
  172. }
  173. </script>
  174. <style></style>