RedisInfo.vue 5.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216
<template>
  <div style="width: 100%;margin-top: 1rem;background-color: #ffffff">
    <a-row :gutter="8">
      <a-col :span="12">
        <apexchart ref="memoryInfo" type=area height=350 :options="memory.chartOptions" :series="memory.series" />
      </a-col>
      <a-col :span="12">
        <apexchart ref="keySize" type=area height=350  :options="key.chartOptions" :series="key.series" />
      </a-col>
    </a-row>
    <a-row :gutter="8">
      <a-divider orientation="left">Redis详细信息</a-divider>
      <table style="border-bottom: 1px solid #f1f1f1;">
        <tr v-for="(info, index) in redisInfo" :key="index" style="border-top: 1px solid #f1f1f1;">
          <td style="padding: .7rem 1rem">{{info.key}}</td>
          <td style="padding: .7rem 1rem">{{info.description}}</td>
          <td style="padding: .7rem 1rem">{{info.value}}</td>
        </tr>
      </table>
    </a-row>
  </div>
</template>
<script>
import axios from 'axios'
import moment from 'moment'
import {getAction} from '@/api/manage'

export default {
  name: 'RedisInfo',
  data () {
    return {
      loading: true,
      memory: {
        series: [],
        chartOptions: {
          chart: {
            animations: {
              enabled: true,
              easing: 'linear',
              dynamicAnimation: {
                speed: 3000
              }
            },
            toolbar: {
              show: false
            },
            zoom: {
              enabled: false
            }
          },
          dataLabels: {
            enabled: false
          },
          stroke: {
            curve: 'smooth'
          },
          title: {
            text: 'Redis内存实时占用情况(kb)',
            align: 'left'
          },
          markers: {
            size: 0
          },
          xaxis: {
          },
          yaxis: {},
          legend: {
            show: false
          }
        },
        data: [],
        xdata: []
      },
      key: {
        series: [],
        chartOptions: {
          chart: {
            animations: {
              enabled: true,
              easing: 'linear',
              dynamicAnimation: {
                speed: 3000
              }
            },
            toolbar: {
              show: false
            },
            zoom: {
              enabled: false
            }
          },
          dataLabels: {
            enabled: false
          },
          colors: ['#f5564e'],
          stroke: {
            curve: 'smooth'
          },
          title: {
            text: 'Redis key实时数量(个)',
            align: 'left'
          },
          markers: {
            size: 0
          },
          xaxis: {
          },
          yaxis: {},
          legend: {
            show: false
          }
        },
        data: [],
        xdata: []
      },
      redisInfo: [],
      timer: null
    }
  },
  beforeDestroy () {
    if (this.timer) {
      clearInterval(this.timer)
    }
  },
  mounted () {
    let minMemory = 1e10
    let minSize = 1e10
    let maxMemory = -1e10
    let maxSize = -1e10
    this.timer = setInterval(() => {
      if (this.$route.path.indexOf('redis') !== -1) {
        axios.all([
          getAction('redis/keysSize'),
          getAction('redis/memoryInfo')
        ]).then((r) => {
          console.log(r)
          let currentMemory = r[1].used_memory / 1000
          let currentSize = r[0].dbSize
          if (currentMemory < minMemory) {
            minMemory = currentMemory
          }
          if (currentMemory > maxMemory) {
            maxMemory = currentMemory
          }
          if (currentSize < minSize) {
            minSize = currentSize
          }
          if (currentSize > maxSize) {
            maxSize = currentSize
          }
          let time = moment().format('hh:mm:ss')
          this.memory.data.push(currentMemory)
          this.memory.xdata.push(time)
          this.key.data.push(currentSize)
          this.key.xdata.push(time)
          if (this.memory.data.length >= 6) {
            this.memory.data.shift()
            this.memory.xdata.shift()
          }
          if (this.key.data.length >= 6) {
            this.key.data.shift()
            this.key.xdata.shift()
          }
          this.$refs.memoryInfo.updateSeries([
            {
              name: '内存(kb)',
              data: this.memory.data.slice()
            }
          ])
          this.$refs.memoryInfo.updateOptions({
            xaxis: {
              categories: this.memory.xdata.slice()
            },
            yaxis: {
              min: minMemory,
              max: maxMemory
            }
          }, true, true)
          this.$refs.keySize.updateSeries([
            {
              name: 'key数量',
              data: this.key.data.slice()
            }
          ])
          this.$refs.keySize.updateOptions({
            xaxis: {
              categories: this.key.xdata.slice()
            },
            yaxis: {
              min: minSize - 2,
              max: maxSize + 2
            }
          }, true, true)
          if (this.loading) {
            this.loading = false
          }
        }).catch((r) => {
          console.error(r)
          this.$message.error('获取Redis信息失败')
          if (this.timer) {
            clearInterval(this.timer)
          }
        })
      }
    }, 3000)
    getAction('redis/info').then((r) => {
      console.log('redis/info')
      console.log(r)
      this.redisInfo = r.result
    })
  }
}
</script>
<style>

</style>