Blame view

Yi.Vben5.Vue3/apps/web-antd/src/views/monitor/cache/index.vue 2.76 KB
515fceeb   “wangming”   框架初始化
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
  <script setup lang="ts">
  import type { RedisInfo } from '#/api/monitor/cache';
  
  import { onMounted, reactive, ref } from 'vue';
  
  import { Page } from '@vben/common-ui';
  import { CommandLineIcon, MemoryIcon, RedisIcon } from '@vben/icons';
  
  import { Button, Card, Col, Row } from 'ant-design-vue';
  
  import { redisCacheInfo } from '#/api/monitor/cache';
  
  import { CommandChart, MemoryChart, RedisDescription } from './components';
  
  const baseSpan = { lg: 12, md: 24, sm: 24, xl: 12, xs: 24 };
  
  const chartData = reactive<{
    command: { name: string; value: string }[];
    memory: string;
  }>({
    command: [],
    memory: '0',
  });
  
  interface IRedisInfo extends RedisInfo {
    dbSize: string;
  }
  const redisInfo = ref<IRedisInfo>();
  
  onMounted(async () => {
    await loadInfo();
  });
  
  async function loadInfo() {
    try {
      const ret = await redisCacheInfo();
  
      // 单位MB 保留两位小数
      const usedMemory = (
        Number.parseInt(ret.info.used_memory!) /
        1024 /
        1024
      ).toFixed(2);
      chartData.memory = usedMemory;
      // 命令统计
      chartData.command = ret.commandStats;
      console.log(chartData.command);
      // redis信息
      redisInfo.value = { ...ret.info, dbSize: String(ret.dbSize) };
    } catch (error) {
      console.warn(error);
    }
  }
  </script>
  
  <template>
    <Page>
      <Row :gutter="[15, 15]">
        <Col :span="24">
          <Card size="small">
            <template #title>
              <div class="flex items-center justify-start gap-[6px]">
                <RedisIcon class="size-[16px]" />
                <span>redis信息</span>
              </div>
            </template>
            <template #extra>
              <Button size="small" @click="loadInfo">
                <div class="flex">
                  <span class="icon-[charm--refresh]"></span>
                </div>
              </Button>
            </template>
            <RedisDescription v-if="redisInfo" :data="redisInfo" />
          </Card>
        </Col>
        <Col v-bind="baseSpan">
          <Card size="small">
            <template #title>
              <div class="flex items-center gap-[6px]">
                <CommandLineIcon class="size-[16px]" />
                <span>命令统计</span>
              </div>
            </template>
            <CommandChart
              v-if="chartData.command.length > 0"
              :data="chartData.command"
            />
          </Card>
        </Col>
        <Col v-bind="baseSpan">
          <Card size="small">
            <template #title>
              <div class="flex items-center justify-start gap-[6px]">
                <MemoryIcon class="size-[16px]" />
                <span>内存占用</span>
              </div>
            </template>
            <MemoryChart
              v-if="chartData.memory !== '0'"
              :data="chartData.memory"
            />
          </Card>
        </Col>
      </Row>
    </Page>
  </template>